내용으로 건너뛰기

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

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.