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

add workspaces data source (v1beta1 list workspaces equivalent) #6

Merged
merged 7 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
42 changes: 42 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''
---

**Describe the bug**

<!--
A clear and concise description of what the bug is.
On errors, please provide the output of the console
-->

```
Please paste terminal or playground output in a code block here
```

**What Terraform Provider Version and Terraform Version did you experience this bug?**

<!--
Run the command `astro version` to get the cli version
-->


**What Operating System is the above Terraform Provider installed on?**

**🪜 Steps To Reproduce**

<!--
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
-->

**📸 Screenshots**

<!--
If applicable, add screenshots to help explain your problem.
-->
33 changes: 33 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''
---

- [ ] I have checked that a similar [feature request](https://github.com/astronomer/astronomer-terraform-provider/issues?q=is%3Aopen+is%3Aissue+label%3A%22feature+request%22) does not already exist.

**✍️ Is your feature request related to a problem? Please describe.**

<!--
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
-->

**🧩 Describe the solution you'd like**

<!--
A clear and concise description of what you want to happen.
-->

**🤔 Describe alternatives you've considered**

<!--
A clear and concise description of any alternative solutions or features you've considered.
-->

**💡 Additional context**

<!--
Add any other context or screenshots about the feature request here.
-->
6 changes: 3 additions & 3 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
## Description

> Describe the purpose of this pull request.
<!--- Describe the purpose of this pull request. --->

## 🎟 Issue(s)

Related #XXX

## 🧪 Functional Testing

> List the functional testing steps to confirm this feature or fix.
<!--- List the functional testing steps to confirm this feature or fix. --->

## 📸 Screenshots

> Add screenshots to illustrate the validity of these changes.
<!--- Add screenshots to illustrate the validity of these changes. --->

## 📋 Checklist

Expand Down
15 changes: 3 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
CORE_IAM_OPENAPI_SPEC=../astro-monorepo/apps/core/docs/iam/v1beta1/iam_v1beta1.yaml
CORE_PLATFORM_OPENAPI_SPEC=../astro-monorepo/apps/core/docs/platform/v1beta1/platform_v1beta1.yaml
CORE_IAM_OPENAPI_SPEC=../astro/apps/core/docs/iam/v1beta1/iam_v1beta1.yaml
CORE_PLATFORM_OPENAPI_SPEC=../astro/apps/core/docs/platform/v1beta1/platform_v1beta1.yaml

DESIRED_OAPI_CODEGEN_VERSION=v2.1.0
DESIRED_MOCKERY_VERSION=v2.40.2

## Location to install dependencies to
ENVTEST_ASSETS_DIR=$(shell pwd)/bin
$(ENVTEST_ASSETS_DIR):
mkdir -p $(ENVTEST_ASSETS_DIR)
MOCKERY ?= $(ENVTEST_ASSETS_DIR)/mockery
OAPI_CODEGEN ?= $(ENVTEST_ASSETS_DIR)/oapi-codegen

# Run acceptance tests
Expand All @@ -20,7 +18,7 @@ testacc:
.PHONY: test
test:
go vet ./...
go run github.com/onsi/ginkgo/v2/ginkgo run -r -v --skip-package internal/mocks --cover --covermode atomic --junit-report=report.xml --output-dir=test_results $(ARGS)
go run github.com/onsi/ginkgo/v2/ginkgo run -r -v --cover --covermode atomic --junit-report=report.xml --output-dir=test_results $(ARGS)

.PHONY: fmt
fmt:
Expand All @@ -47,13 +45,6 @@ dep:
build:
go build -o ${ENVTEST_ASSETS_DIR}/terraform-provider-astronomer
go generate ./...
#
#.PHONY: mock
#mock: $(ENVTEST_ASSETS_DIR)
# # Install correct mockery version if not installed
# (test -s $(MOCKERY) && $(MOCKERY) --version | grep -i $(DESIRED_MOCKERY_VERSION)) || GOBIN=$(ENVTEST_ASSETS_DIR) go install github.com/vektra/mockery/v2@$(DESIRED_MOCKERY_VERSION)
# rm -rf internal/mocks
# $(MOCKERY) --config .mockery.yaml

.PHONY: api_client_gen
api_client_gen: $(ENVTEST_ASSETS_DIR)
Expand Down
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,26 @@ go mod tidy
Then commit the changes to `go.mod` and `go.sum`.

## Using the provider
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.
2. Create a `main.tf` file with the following content:
```terraform
terraform {
required_providers {
astronomer = {
source = "registry.terraform.io/astronomer/astronomer"
}
}
}

provider "astronomer" {
organization_id = "<cuid>"
}

# your terraform commands here
```
3. Run the following commands to apply the provider:
```shell
export ASTRO_API_TOKEN=<token>
terraform apply
terraform plan
```
Expand All @@ -56,6 +74,45 @@ direct {}
}
```

## Example `main.tf` file for development and testing data sources and resources
```terraform
terraform {
required_providers {
astronomer = {
source = "registry.terraform.io/astronomer/astronomer"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be astronomer/astro since the provider is for astro the product?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure we can change it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you think @sunkickr ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

astronomer/astro makes more sense to me as well

}
}
}

variable "token" {
type = string
}

provider "astronomer" {
organization_id = "<cuid>"
host = "https://api.astronomer-dev.io"
token = var.token
}

data "astronomer_workspace" "example" {
id = "<cuid>>"
}

output "data_workspace_example" {
value = data.astronomer_workspace.example
}

resource "astronomer_workspace" "tf_workspace" {
name = "my workspace"
description = "my first workspace"
cicd_enforced_default = false
}

output "terraform_workspace" {
value = astronomer_workspace.tf_workspace
}
```

## Testing
TODO: In order to run the full suite of Acceptance tests, run `make testacc`.

Expand Down
68 changes: 68 additions & 0 deletions docs/data-sources/workspaces.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "astronomer_workspaces Data Source - astronomer"
subcategory: ""
description: |-
Workspaces data source
---

# astronomer_workspaces (Data Source)

Workspaces data source



<!-- schema generated by tfplugindocs -->
## Schema

### Optional

- `names` (List of String)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be list of workspace names?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep that you can query if you want

- `workspace_ids` (List of String)

### Read-Only

- `workspaces` (Attributes List) (see [below for nested schema](#nestedatt--workspaces))

<a id="nestedatt--workspaces"></a>
### Nested Schema for `workspaces`

Required:

- `id` (String) Workspace identifier

Read-Only:

- `cicd_enforced_default` (Boolean) Whether new Deployments enforce CI/CD deploys by default
- `created_at` (String) Workspace creation timestamp
- `created_by` (Attributes) Workspace creator (see [below for nested schema](#nestedatt--workspaces--created_by))
- `description` (String) Workspace description
- `name` (String) Workspace name
- `organization_name` (String) Workspace organization name
- `updated_at` (String) Workspace last updated timestamp
- `updated_by` (Attributes) Workspace updater (see [below for nested schema](#nestedatt--workspaces--updated_by))

<a id="nestedatt--workspaces--created_by"></a>
### Nested Schema for `workspaces.created_by`

Read-Only:

- `api_token_name` (String)
- `avatar_url` (String)
- `full_name` (String)
- `id` (String)
- `subject_type` (String)
- `username` (String)


<a id="nestedatt--workspaces--updated_by"></a>
### Nested Schema for `workspaces.updated_by`

Read-Only:

- `api_token_name` (String)
- `avatar_url` (String)
- `full_name` (String)
- `id` (String)
- `subject_type` (String)
- `username` (String)
50 changes: 0 additions & 50 deletions examples/main.tf

This file was deleted.

6 changes: 5 additions & 1 deletion internal/provider/datasources/data_source_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ func (d *workspaceDataSource) Read(
}

// Populate the model with the response data
data.ReadFromResponse(ctx, workspace.JSON200)
diags := data.ReadFromResponse(ctx, workspace.JSON200)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is workspace.JSON200? and why is it called JSON200 (is it supposed to represent a 200 resp code?)

notice this being referenced and used a lot

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

workspace is the response object from the API client, workspace.JSON200 gives us the platformv1beta1.Workspace object

we use a different client here than we do for the component tests, which is why there are these syntax differences

if diags.HasError() {
resp.Diagnostics.Append(diags...)
return
}

// Save data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
Expand Down
Loading