Difference between revisions of "AWS instance example with aws ami lookup"

From wikieduonline
Jump to navigation Jump to search
Line 8: Line 8:
 
  [[data]] "[[aws_ami]]" "ubuntu" {
 
  [[data]] "[[aws_ami]]" "ubuntu" {
 
   most_recent = true
 
   most_recent = true
<pre>
 
  
  filter {
+
  filter {
    name  = "name"
+
    name  = "name"
    values = ["ubuntu/images/hvm-ssd/ubuntu-hirsute-21.04-amd64-server-*"]
+
    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"
  
  filter {
+
  tags = {
    name  = "virtualization-type"
+
    Name = "MyInstanceName"
    values = ["hvm"]
+
  }
  }
+
}
 
 
  owners = ["099720109477"] # Canonical
 
}
 
 
 
resource "aws_instance" "myUbuntuMicroInstance" {
 
  ami          = data.aws_ami.ubuntu.id
 
  instance_type = "t3.micro"
 
 
 
  tags = {
 
    Name = "MyInstanceName"
 
  }
 
}
 
</pre>
 
  
 
== [[Ubuntu Focal 20.04]] ==
 
== [[Ubuntu Focal 20.04]] ==

Revision as of 02:39, 2 February 2022

Ubuntu Hirsute 21.04

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" 
  tags = {
    Name = "MyInstanceName"
  }
}

Ubuntu Focal 20.04

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"
  }
}

Related terms

See also

Advertising: