スキップしてコンテンツを表示

How to get the username and password for my terraform-created lightsail instances?

0

Hello community. I can create a lightsail instance using terraform using the code below. But I don't know how to get password from it. I don't see any mentioning of this on the documents either.

resource "aws_lightsail_instance" "instance_singapore" {
  provider          = aws.singapore
  name              = var.instance_name_singapore
  availability_zone = var.instance_availability_zone_asia
  blueprint_id      = var.instance_blueprintid
  bundle_id         = var.instance_bundleid

  tags = {
    Environment = "production"
  }
}

For blueprintid, I am using ubuntu_24_04

質問済み 2年前332ビュー

1回答
1

Hello.

Lightsail normally uses public key authentication instead of password authentication to connect with things like SSH.
Therefore, download the key pair and connect by following the steps in the document below.
https://docs.aws.amazon.com/lightsail/latest/userguide/amazon-lightsail-ssh-using-terminal.html

Also, if you are using the Ubuntu blueprint, the OS user will be "ubuntu".

エキスパート

回答済み 2年前

AWS
エキスパート

レビュー済み 2年前

  • Now I couldn't create instance now with key pair generation code added. New code:

    # Create the Lightsail instance for Singapore
    resource "aws_lightsail_instance" "instance_singapore" {
      provider          = aws.singapore
      name              = var.instance_name_singapore
      availability_zone = var.instance_availability_zone_asia
      key_pair_name     = aws_lightsail_key_pair.private_key_1.id
      blueprint_id      = var.instance_blueprintid
      bundle_id         = var.instance_bundleid
    
      depends_on = [ aws_lightsail_key_pair.private_key_1 ]
      tags = {
        Environment = "production"
      }
    }
    
    provider "tls" {
      # The TLS provider is used to generate the key pair
    }
    
    # Generate an RSA private key
    resource "tls_private_key" "example" {
      algorithm   = "RSA"
      rsa_bits    = 4096
    }
    
    # AWS Lightsail key pair resource using the generated public key
    resource "aws_lightsail_key_pair" "private_key_1" {
      name       = var.key_pair_1_name
      public_key = tls_private_key.example.public_key_openssh
    }
    
    # Output the public key
    output "public_key" {
      value = tls_private_key.example.public_key_openssh
    }
    
    # Optionally, you can also output the private key for further use (e.g., for SSH access)
    # Note: Be cautious with handling private keys
    output "private_key" {
      sensitive = true
      value     = tls_private_key.example.private_key_pem
    }
    

    It says:

    `operation error Lightsail: CreateInstances, https response error StatusCode: 400, RequestID: 0eefa119-62f3-4cca-b09b-5ce625ce8dbc, NotFoundException: The

  • The KeyPair does not exist:

  • key_pair_name = aws_lightsail_key_pair.private_key_1.id

    This should be referring to the keypain name as below

    key_pair_name = aws_lightsail_key_pair.private_key_1.name

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

関連するコンテンツ