terraform v0.12.17.我已经阅读了数据源:aws_ebs_snapshot,但它没有告诉我如何使用结果。
假设我想从最新的 AWS 快照创建一个 AWS 卷。如何使用 data{} 资源获取最新快照,然后使用它来创建卷?
provider "aws" {
region = "us-east-1"
}
data "aws_ebs_snapshot_ids" "jenkins_master" {
filter {
name = "tag:Name"
values = ["jenkins-master"]
}
}
resource "aws_ebs_volume" "jenkins_master_ebs" {
availability_zone = "us-east-1a"
size = ??? // taken from result of above data{}
snapshot_id = ??? // taken from result of above data{}
tags = {
Name = "jenkins-master-ebs"
}
}
根据 Terraform 文档,您将获得一个ids
列表,因此您可以使用如下所示的内容:
resource "aws_ebs_volume" "jenkins_master_ebs" {
availability_zone = "us-east-1a"
size = 50 # Your custom size
snapshot_id = data.aws_ebs_snapshot_ids.jenkins_master.ids.0 # First element
tags = {
Name = "jenkins-master-ebs"
}
}