Dynamic changes in terraform configuration file

426 views
Skip to first unread message

kperi...@nvidia.com

unread,
Sep 4, 2018, 12:42:21 AM9/4/18
to Terraform
 could anyone have suggestions for my case :
is anyway we can fetch/quiry data from database[mysql] & update the terraform configuration ?

What if some value in terraform configuration as to change dynamically, It's not good to manually edit configuration file manually. Anyone have any suggestion/ideas Please let me know.

Thanks.

Oliver Schrenk

unread,
Sep 4, 2018, 2:31:57 AM9/4/18
to terrafo...@googlegroups.com
Terraform novice here, so there might be a more  terraform way but is writing  a script that populates a variables file an option?

In addition to that script, you write a wrapper bash script, first executing your database script and then runs terraform?
--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/65683a89-61f3-4b95-bc4f-1ec939899c58%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

kperi...@nvidia.com

unread,
Sep 4, 2018, 2:39:14 AM9/4/18
to Terraform
Thanks for kind response Oliver, I understand I can use the script to update DB data & create terraform  configuration [json] file based on the DB data but just thinking it doesn't seems effective way to do. 

Is terraform have any inbuild/ external tool feature where we can pull data from DB & modify/update/create the configuration file ? [without our custom script]   I searched for this requirement but am unable to get right solution !! :( 

Anshu Prateek

unread,
Sep 4, 2018, 3:33:15 AM9/4/18
to Terraform
You will have to make use of https://www.terraform.io/docs/providers/external/data_source.html to work w. data from DB. You will still need a wrapper script to get the data in required format.


For more options, visit https://groups.google.com/d/optout.


--

Steven Nemetz

unread,
Sep 5, 2018, 12:03:05 AM9/5/18
to Terraform
Depends a little on what type of data you are trying to get and use.
All methods require a custom script to get the data from the database and format it, unless a provider was written with database data sources. The MySQL provider currently doesn't have data sources.

Methods:
  1. Wrapper or pre-terraform scripts
    • This could create a .tfvar or .tf file (hcl or json)
    • Could create TF_VAR_ environment variables
    • As a wrapper, would build the terraform command line with all the variables
  2. external/data_source provider
    • In this case terraform runs your script and the output must be json, which Terraform will read in and can be referenced
All of these methods work for string variables.
If you need something other than strings, then there can be differences in the methods.
Terraform json parser is not true json, which prevents it's use for complex data structures.
I'd advise against uses complex data structures. But if you do need them, you may be forced to generate a hcl file

They are other obscure methods, that I'd recommend not using.

Kumaresan

unread,
Sep 10, 2018, 11:24:38 AM9/10/18
to Terraform
Thanks all got some really good stuff :) 
Reply all
Reply to author
Forward
0 new messages