-
Notifications
You must be signed in to change notification settings - Fork 55
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
DXCDT-498: Add terraform generate command skeleton #792
Conversation
e34ff05
to
9076052
Compare
## Flags | ||
|
||
``` | ||
-o, --output-dir string Output directory for the generated Terraform config files. If not provided, the files will be saved in the current working directory. (default "./") |
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 considered naming this just --dir
, however the extra verbosity adds clarity in the full form for this flag and considering there's also the short form option of -o
, I deemed unnecessary to have the flag shorter.
internal/cli/terraform.go
Outdated
|
||
cmd := &cobra.Command{ | ||
Use: "generate", | ||
Aliases: []string{"gen", "export"}, |
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.
If we are able to integrate the terraform-exec pkg as well, naming this generate makes more sense, otherwise keeping it as export would fit better. So for now I added both aliases. We can consider keeping just one of these once we explore how viable the terraform-exec pkg is for our use case of generating the config and state as well on behalf of the user.
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'd suggest adding a comment so as to not forget to remove the lesser fitting alias in the future.
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.
Also keep in mind that once this goes out in a release, the aliases will be part of the public API, and removing one will be a breaking change. So you might want to consider not adding aliases until it's clear which one should be used.
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.
A comment could also be used as a reminder for the above.
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.
Added a comment for now in 6cd31e8
(#792).
required_providers { | ||
auth0 = { | ||
source = "auth0/auth0" | ||
version = "1.0.0-beta.1" |
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.
Is there a way to set this value programmatically?
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.
Can't think of any. Any suggestions?
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.
Once v1 GA goes live, we can consider omitting the version, so it always fetches the latest stable.
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.
Once v1 GA goes live, we can consider omitting the version, so it always fetches the latest stable.
Once we eventually release v2 (e.g. in a couple of years), would this mean it will automatically fetch the new major (along with its breaking changes)?
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.
We could also use "~> 1.0"
to pin it to the v1 major, as per https://developer.hashicorp.com/terraform/language/providers/configuration#provider-configuration-1.
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.
All good things to consider, but at the moment we don't have any stable v1 so we can use "~> 1.0"
, and we need to specify the version explicitly for the beta so we can do some rapid testing as well. We'll adjust that value accordingly in the future.
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #792 +/- ##
==========================================
+ Coverage 72.04% 72.11% +0.06%
==========================================
Files 89 90 +1
Lines 11149 11223 +74
==========================================
+ Hits 8032 8093 +61
- Misses 2615 2627 +12
- Partials 502 503 +1
☔ View full report in Codecov by Sentry. |
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.
Mostly looking good but one question about an error check.
func terraformCmd(cli *cli) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "terraform", | ||
Aliases: []string{"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.
I like the tf
alias 👍
Long: "This command is designed to streamline the process of generating Terraform configuration files for " + | ||
"your Auth0 resources, serving as a bridge between the two.\n\nIt automatically scans your Auth0 Tenant " + | ||
"and compiles a set of Terraform configuration files based on the existing resources and configurations." + | ||
"\n\nThe generated Terraform files are written in HashiCorp Configuration Language (HCL).", |
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.
Reminder for us to include instructions and/or link to a guide once one is available.
func generateTerraformConfigFiles(inputs *terraformInputs) error { | ||
const readWritePermission = 0755 | ||
if err := os.MkdirAll(inputs.OutputDIR, readWritePermission); err != nil { | ||
if !os.IsExist(err) { |
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.
Does there need to be some nuance here? There's no certainty that an existing main.tf
will be compatible with the command.
Some ideas on how to manage:
- Require absence of
main.tf
- If
main.tf
exists, print warning explaining a potential incompatibility
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.
Good callout, however considering we will have the same issue with the import.tf file and the generated files, let's focus on this as a separate PR after those are added as well.
Currently, if the file exists it gets truncated and overwritten.
🔧 Changes
This PR adds the command skeleton for generating terraform config files for the Auth0 tenant.
📚 References
🔬 Testing
📝 Checklist