【发布时间】:2019-09-06 20:27:24
【问题描述】:
如何将资源块(例如:资源“aws 卷附件”“ebs att”)作为输入发送到 tf 文件
resource "aws_volume_attachment" "ebs_att" {
device_name = "/dev/sdh"
volume_id = "${aws_ebs_volume.example.id}"
instance_id = "${aws_instance.example.id}"
force_detach = "true"
}
假设,下面是我的 terraform .tf 文件
provider "aws" {
region = "${var.region}"
access_key = "${var.access_key}"
secret_key = "${var.secret_key}"
}
resource "aws_key_pair" "deployer" {
key_name = "testkey-${var.hostname}"
public_key = "${file(var.public_key_path)}"
}
对于这个文件,我必须发送资源块->
resource "aws_volume_attachment" "ebs_att"
这样最终的 .tf 文件看起来像
provider "aws" {
region = "${var.region}"
access_key = "${var.access_key}"
secret_key = "${var.secret_key}"
}
resource "aws_key_pair" "deployer" {
key_name = "testkey-${var.hostname}"
public_key = "${file(var.public_key_path)}"
}
resource "aws_volume_attachment" "ebs_att" {
device_name = "/dev/sdh"
volume_id = "${aws_ebs_volume.example.id}"
instance_id = "${aws_instance.example.id}"
force_detach = "true"
}
【问题讨论】:
-
什么意思?您能否提供一个更大的工作示例并解释您在这里尝试做什么?你也在使用 Terraform 0.12+ 吗?
-
好的我已经编辑了这个问题通常terraform允许我们在tf文件之外输入变量值而不在tf文件中明确给出有没有办法像我们为变量一样提供资源块??
-
您为什么要这样做,而不是在该目录的
.tf文件中添加卷附件?
标签: amazon-web-services terraform