Skip to content

Commit

Permalink
133 bug bash script fixes (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
ichung08 authored Aug 23, 2024
1 parent 0610c22 commit dd5c6f3
Show file tree
Hide file tree
Showing 34 changed files with 468 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ website/node_modules
import.tf
generated.tf
import/import_script
terraform-provider-astro-import-script*

website/vendor
test_results
Expand Down
179 changes: 179 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
# Contributing to Terraform Provider Astro

Welcome to the Terraform Provider Astro project! We're excited that you're interested in contributing. This document will guide you through the process of setting up your development environment, making changes, submitting pull requests, and reporting issues.

## 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)
5. [Reporting Issues](#reporting-issues)
6. [Best Practices](#best-practices)
7. [Additional Resources](#additional-resources)

## Development Environment Setup

### Prerequisites

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

### Setting up the Provider for Local Development

1. Clone the repository:
```
git clone https://github.com/astronomer/terraform-provider-astro.git
cd terraform-provider-astro
```

2. Build the provider:
```
make dep
make build
```

3. Create a `.terraformrc` file in your home directory (`~`) with the following content:
```hcl
provider_installation {
dev_overrides {
"registry.terraform.io/astronomer/astro" = "/path/to/your/terraform-provider-astro/bin"
}
direct {}
}
```
Replace `/path/to/your/terraform-provider-astro/bin` with the actual path to the `bin` directory in your cloned repository.

4. Create a `main.tf` file for testing:
```hcl
terraform {
required_providers {
astro = {
source = "astronomer/astro"
}
}
}
provider "astro" {
organization_id = "<your-org-id>"
}
# Add resources and data sources here for testing
```

5. Set up your Astro API token:
```
export ASTRO_API_TOKEN=<your-api-token>
```

## Making Changes

1. Create a new branch for your changes:
```
git checkout -b feature/your-feature-name
```

2. Make your changes in the appropriate files. Common areas for changes include:
- `internal/provider/` for provider logic
- `internal/resources/` for resource implementations
- `internal/datasources/` for data source implementations
- `examples/` for example configurations

3. Update or add tests in the corresponding `*_test.go` files. If a new data source or resource is added, create a new test file in the `*_test.go` file for that feature.

4. Update documentation if your changes affect the provider's behavior or add new features.

## Testing

1. Run unit tests:
```
make test
```

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

3. Test your changes manually using the `main.tf` file you created earlier:
```
terraform init
terraform plan
terraform apply
```

## 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
```

3. Open a pull request on GitHub.

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

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.

### Creating an Issue

1. Go to the [Issues page](https://github.com/astronomer/terraform-provider-astro/issues) of the repository.
2. Click on "New Issue".
3. Choose the appropriate issue template if available, or start with a blank issue.
4. Provide a clear and concise title that summarizes the issue.
5. In the description, include:
- A detailed description of the bug or feature request
- Steps to reproduce the issue (for bugs)
- Expected behavior
- Actual behavior (for bugs)
- Screenshots or error messages, if applicable
- Your environment details:
- Terraform version
- Terraform Provider Astro version
- Operating System
- Any other relevant information
6. Add appropriate labels to the issue (e.g., "bug", "enhancement", "documentation")
7. Submit the issue

### Best Practices for Issue Reporting

- Search existing issues before creating a new one to avoid duplicates.
- One issue per report. If you have multiple bugs or feature requests, create separate issues for each.
- Be responsive to questions or requests for additional information.
- If you find a solution to your problem before the issue is resolved, add a comment describing the solution for others who might encounter the same issue.

### Security Issues

If you discover a security vulnerability, please do NOT open an issue. Email [email protected] instead.

## Best Practices

- Follow Go best practices and conventions.
- Ensure your code is well-commented and easy to understand.
- Keep your changes focused. If you're working on multiple features, submit separate pull requests.
- Update the README.md if your changes affect the overall usage of the provider.
- Add example configurations to the `examples/` directory for any new features or resources.
- If you're adding a new resource or data source, ensure you've added corresponding acceptance tests.

## Additional Resources

- [Terraform Provider Astro Documentation](https://registry.terraform.io/providers/astronomer/astro/latest/docs)
- [Astro API Documentation](https://docs.astronomer.io/astro/api-overview)
- [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.
43 changes: 41 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ On Windows:

- `-resources`: Comma-separated list of resources to import. Accepted values are workspace, deployment, cluster, api_token, team, team_roles, user_roles.
- `-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. Used for initializing the Terraform state in our GitHub Actions.
- `-help`: Display help information.
Expand All @@ -246,7 +245,7 @@ On Windows:

3. Use a different API host (e.g., dev environment):
```
./terraform-provider-astro-import-script_<version-number>_<os>_<arc> -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
```

### Output
Expand All @@ -262,3 +261,43 @@ The script will generate two main files:
- The generated Terraform configurations may require some manual adjustment to match your specific requirements or to resolve any conflicts.
- Always review the generated files before applying them to your Terraform state.

## FAQ and Troubleshooting

### Frequently Asked Questions

1. **What resources can I manage with this Terraform provider?**
- Workspaces, deployments, clusters, hybrid cluster workspace authorizations, API tokens, teams, team roles, and user roles.

2. **How do I authenticate with the Astro API?**
- Use an API token set as the `ASTRO_API_TOKEN` environment variable or add it to the provider configuration.

3. **Can I import existing Astro resources into Terraform?**
- Yes, use the Astro Terraform Import Script to generate import blocks and resource configurations.

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

1. **Issue: 401 Unauthorized error when running `terraform plan` or `terraform apply`**

Solution: Your API token may have expired. Update your `ASTRO_API_TOKEN` environment variable with a fresh token:
```
export ASTRO_API_TOKEN=<your-new-token>
```

2. **Issue: Import script fails to find resources**

Solution:
- Ensure you have the correct permissions in your Astro organization.
- Verify that your API token is valid and has the necessary scopes and permissions.
- Double-check the organization ID provided to the script.

3. **Issue: "Error: Invalid provider configuration" when initializing Terraform**

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.
7 changes: 6 additions & 1 deletion docs/data-sources/api_token.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ API Token data source
## Example Usage

```terraform
data "astro_api_token" "example" {
data "astro_api_token" "example_api_token" {
id = "clxm4836f00ql01me3nigmcr6"
}
# Output the API token using terraform apply
output "api_token" {
value = data.astro_api_token.example_api_token
}
```

<!-- schema generated by tfplugindocs -->
Expand Down
7 changes: 6 additions & 1 deletion docs/data-sources/api_tokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ API Tokens data source
## Example Usage

```terraform
data "astro_api_tokens" "example" {}
data "astro_api_tokens" "example_api_tokens" {}
data "astro_api_tokens" "organization_only_example" {
include_only_organization_tokens = true
Expand All @@ -26,6 +26,11 @@ data "astro_api_tokens" "workspace_example" {
data "astro_api_tokens" "deployment_example" {
deployment_id = "clx44jyu001m201m5dzsbexqr"
}
# Output the API tokens using terraform apply
output "api_tokens" {
value = data.astro_api_tokens.example_api_tokens
}
```

<!-- schema generated by tfplugindocs -->
Expand Down
7 changes: 6 additions & 1 deletion docs/data-sources/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ Cluster data source
## Example Usage

```terraform
data "astro_cluster" "example" {
data "astro_cluster" "example_cluster" {
id = "clozc036j01to01jrlgvueo8t"
}
# Output the cluster value using terraform apply
output "cluster" {
value = data.astro_cluster.example_cluster
}
```

<!-- schema generated by tfplugindocs -->
Expand Down
5 changes: 5 additions & 0 deletions docs/data-sources/cluster_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ data "astro_cluster_options" "example_cluster_options_filter_by_provider" {
type = "HYBRID"
cloud_provider = "AWS"
}
# Output the cluster options value using terraform apply
output "cluster_options" {
value = data.astro_cluster_options.example_cluster_options
}
```

<!-- schema generated by tfplugindocs -->
Expand Down
5 changes: 5 additions & 0 deletions docs/data-sources/clusters.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ data "astro_clusters" "example_clusters_filter_by_names" {
data "astro_clusters" "example_clusters_filter_by_cloud_provider" {
cloud_provider = "AWS"
}
# Output the clusters value using terraform apply
output "clusters" {
value = data.astro_clusters.example_clusters
}
```

<!-- schema generated by tfplugindocs -->
Expand Down
7 changes: 6 additions & 1 deletion docs/data-sources/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ Deployment data source
## Example Usage

```terraform
data "astro_deployment" "example" {
data "astro_deployment" "example_deployment" {
id = "clozc036j01to01jrlgvueo8t"
}
# Output the deployment value using terraform apply
output "deployment" {
value = data.astro_deployment.example_deployment
}
```

<!-- schema generated by tfplugindocs -->
Expand Down
7 changes: 6 additions & 1 deletion docs/data-sources/deployment_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Deployment options data source
## Example Usage

```terraform
data "astro_deployment_options" "example" {}
data "astro_deployment_options" "example_deployment_options" {}
data "astro_deployment_options" "example_with_deployment_id_query_param" {
deployment_id = "clozc036j01to01jrlgvueo8t"
Expand All @@ -30,6 +30,11 @@ data "astro_deployment_options" "example_with_executor_query_param" {
data "astro_deployment_options" "example_with_cloud_provider_query_param" {
cloud_provider = "AWS"
}
# Output the deployment options value using terraform apply
output "deployment_options" {
value = data.astro_deployment_options.example_deployment_options
}
```

<!-- schema generated by tfplugindocs -->
Expand Down
5 changes: 5 additions & 0 deletions docs/data-sources/deployments.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ data "astro_deployments" "example_deployments_filter_by_deployment_ids" {
data "astro_deployments" "example_deployments_filter_by_workspace_ids" {
workspace_ids = ["clozc036j01to01jrlgvu798d"]
}
# Output the deployments value using terraform apply
output "deployments" {
value = data.astro_deployments.example_deployments
}
```

<!-- schema generated by tfplugindocs -->
Expand Down
7 changes: 6 additions & 1 deletion docs/data-sources/organization.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ Organization data source
## Example Usage

```terraform
data "astro_organization" "example" {}
data "astro_organization" "example_organization" {}
# Output the organization value using terraform apply
output "organization" {
value = data.astro_organization.example_organization
}
```

<!-- schema generated by tfplugindocs -->
Expand Down
Loading

0 comments on commit dd5c6f3

Please sign in to comment.