-1

我很喜欢地形化;事实上,这是我训练的一部分。

我在想; 有没有办法让 terraform 将来自上一个命令的特定值(作为变量)存储在同一个文件中。

例子:

    resource "aws_vpc" "TestVPC"{
    cidr_block = "192.168.0.0/16"
    instance_tenancy = "default"
    enable_dns_hostnames="True"
    tags{
        Name="TestVpc"
    }
}
resource "aws_subnet" "TestSubnet"{
    vpc_id = "${var.aws_vpc_id}" ##This is where I'd like to populate the aws_vpc_id from the VPC creation step above.
    cidr_block = "192.168.0.0/24"
    map_public_ip_on_launch="True"
    availability_zone = "us-east-2a"
    tags{
        Name="TestSubnet"
    }
}

非常感谢您的帮助。

谢谢。

4

1 回答 1

1

您可以使用创建 VPC 的输出,${aws_vpc.TestVPC.id}

像这样:

resource "aws_vpc" "TestVPC" {
  cidr_block           = "192.168.0.0/16"
  instance_tenancy     = "default"
  enable_dns_hostnames = "True"

  tags {
    Name = "TestVpc"
  }
}

resource "aws_subnet" "TestSubnet" {
  vpc_id                  = "${aws_vpc.TestVPC.id}"
  cidr_block              = "192.168.0.0/24"
  map_public_ip_on_launch = "True"
  availability_zone       = "us-east-2a"

  tags {
    Name = "TestSubnet"
  }
}
于 2018-12-04T00:30:02.450 回答