Referring to resources named with variables in Terraform

后端 未结 2 810
广开言路
广开言路 2021-02-12 21:49

I\'m trying to create a module in Terraform that can be instantiated multiple times with different variable inputs. Within the module, how do I reference resources when their na

相关标签:
2条回答
  • 2021-02-12 22:32

    I was fundamentally misunderstanding how modules worked.

    Terraform does not support interpolation in resource names (see the relevant issues), but that doesn't matter in my case, because the resources of each instance of a module are in the instance's namespace. I was worried about resource names colliding, but the module system already handles that.

    0 讨论(0)
  • 2021-02-12 22:41

    The picture below shows what is going on.

    The terraform documentation does not make their use of "NAME" clear versus the "name" values that are used for the actual resources created by the infrastructure vender (like, AWS or Google Cloud).

    Additionally, it isn't always "name=, but sometimes, say, "endpoint= or even "resource_group_name= or whatever.

    And there are a couple of ways to generate multiple "name" values -- using count, variables, etc., or inside tfvar files and running terraform apply -var-file=foo.tfvars

    0 讨论(0)
提交回复
热议问题