Skip to content
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-543: Refining tf generate output instructions #842

Merged
merged 10 commits into from
Sep 14, 2023
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
Loading