Skip to content

Commit

Permalink
Update generated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
yanmastin-astro committed Oct 21, 2024
1 parent 4e0559c commit 6c5dddc
Showing 1 changed file with 43 additions and 32 deletions.
75 changes: 43 additions & 32 deletions docs/guides/import-script.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@ page_title: "Use Terraform Import Script to migrate existing resources"
# Use Import Script to migrate existing resources
The Astro Terraform Import Script is a tool designed to help you import existing Astro resources into your Terraform configuration.

In this guide, we will automate the migration of an existing Deployment, API token and Team into Terraform using the Terraform Import Script.

### Supported Resources
- Workspace
- Deployment
- Cluster
- Hybrid Cluster Workspace Authorization
- API Token
- Team
- Team Roles
- User Roles
In this guide, we will migrate an existing Workspace, API token and Team into Terraform using the Terraform Import Script.

### Import Script options
- `-resources`: Comma-separated list of resources to import. Accepted values are
`workspace`, `deployment`, `cluster`, `api_token`, `team`, `team_roles`,and `user_roles`. If not provided, all resources are imported.

-> Ensure you have the necessary permissions in your Astro organization to access the resources you're attempting to import.

- `-token`: API token to authenticate with the Astro platform. If not provided, the script will attempt to use the ASTRO_API_TOKEN environment variable.
- `-organizationId`: Organization ID to import resources from.
- `-runTerraformInit`: Run terraform init after generating the import configuration. Used for initializing the Terraform state in our GitHub Actions.
- `-help`: Display help information.


## Prerequisites
- An [Astro](https://www.astronomer.io/product/) organization with a Workspace, Team, and API token
- An initialized Terraform working directory

## Step 1: Download the Import Script
1. 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. For this guide, the script will be `terraform-provider-astro-import-script_v0.1.3_darwin_arm64`.
Expand Down Expand Up @@ -44,49 +50,54 @@ chmod +x terraform-provider-astro-import-script_<version-number>_<os&gt
```
.\terraform-provider-astro-import-script_<version-number>_<os>_<arc>.exe [options]
```
### Options
- `-resources`: Comma-separated list of resources to import. Accepted values are workspace, deployment, cluster, api_token, team, team_roles, user_roles. If not provided, all resources are imported.

-> Ensure you have the necessary permissions in your Astro organization to access the resources you're attempting to import.

- `-token`: API token to authenticate with the Astro platform. If not provided, the script will attempt to use the ASTRO_API_TOKEN environment variable.
- `-organizationId`: Organization ID to import resources from.
- `-runTerraformInit`: Run terraform init after generating the import configuration. Used for initializing the Terraform state in our GitHub Actions.
- `-help`: Display help information.

To import your existing Deployment, API token and Team, specify those resources with the `-resources` option. The other option you will need to specify is `-organizationId`:
To import your existing Workspace, API token and Team, specify those resources with the `-resources` option. The other option you will need to specify is `-organizationId`:
```
./terraform-provider-astro-import-script_v0.1.3_darwin_arm64 -organizationId <your-organization-id> -resources deployment,team
./terraform-provider-astro-import-script_v0.1.3_darwin_arm64 -organizationId <your-organization-id> -resources api_token,team,workspace
```

You should see the following output:
```
Terraform Import Script Starting
Resources to import: [team api_token]
Resources to import: [api_token team workspace]
Using organization ID: <your-organization-id&gt
Terraform version 1.9.7 is installed and meets the minimum required version.
Importing teams for organization <your-organization-id&gt
Importing API tokens for organization <your-organization-id&gt
Importing Teams: [<your-team-id&gt]
Successfully handled resource team
Importing API Tokens: [<your-token-id&gt]
Importing workspaces for organization <your-organization-id&gt
Importing Workspaces: [<workspace-id&gt]
Successfully handled resource workspace
Importing API Tokens: [<api_token-id&gt]
Successfully handled resource api_token
Importing Teams: [<team-id&gt]
Successfully handled resource team
Successfully wrote import configuration to import.tf
Successfully deleted generated.tf
terraform.tfstate does not exist, no need to delete
astro_api_token.api_token_<your-token-id&gt: Preparing import... [id=<your-token-id&gt]
astro_team.team_<your-team-id&gt: Preparing import... [id=<your-team-id&gt]
astro_team.team_<your-team-id&gt: Refreshing state... [id=<your-team-id&gt]
astro_api_token.api_token_<your-token-id&gt: Refreshing state... [id=<your-token-id&gt]
astro_team.team_<team-id&gt: Preparing import... [id=<team-id&gt]
astro_api_token.api_token_cm2c9slvb08p601n3lb4jljps: Preparing import... [id=cm2c9slvb08p601n3lb4jljps]
astro_workspace.workspace_<workspace-id&gt: Preparing import... [id=<workspace-id&gt]
astro_workspace.workspace_<workspace-id&gt: Refreshing state... [id=<workspace-id&gt]
astro_api_token.api_token_<api_token-id&gt: Refreshing state... [id=<api_token-id&gt]
astro_team.team_<team-id&gt: Refreshing state... [id=<team-id&gt]
Terraform will perform the following actions:
...
Plan: 2 to import, 0 to add, 0 to change, 0 to destroy.
Plan: 3 to import, 0 to add, 0 to change, 0 to destroy.
Terraform has generated configuration and written it to generated.tf. Please review the configuration and edit it as
necessary before adding it to version control.
Terraform has generated configuration and written it to generated.tf. Please review the configuration and edit it as necessary before adding it to version control.
Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you
run "terraform apply" now.
Import process completed. Summary:
Resource workspace processed successfully
Resource api_token processed successfully
Resource team processed successfully
```
-> If you import Deployments, they will not count torwards the `Plan: 3 to import, 0 to add, 0 to change, 0 to destroy` line of the output even when the Deployments are successfully imported.

## Step 3: Review output
The script will generate two main files:
Expand Down

0 comments on commit 6c5dddc

Please sign in to comment.