Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adhoc execute commands for var injection and setup before terraform apply. #5258

Closed
ghost opened this issue Feb 22, 2016 · 6 comments
Closed

Comments

@ghost
Copy link

ghost commented Feb 22, 2016

At current while trying to generate a fleet cluster id with terraform, I have to wrap the terraform apply process with a script to inject that data as variables.

Using a script similar to:

#!/bin/bash

REGION=us-east-1
ENV=dev

case "$1" in
  apply)
    SIZE=`grep -E "deployment.cluster_size_min" ./${ENV}.tfvars | awk -F= '{print$2}' | sed -e 's/"//g'`
    echo "cluster size: ${SIZE}"
    etcd_token=`curl -s https://discovery.etcd.io/new?size=${SIZE} 2>/dev/null`
    echo "cluster token: ${etcd_token}"

    terraform apply --var "etcd_token=${etcd_token}" ${@: 2}
...

Is there a better way to do this within terraform?

@ghost
Copy link
Author

ghost commented Feb 24, 2016

I validated I could execute this before the aws_instance or aws_autoscale_group.

resource "null_resource" "pre-flight" {
  provisioner "local-exec" {
    command = "echo 'pre-flight......'"
  }
}

However can that be assigned as an input to a variable?

i.e. something like:

variable "etcd_token" {
    "default": "${null_resource.pre-flight.rendered}"
}

Last time I tried that I couldn't seem to define a variable with interpolation involved.

@jen20
Copy link
Contributor

jen20 commented Mar 3, 2016

Hi @johnt337! Thanks for opening this! Right now there isn't a better way than wrapping a script around the execution of Terraform. This is something that may be covered by #4169 however. For now I'll close this issue and continue to track it there.

@ghost
Copy link
Author

ghost commented Mar 21, 2016

Hi @jen20 thanks for the feedback, i'll be sure to track #4169.

@ghost ghost closed this as completed Mar 21, 2016
@chbrown
Copy link
Contributor

chbrown commented Oct 10, 2016

Btw, it looks like, insofar as #4169 ever intended to implement this functionality, it got split off into #8144 (which is currently open). @apparentlymart is doing some excellent work on this front, thanks!

@ramalhais-sky
Copy link

This can be worked around with an External Data Source:
https://www.terraform.io/docs/providers/external/data_source.html

but it's alot of boilerplate

@ghost
Copy link

ghost commented Apr 5, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 5, 2020
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants