AWS instance example with aws ami lookup

From wikieduonline
Revision as of 10:29, 2 September 2021 by Welcome (talk | contribs) (Created page with "<pre> provider "aws" { region = "us-west-2" profile = "YourProfile" } data "aws_ami" "ubuntu" { most_recent = true filter { name = "name" values = ["ubun...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

data "aws_ami" "ubuntu" {
  most_recent = true

  filter {
    name   = "name"
    values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.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"

  tags = {
    Name = "MyInstanceName"
  }
}

See also

Advertising: