Skip to content

Commit

Permalink
Fix Import Script Bugs (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
ichung08 authored Aug 21, 2024
1 parent bf6a998 commit 0610c22
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-release-import-script.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_<version-number>_<os>_<arc>
./terraform-provider-astro-import-script_<version-number>_<os>_<arc> [options]
```

On Windows:

```
./import [options]
.\terraform-provider-astro-import-script_<version-number>_<os>_<arc>.exe [options]
```

### Options
Expand All @@ -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_<version-number>_<os>_<arc> -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_<version-number>_<os>_<arc> -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_<version-number>_<os>_<arc> -resources workspace -token your_api_token -organizationId your_org_id -host dev
```

### Output
Expand Down
14 changes: 8 additions & 6 deletions import/import_script.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:")
Expand Down

0 comments on commit 0610c22

Please sign in to comment.