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

Doc enhancements #177

Merged
merged 20 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 30 additions & 38 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ Welcome to the Terraform Provider Astro project! We're excited that you're inter
## Table of Contents

1. [Development Environment Setup](#development-environment-setup)
2. [Making Changes](#making-changes)
3. [Testing](#testing)
4. [Submitting Pull Requests](#submitting-pull-requests)
2. [Adding Dependencies](#adding-dependencies)
3. [Making Changes](#making-changes)
4. [Testing](#testing)
5. [Reporting Issues](#reporting-issues)
6. [Best Practices](#best-practices)
7. [Additional Resources](#additional-resources)
Expand Down Expand Up @@ -66,6 +66,20 @@ Ensure you have the following installed:
```
export ASTRO_API_TOKEN=<your-api-token>
```

## Adding Dependencies

This provider uses [Go modules](https://go.dev/wiki/Modules).
Please see the Go documentation for the most up-to-date information about using Go modules.

To add a new dependency `github.com/author/dependency` to your Terraform provider:

```shell
go get github.com/author/dependency
go mod tidy
```

Then commit the changes to `go.mod` and `go.sum`.
yanmastin-astro marked this conversation as resolved.
Show resolved Hide resolved

## Making Changes
yanmastin-astro marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -85,45 +99,23 @@ Ensure you have the following installed:
4. Update documentation if your changes affect the provider's behavior or add new features.

## Testing
Unit tests can be run with `make test`.

1. Run unit tests:
```
make test
```
### Acceptance tests
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.

2. Run acceptance tests (these will create real resources in your Astro account):
```
make testacc
```
Note: Ensure all required environment variables are set as described in `internal/provider/provider_test_utils.go`.
Using the terraform-plugin-testing framework, each `resource.Test` runs an acceptance test on a resource.
- `ProtoV6ProviderFactories`: map of the provider factories that the test suite will use to create the provider - just has the `astronomer` provider
- `PreCheck`: a function that runs before the test suite starts to check that all the required environment variables are set
- `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.
- `Config`: the Terraform configuration that the test will run (ie. the `.tf` file)
- `Check`: function that will verify the state of the resources after the `terraform apply` command has run.

3. Test your changes manually using the `main.tf` file you created earlier:
```
terraform init
terraform plan
terraform apply
```
yanmastin-astro marked this conversation as resolved.
Show resolved Hide resolved

## Submitting Pull Requests

1. Commit your changes:
```
git add .
git commit -m "Description of your changes"
```

2. Push your branch to GitHub:
```
git push origin feature/your-feature-name
```
In order to run the full suite of Acceptance tests, run `make testacc`.
You will also need to set all the environment variables described in `internal/provider/provider_test_utils.go`.

3. Open a pull request on GitHub.
The acceptance tests will run against the Astronomer API and create/read/update/delete real resources.

4. In your pull request description, include:
- A clear description of the changes
- Any related issue numbers
- Steps to test the changes
- Screenshots or code snippets if applicable

## Reporting Issues

Expand Down Expand Up @@ -176,4 +168,4 @@ If you discover a security vulnerability, please do NOT open an issue. Email sec
- [Terraform Plugin Framework Documentation](https://developer.hashicorp.com/terraform/plugin/framework)
- [Go Documentation](https://golang.org/doc/)

Thank you for contributing to the Terraform Provider Astro project! Your efforts help improve the experience for all Astro users.
Thank you for contributing to the Terraform Provider Astro project! Your efforts help improve the experience for all Astro users.
85 changes: 11 additions & 74 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,15 @@
# Terraform Provider Astro
<div align="center">
<picture>
<img src="https://github.com/user-attachments/assets/22586f12-3871-4bb6-8ead-40bec82ec3ce" width="200">
</picture>
<p>Official Astro Terraform Provider to configure and manage your Astro infrastructure through an API.</p>
<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>
<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>
</div>

## Requirements

- [Terraform](https://developer.hashicorp.com/terraform/downloads) >= 1.7
- [Go](https://golang.org/doc/install) >= 1.21

## Building The Provider

1. Clone the repository
2. Enter the repository directory
3. Build the provider using the following `Makefile` command:

```shell
make dep
make build
```

4. The provider binary will be available in the `bin` directory

## Adding Dependencies

This provider uses [Go modules](https://github.com/golang/go/wiki/Modules).
Please see the Go documentation for the most up-to-date information about using Go modules.

To add a new dependency `github.com/author/dependency` to your Terraform provider:

```shell
go get github.com/author/dependency
go mod tidy
```

Then commit the changes to `go.mod` and `go.sum`.

## Using the provider
yanmastin-astro marked this conversation as resolved.
Show resolved Hide resolved
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.
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.
2. Create a `main.tf` file with the following content:
```terraform
terraform {
Expand All @@ -58,26 +34,7 @@ terraform plan # creates a plan consisting of a set of changes that will make yo
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
```

## Developing the Provider
yanmastin-astro marked this conversation as resolved.
Show resolved Hide resolved

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).

To compile the provider, see [Building The Provider](#building-the-provider).

To add example docs, add the correspond `.tf` files to the `examples` directory. These should be added for every new data source and resource.

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:

```hcl
provider_installation {
dev_overrides {
"registry.terraform.io/astronomer/astro" = "~/terraform-provider-astro/bin" # Your path to the provider binary
}
direct {}
}
```

## Example `main.tf` file for development and testing data sources and resources
## Example `main.tf` file for testing data sources and resources
yanmastin-astro marked this conversation as resolved.
Show resolved Hide resolved
```terraform
terraform {
required_providers {
Expand Down Expand Up @@ -185,24 +142,6 @@ resource "astro_deployment" "tf_standard_deployment" {
}
```

## Testing
Unit tests can be run with `make test`.

### Acceptance tests
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.

Using the terraform-plugin-testing framework, each `resource.Test` runs an acceptance test on a resource.
- `ProtoV6ProviderFactories`: map of the provider factories that the test suite will use to create the provider - just has the `astronomer` provider
- `PreCheck`: a function that runs before the test suite starts to check that all the required environment variables are set
- `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.
- `Config`: the Terraform configuration that the test will run (ie. the `.tf` file)
- `Check`: function that will verify the state of the resources after the `terraform apply` command has run.

In order to run the full suite of Acceptance tests, run `make testacc`.
You will also need to set all the environment variables described in `internal/provider/provider_test_utils.go`.

The acceptance tests will run against the Astronomer API and create/read/update/delete real resources.

## Importing Existing Resources
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.
Expand Down Expand Up @@ -277,8 +216,6 @@ The script will generate two main files:
4. **What Terraform versions are required?**
- Terraform >= 1.7.

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

### Troubleshooting

Expand All @@ -300,4 +237,4 @@ The script will generate two main files:

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

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.
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.