【问题标题】:Terraform - populate variable values from same scriptTerraform - 从同一脚本填充变量值
【发布时间】:2019-05-05 08:01:59
【问题描述】:

我很擅长地形改造;事实上,这是我训练的一部分。

我想知道;有没有办法让 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"
    }
}

非常感谢您的帮助。

谢谢。

【问题讨论】:

    标签: terraform infrastructure-as-code


    【解决方案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"
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-10
      • 1970-01-01
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-24
      相关资源
      最近更新 更多