Terraform Data Sources

data "aws_ami" "myAmi" {
owners = ["099720109477"]
most_recent = true

filter {
name = "description"
values = ["Canonical, Ubuntu, 20.04 LTS*"]
}

filter {
name = "architecture"
values = ["x86_64"]
}
}
data "aws_ami" "myAmi" {
owners = ["099720109477"]
most_recent = true

filter {
name = "description"
values = ["Canonical, Ubuntu, 20.04 LTS*"]
}

filter {
name = "architecture"
values = ["x86_64"]
}

filter {
name = "image-type"
values = ["machine"]
}

filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20201026"]
}
}
  1. All images are owned by “099720109477". This value could be amazon or marketplace to make it simple. But specifying the account number like this helps you narrow down more.
  2. Description filter informs Terraform to include all images for which the description contains “Canonical, Ubuntu, 20.04 LTS" string.
  3. Architecture filter specifies the type of processor architecture-based images — in this case, x86_64.
  4. The image-type filter specifies the time of images to be “machine".
  5. The name filter specifies the name of the image set by the owner at the time when the image was being built.
. . .
Terraform will perform the following actions:

# aws_instance.demo_vm_1 will be created
+ resource "aws_instance" "demo_vm_1" {
+ ami = "ami-00831fc7c1e3ddc60"
+ arn = (known after apply)
+ associate_public_ip_address = (known after apply)
. . .
. . .

# aws_instance.demo_vm_2 will be created
+ resource "aws_instance" "demo_vm_2" {
+ ami = "ami-00831fc7c1e3ddc60"
+ arn = (known after apply)
+ associate_public_ip_address = (known after apply)
. . .

--

--

--

https://letsdotech.dev

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

A guide to learning Apache Spark and Databricks Spark Certification

Wild card certificate using cert-manager in Kubernetes

What is the composable enterprise? And how does it relate to business process as a service (BPaaS)?

Stop Using Structs!

Pointless or Best Practice

What Milking Cows Can Teach You About Programming

CyNix:1 Vulnhub Write-up

Local Hack Day: Share is online! — April 11th

I found a software team that really cares about its users and its people

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Let's Do Tech

Let's Do Tech

https://letsdotech.dev

More from Medium

Generate SSH key using terraform for multiple environments

ACL on S3 bucket objects with Terraform

Monitoring as Code with Newrelic and Terraform

gcloud auth login using CLI