Skip to content

Commit

Permalink
DXCDT-543: Refining tf generate output instructions (#842)
Browse files Browse the repository at this point in the history
* Refining output language

* Fixing insufficient credentials case

* Update internal/cli/terraform.go

Co-authored-by: Sergiu Ghitea <[email protected]>

* Update internal/cli/terraform.go

Co-authored-by: Rita Zerrizuela <[email protected]>

* Update internal/ansi/ansi.go

Co-authored-by: Rita Zerrizuela <[email protected]>

* Update internal/cli/terraform.go

Co-authored-by: Rita Zerrizuela <[email protected]>

---------

Co-authored-by: Will Vedder <[email protected]>
Co-authored-by: Sergiu Ghitea <[email protected]>
Co-authored-by: Rita Zerrizuela <[email protected]>
  • Loading branch information
4 people authored Sep 14, 2023
1 parent 04fad78 commit 4ad5657
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 28 deletions.
5 changes: 5 additions & 0 deletions internal/ansi/ansi.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ func Italic(text string) string {
return color.Sprintf(color.Italic(text))
}

// URL formats URL links if the writer supports it.
func URL(text string) string {
return color.Sprintf(color.Underline(text))
}

// Red returns text colored red.
func Red(text string) string {
return color.Sprintf(color.Red(text))
Expand Down
55 changes: 27 additions & 28 deletions internal/cli/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,43 +166,42 @@ func generateTerraformCmdRun(cli *cli, inputs *terraformInputs) func(cmd *cobra.
return err
}

cdInstructions := ""
if inputs.OutputDIR != "./" {
cdInstructions = fmt.Sprintf("cd %s && ", inputs.OutputDIR)
}

if terraformProviderCredentialsAreAvailable() {
err = ansi.Spinner("Generating Terraform configuration", func() error {
return generateTerraformResourceConfig(cmd.Context(), inputs.OutputDIR)
})

if err == nil {
cli.renderer.Infof("Terraform resource config files generated successfully in: %q", inputs.OutputDIR)
cli.renderer.Infof(
"Review the config and generate the terraform state by running: \n\n cd %s && ./terraform apply",
inputs.OutputDIR,
)
cli.renderer.Newline()
cli.renderer.Infof(
"After running the above command and generating the state, " +
"the ./terraform binary and auth0_import.tf files can be safely removed.\n",
)

if err != nil {
cli.renderer.Warnf("Terraform resource config generated successfully but there was an error with terraform plan.\n\n")
cli.renderer.Warnf("Run " + ansi.Cyan(cdInstructions+"./terraform plan") + " to troubleshoot\n\n")
cli.renderer.Warnf("Once the plan succeeds, run " + ansi.Cyan("./terraform apply") + " to complete the import.\n\n")
cli.renderer.Infof("The terraform binary and auth0_import.tf files can be deleted afterwards.\n")
return nil
}

cli.renderer.Infof("Terraform resource config files generated successfully in: %s", inputs.OutputDIR)
cli.renderer.Infof(
"Review the config and generate the terraform state by running: \n\n " + ansi.Cyan(cdInstructions+"./terraform apply") + "\n",
)
cli.renderer.Infof(
"Once Terraform files are auto-generated, the terraform binary and auth0_import.tf files can be deleted.\n",
)

return nil
}

cli.renderer.Infof("Terraform resource import files generated successfully in: %q", inputs.OutputDIR)
cli.renderer.Infof(
"Follow this " +
"[quickstart](https://registry.terraform.io/providers/auth0/auth0/latest/docs/guides/quickstart) " +
"to go through setting up an Auth0 application for the provider to authenticate against and manage " +
"resources.",
)
cli.renderer.Infof(
"After setting up the provider credentials, run: \n\n"+
" cd %s && terraform init && terraform plan -generate-config-out=auth0_generated.tf && terraform apply",
inputs.OutputDIR,
)
cli.renderer.Newline()
cli.renderer.Infof(
"After running the above command and generating the state, " +
"the auth0_import.tf file can be safely removed.\n",
cli.renderer.Errorf("Terraform provider credentials not detected\n")
cli.renderer.Warnf(
"Refer to following guide on how to create a dedicated Auth0 client and configure credentials: " +
ansi.URL("https://registry.terraform.io/providers/auth0/auth0/latest/docs/guides/quickstart") + "\n\n" +
"After provider credentials are set, run: \n\n" +
ansi.Cyan(cdInstructions+"terraform init && terraform plan -generate-config-out=auth0_generated.tf && terraform apply") + "\n\n" +
"Once the Terraform file is auto-generated, the auth0_import.tf file can be deleted.\n",
)

return nil
Expand Down

0 comments on commit 4ad5657

Please sign in to comment.