Salta al contenuto

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

posta 2 anni fa330 visualizzazioni

1 Risposta
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".

ESPERTO

con risposta 2 anni fa

AWS
ESPERTO

verificato 2 anni fa

  • 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

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.