-
Notifications
You must be signed in to change notification settings - Fork 157
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
Feature/variables data source #369
Feature/variables data source #369
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for implementing this! It looks very promising. Here's my initial code review. Tomorrow I'll take some time to smoke test and ensure everything works as I imagine it did.
tfe/data_source_variables.go
Outdated
if variable.Category == "terraform" { | ||
result := make(map[string]interface{}) | ||
result["id"] = variable.ID | ||
result["name"] = variable.Key | ||
result["category"] = variable.Category | ||
result["hcl"] = variable.HCL | ||
if variable.Sensitive != true { | ||
result["value"] = variable.Value | ||
} else { | ||
result["value"] = "***" | ||
} | ||
|
||
terraformVars = append(terraformVars, result) | ||
} else if variable.Category == "env" { | ||
result := make(map[string]interface{}) | ||
result["id"] = variable.ID | ||
result["name"] = variable.Key | ||
result["category"] = variable.Category | ||
result["hcl"] = variable.HCL | ||
if variable.Sensitive != true { | ||
result["value"] = variable.Value | ||
} else { | ||
result["value"] = "***" | ||
} | ||
|
||
envVars = append(envVars, result) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since these two conditions are identical, you can use the condition to figure out which slice to append result to:
I would also add "sensitive" to the schema and set that:
if variable.Category == "terraform" { | |
result := make(map[string]interface{}) | |
result["id"] = variable.ID | |
result["name"] = variable.Key | |
result["category"] = variable.Category | |
result["hcl"] = variable.HCL | |
if variable.Sensitive != true { | |
result["value"] = variable.Value | |
} else { | |
result["value"] = "***" | |
} | |
terraformVars = append(terraformVars, result) | |
} else if variable.Category == "env" { | |
result := make(map[string]interface{}) | |
result["id"] = variable.ID | |
result["name"] = variable.Key | |
result["category"] = variable.Category | |
result["hcl"] = variable.HCL | |
if variable.Sensitive != true { | |
result["value"] = variable.Value | |
} else { | |
result["value"] = "***" | |
} | |
envVars = append(envVars, result) | |
} | |
result := make(map[string]interface{}) | |
result["id"] = variable.ID | |
result["name"] = variable.Key | |
result["category"] = variable.Category | |
result["hcl"] = variable.HCL | |
result["sensitive"] = variable.Sensitive | |
result["value"] = variable.Value | |
if variable.Category == "terraform" { | |
terraformVars = append(terraformVars, result) | |
} else if variable.Category == "env" { | |
envVars = append(envVars, result) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
big commit incoming solving also this
tfe/data_source_variables.go
Outdated
totalVariables = append(totalVariables, terraformVars...) | ||
totalVariables = append(totalVariables, envVars...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to not interleave pages of terraform and env variables in this collection. At the end, you can just append totalEnvVariables to totalTerraformVariables (see below) so that all the terraform variables come first and all the env variables come after. It also simplifies the code and reduces copying.
totalVariables = append(totalVariables, terraformVars...) | |
totalVariables = append(totalVariables, envVars...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Co-authored-by: Brandon Croft <brandon.croft@gmail.com>
Co-authored-by: Brandon Croft <brandon.croft@gmail.com>
Co-authored-by: Brandon Croft <brandon.croft@gmail.com>
Co-authored-by: Brandon Croft <brandon.croft@gmail.com>
Co-authored-by: Brandon Croft <brandon.croft@gmail.com>
Co-authored-by: Brandon Croft <brandon.croft@gmail.com>
Co-authored-by: Brandon Croft <brandon.croft@gmail.com>
Co-authored-by: Brandon Croft <brandon.croft@gmail.com>
@kilwa0 Thanks for making my recommended changes! I didn't have time to finalize my testing yet but this is still on my radar. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One final tweak! Thanks again
@kilwa0 Congrats and thanks for the excellent contribution. You're always welcome to submit more changes that simplify your workflow. |
@brandonc My pleasure. |
Description
Hi all, this change add the variables data source. It outputs into a list some useful values from the configured variables on a given worskpace
It outputs three values:
variables
- the whole setterraform
- only the terraform categorized variablesenvironment
- the environment variables into the worskpaceAs you can tell English is not my primary language so please double check documentation for misspelled words :)
Please let me know if you need anything from me
Regards
Testing plan
Acceptance test creates:
End checks the id and the outputs of the data source
Output from acceptance tests