-
Notifications
You must be signed in to change notification settings - Fork 273
Config Generation: Go implementation for executing Terraform binary #1592
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
Conversation
|
In order to lower resource usage and have a faster runtime, PRs will not run Cloud tests automatically. |
| gopkg.in/yaml.v3 v3.0.1 // indirect | ||
| ) | ||
|
|
||
| replace github.com/hashicorp/terraform-exec v0.21.0 => github.com/hrmsk66/terraform-exec v0.21.0 |
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.
Using a fork awaiting the merge of this PR: hashicorp/terraform-exec#446
| func setupTerraform(cfg *Config) (*tfexec.Terraform, error) { | ||
| installer := &releases.ExactVersion{ | ||
| Product: product.Terraform, | ||
| Version: version.Must(version.NewVersion("1.8.4")), |
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've pinned the version here for now, should probably become configurable.
| state, err := runTerraformWithOutput(dir, "show", "-json") | ||
| func getState(ctx context.Context, cfg *Config) (*tfjson.State, error) { |
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.
tfexec implements tfjson to read the state, hence the big changeset in this file.
| stack := stack{ | ||
| name: stackName, | ||
| managementKey: cfg.Grafana.Auth, | ||
| url: cfg.Grafana.URL, | ||
| smToken: "", | ||
| smURL: "", | ||
| } |
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.
Synthesizing a stack here to reduce the signatures of the generate functions.
| if err != nil { | ||
| return fmt.Errorf("failed to run terraform init: %w", err) | ||
| } | ||
| cfg.Terraform = tf |
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.
Not sure if this is the best place to put it, probably not but, eh 🤷
dbab7b6 to
ed45869
Compare
julienduchesne
left a comment
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.
Nice!
go.mod
Outdated
| golang.org/x/text v0.15.0 | ||
| ) | ||
|
|
||
| require ( |
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.
Merge this with the upper block IMO
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've just used go mod edit -replace and go mod tidy, stupid tools doing stupid things :P
This PR refactors the generator to use https://github.com/hashicorp/terraform-exec/ to execute the Terraform binary. This removes the need for the user to provide the Terraform binary as part of their runtime environment, allowing the generator to be used as a library with less friction.