From 0610c2261dc871b6528aa99704080a90f1885da3 Mon Sep 17 00:00:00 2001 From: Isaac Chung <69920967+ichung08@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:25:15 -0700 Subject: [PATCH] Fix Import Script Bugs (#138) --- .../workflows/build-release-import-script.yml | 2 +- README.md | 22 ++++++++++++++----- import/import_script.go | 14 +++++++----- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build-release-import-script.yml b/.github/workflows/build-release-import-script.yml index b0e19e1d..68f5fbb0 100644 --- a/.github/workflows/build-release-import-script.yml +++ b/.github/workflows/build-release-import-script.yml @@ -80,7 +80,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: tag_name: ${{ steps.get_version.outputs.VERSION }} - release_name: Release ${{ steps.get_version.outputs.VERSION }} + release_name: Release Astro Import Script ${{ steps.get_version.outputs.VERSION }} draft: false prerelease: false diff --git a/README.md b/README.md index 58a898d9..88101c13 100644 --- a/README.md +++ b/README.md @@ -207,10 +207,20 @@ The acceptance tests will run against the Astronomer API and create/read/update/ The Astro Terraform Import Script is a tool designed to help you import existing Astro resources into your Terraform configuration. Currently, this script automates the process of generating Terraform import blocks and resource configurations for the following resources: workspaces, deployments, clusters, hybrid cluster workspace authorizations, API tokens, teams, team roles, and user roles. -To use the import script, download the `import_script` executable file from [releases](https://github.com/astronomer/terraform-provider-astro/releases) and run it with the following command: +To use the import script, download the `terraform-provider-astro-import-script` executable file from [releases](https://github.com/astronomer/terraform-provider-astro/releases) based on your OS and architecture and run it with the following command: + +On Unix-based systems: + +``` +chmod +x terraform-provider-astro-import-script___ + +./terraform-provider-astro-import-script___ [options] +``` + +On Windows: ``` -./import [options] +.\terraform-provider-astro-import-script___.exe [options] ``` ### Options @@ -219,24 +229,24 @@ To use the import script, download the `import_script` executable file from [rel - `-token`: API token to authenticate with the Astro platform. If not provided, the script will attempt to use the `ASTRO_API_TOKEN` environment variable. - `-host`: API host to connect to. Default is https://api.astronomer.io. Use "dev" for https://api.astronomer-dev.io or "stage" for https://api.astronomer-stage.io. - `-organizationId`: Organization ID to import resources from. -- `-runTerraformInit`: Run `terraform init` after generating the import configuration. +- `-runTerraformInit`: Run `terraform init` after generating the import configuration. Used for initializing the Terraform state in our GitHub Actions. - `-help`: Display help information. ### Examples 1. Import workspaces and deployments: ``` - ./import -resources workspace,deployment -token your_api_token -organizationId your_org_id + ./terraform-provider-astro-import-script___ -resources workspace,deployment -token your_api_token -organizationId your_org_id ``` 2. Import all supported resources and run Terraform init: ``` - ./import -resources workspace,deployment,cluster,api_token,team,team_roles,user_roles -token your_api_token -organizationId your_org_id -runTerraformInit + ./terraform-provider-astro-import-script___ -resources workspace,deployment,cluster,api_token,team,team_roles,user_roles -token your_api_token -organizationId your_org_id -runTerraformInit ``` 3. Use a different API host (e.g., dev environment): ``` - ./import -resources workspace -token your_api_token -organizationId your_org_id -host dev + ./terraform-provider-astro-import-script___ -resources workspace -token your_api_token -organizationId your_org_id -host dev ``` ### Output diff --git a/import/import_script.go b/import/import_script.go index 3d2e6441..9a9a0390 100644 --- a/import/import_script.go +++ b/import/import_script.go @@ -224,13 +224,15 @@ provider "astro" { } // Add deployment import blocks and HCL to the generated file - err = addDeploymentsToGeneratedFile(deploymentImportString, organizationId, platformClient, ctx) - if err != nil { - log.Fatalf("Failed to add deployments to generated file: %v", err) - return - } + if deploymentImportString != "" { + err = addDeploymentsToGeneratedFile(deploymentImportString, organizationId, platformClient, ctx) + if err != nil { + log.Fatalf("Failed to add deployments to generated file: %v", err) + return + } - log.Println("Import process completed successfully. The 'generated.tf' file now includes all resources, including deployments.") + log.Println("Import process completed successfully. The 'generated.tf' file now includes all resources, including deployments.") + } // Print summary of results log.Println("Import process completed. Summary:")