Quantcast
Channel: Terraform - HashiCorp Discuss
Viewing all articles
Browse latest Browse all 11357

DRY string construction from resource

$
0
0

For our EC2 instances, we give them a name (which is also the hostname) that combines a common string, ie ‘vault-’, suffixed by the first few characters of the EC2 instance id. For example:

A vault server with EC2 instance id “i-ab12356afe” would be designated “vault-ab1235”. I’m having a hard time because I have to repeat the same code throughout my aws_instance resource declaration, ie in the provisioners:

${var.node_short_name}-${substr(self.id, 2, 6)}

In addition to DRY, I would really like to be able to export/output this value from the module that creates the aws_instance so that it can be used elsewhere, ie to create/destroy a DNS record.

I think because the instance-id isn’t known until after the instance is created is maybe why I’m having such a hard time with this? At least how I’ve tried to use them, local and null_data_source both create cyclic dependencies.

Is there some way to construct this string just once, and then use that result as both a value in the provisioners and export it as an output value?

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 11357

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>