Skip to content

Commit c781538

Browse files
yanmastin-astroichung08BasPH
authored
Doc enhancements (#177)
Co-authored-by: Isaac Chung <69920967+ichung08@users.noreply.github.com> Co-authored-by: Bas Harenslak <bas@astronomer.io>
1 parent d1333d4 commit c781538

File tree

2 files changed

+46
-227
lines changed

2 files changed

+46
-227
lines changed

CONTRIBUTING.md

+19-36
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ Welcome to the Terraform Provider Astro project! We're excited that you're inter
77
1. [Development Environment Setup](#development-environment-setup)
88
2. [Making Changes](#making-changes)
99
3. [Testing](#testing)
10-
4. [Submitting Pull Requests](#submitting-pull-requests)
11-
5. [Reporting Issues](#reporting-issues)
12-
6. [Best Practices](#best-practices)
13-
7. [Additional Resources](#additional-resources)
10+
4. [Reporting Issues](#reporting-issues)
11+
5. [Best Practices](#best-practices)
12+
6. [Additional Resources](#additional-resources)
1413

1514
## Development Environment Setup
1615

@@ -85,46 +84,30 @@ Ensure you have the following installed:
8584
4. Update documentation if your changes affect the provider's behavior or add new features.
8685

8786
## Testing
87+
1. Run unit tests with `make test`.
8888

89-
1. Run unit tests:
90-
```
91-
make test
92-
```
89+
2. Run acceptance tests (these will create real resources in your Astro account) with `make testacc`. Acceptance integration tests use a Terraform CLI binary to run real Terraform commands against the Astro API. The goal is to approximate using the provider with Terraform in production as closely as possible.
9390

94-
2. Run acceptance tests (these will create real resources in your Astro account):
95-
```
96-
make testacc
97-
```
98-
Note: Ensure all required environment variables are set as described in `internal/provider/provider_test_utils.go`.
91+
Using the terraform-plugin-testing framework, each `resource.Test` runs an acceptance test on a resource.
92+
- `ProtoV6ProviderFactories`: map of the provider factories that the test suite will use to create the provider - just has the `astronomer` provider
93+
- `PreCheck`: a function that runs before the test suite starts to check that all the required environment variables are set
94+
- `Steps`: a list of `terraform apply` sequences that the test suite will run. Each step is a `resource.TestStep` that contains a `Config` and `Check` function.
95+
- `Config`: the Terraform configuration that the test will run (ie. the `.tf` file)
96+
- `Check`: function that will verify the state of the resources after the `terraform apply` command has run.
9997

100-
3. Test your changes manually using the `main.tf` file you created earlier:
101-
```
102-
terraform init
103-
terraform plan
104-
terraform apply
105-
```
98+
In order to run the full suite of Acceptance tests, run `make testacc`.
99+
You will also need to set all the environment variables described in `internal/provider/provider_test_utils.go`.
106100

107-
## Submitting Pull Requests
101+
The acceptance tests will run against the Astronomer API and create/read/update/delete real resources.
108102

109-
1. Commit your changes:
110-
```
111-
git add .
112-
git commit -m "Description of your changes"
113-
```
103+
3. Test your changes manually using the main.tf file you created earlier:
114104

115-
2. Push your branch to GitHub:
116105
```
117-
git push origin feature/your-feature-name
106+
terraform init
107+
terraform plan
108+
terraform apply
118109
```
119110

120-
3. Open a pull request on GitHub.
121-
122-
4. In your pull request description, include:
123-
- A clear description of the changes
124-
- Any related issue numbers
125-
- Steps to test the changes
126-
- Screenshots or code snippets if applicable
127-
128111
## Reporting Issues
129112

130113
If you encounter a bug or have a suggestion for improvement, please create an issue on the GitHub repository. This helps us track and address problems efficiently.
@@ -176,4 +159,4 @@ If you discover a security vulnerability, please do NOT open an issue. Email sec
176159
- [Terraform Plugin Framework Documentation](https://developer.hashicorp.com/terraform/plugin/framework)
177160
- [Go Documentation](https://golang.org/doc/)
178161

179-
Thank you for contributing to the Terraform Provider Astro project! Your efforts help improve the experience for all Astro users.
162+
Thank you for contributing to the Terraform Provider Astro project! Your efforts help improve the experience for all Astro users.

README.md

+27-191
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,14 @@
1-
# Terraform Provider Astro
2-
3-
## Requirements
4-
5-
- [Terraform](https://developer.hashicorp.com/terraform/downloads) >= 1.7
6-
- [Go](https://golang.org/doc/install) >= 1.21
7-
8-
## Building The Provider
9-
10-
1. Clone the repository
11-
2. Enter the repository directory
12-
3. Build the provider using the following `Makefile` command:
13-
14-
```shell
15-
make dep
16-
make build
17-
```
18-
19-
4. The provider binary will be available in the `bin` directory
20-
21-
## Adding Dependencies
22-
23-
This provider uses [Go modules](https://github.com/golang/go/wiki/Modules).
24-
Please see the Go documentation for the most up-to-date information about using Go modules.
25-
26-
To add a new dependency `github.com/author/dependency` to your Terraform provider:
27-
28-
```shell
29-
go get github.com/author/dependency
30-
go mod tidy
31-
```
32-
33-
Then commit the changes to `go.mod` and `go.sum`.
1+
<div align="center">
2+
<picture>
3+
<img src="https://github.com/user-attachments/assets/f89d2532-c360-4082-b899-be2593bb2483" width="200">
4+
</picture>
5+
<p>Official Astro Terraform Provider to configure and manage your Astro infrastructure through an API.</p>
6+
<a href="https://registry.terraform.io/providers/astronomer/astro/latest/docs"><img src="https://img.shields.io/static/v1?label=Docs&labelColor=0F0C27&message=terraform-provider-astro&color=4E408D&style=for-the-badge" /></a>
7+
<a href="https://astronomer.docs.buildwithfern.com/docs/api/overview"><img src="https://img.shields.io/static/v1?label=Docs&labelColor=0F0C27&message=API Ref&color=4E408D&style=for-the-badge" /></a>
8+
</div>
349

3510
## Using the provider
36-
1. Create an [API Token](https://docs.astronomer.io/astro/automation-authentication#step-1-create-an-api-token) to use in the provider. We recommend creating an organization API token since it is the most flexible but the type of your API token will depend on your use case.
11+
1. Create an [API Token](https://docs.astronomer.io/astro/automation-authentication#step-1-create-an-api-token) to use in the provider. Astronomer recommends creating an Organization API token since it is the most flexible but the type of your API token will depend on your use case.
3712
2. Create a `main.tf` file with the following content:
3813
```terraform
3914
terraform {
@@ -50,6 +25,8 @@ provider "astro" {
5025
5126
# your terraform commands here
5227
```
28+
See [Astro Provider docs](https://registry.terraform.io/providers/astronomer/astro/latest/docs) for supported resources and data sources.
29+
5330
3. Run the following commands to apply the provider:
5431
```shell
5532
export ASTRO_API_TOKEN=<token>
@@ -58,154 +35,10 @@ terraform plan # creates a plan consisting of a set of changes that will make yo
5835
terraform apply # performs a plan just like terraform plan does, but then actually carries out the planned changes to each resource using the relevant infrastructure provider's API
5936
```
6037

61-
## Developing the Provider
62-
63-
If you wish to work on the provider, you'll first need [Go](http://www.golang.org) installed on your machine (see [Requirements](#requirements) above).
64-
65-
To compile the provider, see [Building The Provider](#building-the-provider).
66-
67-
To add example docs, add the correspond `.tf` files to the `examples` directory. These should be added for every new data source and resource.
68-
69-
To run terraform with the provider, create a `.terraformrc` file in your home directory (`~`) with the following content to override the provider installation with the local build:
70-
71-
```hcl
72-
provider_installation {
73-
dev_overrides {
74-
"registry.terraform.io/astronomer/astro" = "~/terraform-provider-astro/bin" # Your path to the provider binary
75-
}
76-
direct {}
77-
}
78-
```
79-
80-
## Example `main.tf` file for development and testing data sources and resources
81-
```terraform
82-
terraform {
83-
required_providers {
84-
astro = {
85-
source = "astronomer/astro"
86-
}
87-
}
88-
}
89-
90-
# provider configuration
91-
provider "astro" {
92-
organization_id = "<cuid>"
93-
}
94-
95-
# get information on an existing workspace
96-
data "astro_workspace" "example" {
97-
id = "<cuid>"
98-
}
99-
100-
# output the workspace data to the terminal
101-
output "data_workspace_example" {
102-
value = data.astro_workspace.example
103-
}
104-
105-
# create a new workspace
106-
resource "astro_workspace" "tf_workspace" {
107-
name = "my workspace"
108-
description = "my first workspace"
109-
cicd_enforced_default = false
110-
}
111-
112-
# output the newly created workspace resource to the terminal
113-
output "terraform_workspace" {
114-
value = astro_workspace.tf_workspace
115-
}
116-
117-
# create a new cluster resource
118-
resource "astro_cluster" "tf_cluster" {
119-
type = "DEDICATED"
120-
name = "my first cluster"
121-
region = "us-east-1"
122-
cloud_provider = "AWS"
123-
vpc_subnet_range = "172.20.0.0/20"
124-
workspace_ids = [astro_workspace.tf_workspace.id, data.astro_workspace.example.id]
125-
timeouts = {
126-
create = "3h"
127-
update = "2h"
128-
delete = "20m"
129-
}
130-
}
131-
132-
# create a new dedicated deployment resource in that cluster
133-
resource "astro_deployment" "tf_dedicated_deployment" {
134-
name = "my first dedicated deployment"
135-
description = ""
136-
cluster_id = astro_cluster.tf_cluster.id
137-
type = "DEDICATED"
138-
contact_emails = ["example@astronomer.io"]
139-
default_task_pod_cpu = "0.25"
140-
default_task_pod_memory = "0.5Gi"
141-
executor = "KUBERNETES"
142-
is_cicd_enforced = true
143-
is_dag_deploy_enabled = true
144-
is_development_mode = false
145-
is_high_availability = true
146-
resource_quota_cpu = "10"
147-
resource_quota_memory = "20Gi"
148-
scheduler_size = "SMALL"
149-
workspace_id = astro_workspace.tf_workspace.id
150-
environment_variables = [{
151-
key = "key1"
152-
value = "value1"
153-
is_secret = false
154-
}]
155-
}
156-
157-
# create a new standard deployment resource
158-
resource "astro_deployment" "tf_standard_deployment" {
159-
name = "my first standard deployment"
160-
description = ""
161-
type = "STANDARD"
162-
cloud_provider = "AWS"
163-
region = "us-east-1"
164-
contact_emails = []
165-
default_task_pod_cpu = "0.25"
166-
default_task_pod_memory = "0.5Gi"
167-
executor = "CELERY"
168-
is_cicd_enforced = true
169-
is_dag_deploy_enabled = true
170-
is_development_mode = false
171-
is_high_availability = false
172-
resource_quota_cpu = "10"
173-
resource_quota_memory = "20Gi"
174-
scheduler_size = "SMALL"
175-
workspace_id = astro_workspace.tf_workspace.id
176-
environment_variables = []
177-
worker_queues = [{
178-
name = "default"
179-
is_default = true
180-
astro_machine = "A5"
181-
max_worker_count = 10
182-
min_worker_count = 0
183-
worker_concurrency = 1
184-
}]
185-
}
186-
```
187-
188-
## Testing
189-
Unit tests can be run with `make test`.
190-
191-
### Acceptance tests
192-
Acceptance integration tests use a Terraform CLI binary to run real Terraform commands against the Astro API. The goal is to approximate using the provider with Terraform in production as closely as possible.
193-
194-
Using the terraform-plugin-testing framework, each `resource.Test` runs an acceptance test on a resource.
195-
- `ProtoV6ProviderFactories`: map of the provider factories that the test suite will use to create the provider - just has the `astronomer` provider
196-
- `PreCheck`: a function that runs before the test suite starts to check that all the required environment variables are set
197-
- `Steps`: a list of `terraform apply` sequences that the test suite will run. Each step is a `resource.TestStep` that contains a `Config` and `Check` function.
198-
- `Config`: the Terraform configuration that the test will run (ie. the `.tf` file)
199-
- `Check`: function that will verify the state of the resources after the `terraform apply` command has run.
200-
201-
In order to run the full suite of Acceptance tests, run `make testacc`.
202-
You will also need to set all the environment variables described in `internal/provider/provider_test_utils.go`.
203-
204-
The acceptance tests will run against the Astronomer API and create/read/update/delete real resources.
205-
20638
## Importing Existing Resources
20739
The Astro Terraform Import Script is a tool designed to help you import existing Astro resources into your Terraform configuration.
208-
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.
40+
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.
41+
See Astro's [import script guide](https://registry.terraform.io/providers/astronomer/astro/latest/docs/guides/import-script) for more information.
20942

21043
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:
21144

@@ -226,26 +59,31 @@ On Windows:
22659
### Options
22760

22861
- `-resources`: Comma-separated list of resources to import. Accepted values are workspace, deployment, cluster, api_token, team, team_roles, user_roles.
229-
- `-token`: API token to authenticate with the Astro platform. If not provided, the script will attempt to use the `ASTRO_API_TOKEN` environment variable.
230-
- `-organizationId`: Organization ID to import resources from.
62+
- `-token`: API token to authenticate with the Astro platform. This requires the Organization Owner role. If not provided, the script will attempt to use the `ASTRO_API_TOKEN` environment variable.
63+
- `-organizationId`: (Required) Organization ID to import resources from.
23164
- `-runTerraformInit`: Run `terraform init` after generating the import configuration. Used for initializing the Terraform state in our GitHub Actions.
23265
- `-help`: Display help information.
23366

23467
### Examples
23568

236-
1. Import workspaces and deployments:
69+
1. Import all resources:
70+
```
71+
./terraform-provider-astro-import-script_<version-number>_<os>_<arc> -organizationId <your_org_id> -token <your_api_token>
72+
```
73+
74+
2. Import only workspaces and deployments:
23775
```
238-
./terraform-provider-astro-import-script_<version-number>_<os>_<arc> -resources workspace,deployment -token your_api_token -organizationId your_org_id
76+
./terraform-provider-astro-import-script_<version-number>_<os>_<arc> -resources workspace,deployment -token <your_api_token> -organizationId <your_org_id>
23977
```
24078

241-
2. Import all supported resources and run Terraform init:
79+
3. Import all supported resources and run Terraform init:
24280
```
243-
./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
81+
./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
24482
```
24583

246-
3. Use a different API host (e.g., dev environment):
84+
4. Use a different API host (for example, dev environment):
24785
```
248-
./terraform-provider-astro-import-script_<version-number>_<os>_<arc> -resources workspace -token your_api_token -organizationId your_org_id
86+
./terraform-provider-astro-import-script_<version-number>_<os>_<arc> -resources workspace -token <your_api_token> -organizationId <your_org_id>
24987
```
25088

25189
### Output
@@ -277,8 +115,6 @@ The script will generate two main files:
277115
4. **What Terraform versions are required?**
278116
- Terraform >= 1.7.
279117

280-
5. **How can I contribute to the provider's development?**
281-
- Submit pull requests, report issues, or suggest improvements on the GitHub repository.
282118

283119
### Troubleshooting
284120

@@ -300,4 +136,4 @@ The script will generate two main files:
300136

301137
Solution: Ensure your `.terraformrc` file is correctly set up, especially if you're using a local build of the provider for development.
302138

303-
If you encounter any issues not listed here, please check the [GitHub Issues](https://github.com/astronomer/terraform-provider-astro/issues) page or open a new issue with details about your problem.
139+
If you encounter any issues not listed here, please check the [GitHub Issues](https://github.com/astronomer/terraform-provider-astro/issues) page or open a new issue with details about your problem.

0 commit comments

Comments
 (0)