Difference between revisions of "Terraform: AWS instance example with aws ami lookup and key name"

From wikieduonline
Jump to navigation Jump to search
Line 35: Line 35:
  
 
== Related ==
 
== Related ==
* <code>[[aws ec2 describe-key-pars]]</code>
+
* <code>[[aws ec2 describe-key-pairs]]</code>
  
 
== See also ==
 
== See also ==

Revision as of 10:50, 2 September 2021

provider "aws" {
  region  = "us-west-2"
  profile = "YourProfile"
}

data "aws_ami" "ubuntu" {
  most_recent = true

  filter {
    name   = "name"
    values = ["ubuntu/images/hvm-ssd/ubuntu-hirsute-21.04-amd64-server-*"]
  }

  filter {
    name   = "virtualization-type"
    values = ["hvm"]
  }

  owners = ["099720109477"] # Canonical
}

resource "aws_instance" "myUbuntuMicroInstance" {
  ami           = data.aws_ami.ubuntu.id
  instance_type = "t3.micro"
  key_name = "YourKeyName"

  tags = {
    Name = "MyInstanceName"
  }
}


Related

See also

Advertising: