Terraform-provider-aws: Terraform: List of AMI specific to ubuntu 20.04 LTS AWS

Created on 15 Sep 2020  Ā·  3Comments  Ā·  Source: hashicorp/terraform-provider-aws

I am using terraform to get a list of AMI for a specific OS - ubuntu 20.04,

I have checked different examples link

When I use the script this does not give me list of AMI. So i modified the code

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

However, ideally this should give me the details of ami in the region specified in my case us-east-1.

[ec2-user@ip-172-31-84-148 ~]$ terraform plan
provider.aws.region
The region where AWS operations will take place. Examples
are us-east-1, us-west-2, etc.

Enter a value: us-east-1

Refreshing Terraform state in-memory prior to plan…
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

data.aws_ami.ubuntu: Refreshing state…

No changes. Infrastructure is up-to-date.

This means that Terraform did not detect any differences between your
configuration and real physical resources that exist. As a result, no
actions need to be performed.

and also i am not sure how create an out for the above script. i am not very good in terraform. Please guide me where am i going wrong.

Note: I really am not sure whether this is a bug or ... a question..

question servicec2

Most helpful comment

If your terraform only has the data block in it, there is no resource being controlled by terraform and thus there will never be a change reported.

If you want terraform to output information about the AMI, you will have to add an output block similar to this:

output "ubuntu_ami" {
  value = data.aws_ami.ubuntu
}

If you are new to terraform, you may want to review some of the tutorials at https://learn.hashicorp.com/collections/terraform/aws-get-started

Cheers!

All 3 comments

If your terraform only has the data block in it, there is no resource being controlled by terraform and thus there will never be a change reported.

If you want terraform to output information about the AMI, you will have to add an output block similar to this:

output "ubuntu_ami" {
  value = data.aws_ami.ubuntu
}

If you are new to terraform, you may want to review some of the tutorials at https://learn.hashicorp.com/collections/terraform/aws-get-started

Cheers!

@dthvt Thank you so much sir.

Let me try this. I will get back to you . If there is any kind of issues..

Thanks for your time and patience.

I'm going to lock this issue because it has been closed for _30 days_ ā³. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

Was this page helpful?
0 / 5 - 0 ratings