Created
January 26, 2018 03:51
-
-
Save Joseph-R/603de5d84f6b5685ed73cce894c97ad3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I want to configure an AWS Launch Config resource to use a local user-data file from the repo. And I set that up okay | |
using file(), but variables had to be hard-coded for each stack. There was no interpolation. That's fine if each stack | |
has their own launch config, but what I'd really like to do is re-use one user-data file for a couple different stacks | |
and feed in variables to differentiate between each. | |
I created a template resource and file and fed in variables, but I'm getting a weird error. Is this the correct approach? | |
# Code snippet | |
------------------- | |
data "template_file" "user-data" { | |
template = "${file("${path.module}/../elasticsearch-user-data.sh.tpl")}" | |
vars { | |
stage="${var.environment}" | |
cluster="${local.cluster}" | |
cluster_name="${local.cluster_name}" | |
} | |
} | |
resource "aws_launch_configuration" "cluster" { | |
# Static LC names create a problem when updating launch configs. Append timestamp to make names unique while maintaining backwards compatibility. | |
name = "${upper(local.cluster_name)}-${replace(timestamp(), ":" , "-")}" | |
user_data = "${template_file.user-data.template}" | |
------------------- | |
# Error Output | |
------------------- | |
$ terraform plan | |
Error: resource 'aws_launch_configuration.cluster' config: unknown resource 'template_file.user-data' referenced in variable template_file.user-data.template | |
------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment