【问题标题】:Terraform: List of AMI specific to ubuntu 20.08 LTS AWSTerraform:特定于 ubuntu 20.08 LTS AWS 的 AMI 列表
【发布时间】:2021-01-02 01:08:46
【问题描述】:

问题:我正在使用 terraform 获取特定操作系统的 AMI 列表 - ubuntu 20.08

我检查了不同的例子link

当我使用脚本时,这不会给我 AMI 列表

脚本

data "aws_ami" "ubuntu" {
    most_recent = true

    filter {
        name   = "name"
        values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-20.08-amd64-server-*"]
    }
    
    filter {
        name = "virtualization - type"
        values = ["hvm"]
    }

    owners = ["AWS"]
}

我也参考了下面的链接

How are data sources used in Terraform?

输出:

[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.std_ami: 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.

我不确定我哪里出错了我检查了很多链接,其中一些我在下面列出。

【问题讨论】:

  • 没有 20.08,Xenial 指的是 16.04。您想使用最新的 Ubuntu LTS 吗?这是 20.04,代号为 focal。因此,您要搜索的 AMI 应该是 ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*。 Canonical 还在 cloud-images.ubuntu.com/locator/ec2 上发布了 AMI 列表。
  • @ydaetskcoR 是的,我需要最新的对不起,我在 terraform 方面不是很好。请指导我>>我正在寻找 AMI + ubuntu 20.08 的列表

标签: amazon-web-services terraform


【解决方案1】:

您的数据应该是:

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

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

Ubuntu的所有者不是AWS,镜像是ubuntu-focal-20.04-amd64-server-,不是ubuntu-xenial-20.08-amd64-server-

以上结果为 (us-east-1):

 {
  "architecture" = "x86_64"
  "arn" = "arn:aws:ec2:us-east-1::image/ami-0dba2cb6798deb6d8"
  "block_device_mappings" = [
    {
      "device_name" = "/dev/sda1"
      "ebs" = {
        "delete_on_termination" = "true"
        "encrypted" = "false"
        "iops" = "0"
        "snapshot_id" = "snap-0f06f1549ff7327c9"
        "volume_size" = "8"
        "volume_type" = "gp2"
      }
      "no_device" = ""
      "virtual_name" = ""
    },
    {
      "device_name" = "/dev/sdb"
      "ebs" = {}
      "no_device" = ""
      "virtual_name" = "ephemeral0"
    },
    {
      "device_name" = "/dev/sdc"
      "ebs" = {}
      "no_device" = ""
      "virtual_name" = "ephemeral1"
    },
  ]
  "creation_date" = "2020-09-08T00:55:25.000Z"
  "description" = "Canonical, Ubuntu, 20.04 LTS, amd64 focal image build on 2020-09-07"
  "filter" = [
    {
      "name" = "name"
      "values" = [
        "ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*",
      ]
    },
    {
      "name" = "virtualization-type"
      "values" = [
        "hvm",
      ]
    },
  ]
  "hypervisor" = "xen"
  "id" = "ami-0dba2cb6798deb6d8"
  "image_id" = "ami-0dba2cb6798deb6d8"
  "image_location" = "099720109477/ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20200907"
  "image_type" = "machine"
  "most_recent" = true
  "name" = "ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20200907"
  "owner_id" = "099720109477"
  "owners" = [
    "099720109477",
  ]
  "product_codes" = []
  "public" = true
  "root_device_name" = "/dev/sda1"
  "root_device_type" = "ebs"
  "root_snapshot_id" = "snap-0f06f1549ff7327c9"
  "sriov_net_support" = "simple"
  "state" = "available"
  "state_reason" = {
    "code" = "UNSET"
    "message" = "UNSET"
  }
  "tags" = {}
  "virtualization_type" = "hvm"
}

【讨论】:

  • 我收到如下消息 没有变化。基础设施是最新的。这意味着 Terraform 没有检测到您的配置与存在的真实物理资源之间的任何差异。因此,无需执行任何操作。
  • @sudlo data 不会改变任何东西。它只是获取 AMI 列表。因此,它不会改变您的基础架构。
  • 我同意/// 让我解决这个问题,我会尽快回复您。我唯一需要弄清楚的是创建一个输出..
  • @sudlo 哪个输出?从数据aws_ami?顺便一提。如果我的回答有帮助,我们将不胜感激。
  • 你的答案是完美的......毫无疑问......谢谢......我说的是你输入的输出......我创建了一个 output.tf 文件..
猜你喜欢
  • 2014-06-12
  • 1970-01-01
  • 2020-10-29
  • 2017-10-28
  • 1970-01-01
  • 1970-01-01
  • 2022-10-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多