How to use terraform output as input variable of another terraform template

前端 未结 2 812
悲哀的现实
悲哀的现实 2021-02-07 10:25

Is there any way I can use a Terraform template output to another Terraform template\'s input?

Ex: I have a Terraform template which creates an ELB and I have another T

2条回答
  •  迷失自我
    2021-02-07 10:47

    Have you tried using remote state to populate your second template?

    Declare it like this:

    resource "terraform_remote_state" "your_state" {
      backend = "s3"
      config {
        bucket = "${var.your_bucket}"
        region = "${var.your_region}"
        key = "${var.your_state_file}"
      }
    }
    

    And then you should be able to pull out your resource directly like this:

    your_elb = "${terraform_remote_state.your_state.output.your_output_resource}"
    

    If this doesn't work for you, have you tried implementing your ELB in a module and then just using the output?

    https://github.com/terraform-community-modules/tf_aws_elb is a good example of how to structure the module.

提交回复
热议问题