Skip to content

Commit 5c6a204

Browse files
authored
add workspaces data source (v1beta1 list workspaces equivalent) (#6)
2 parents db752d5 + b5a6a5b commit 5c6a204

21 files changed

+553
-127
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
---
8+
9+
**Describe the bug**
10+
11+
<!--
12+
A clear and concise description of what the bug is.
13+
On errors, please provide the output of the console
14+
-->
15+
16+
```
17+
Please paste terminal or playground output in a code block here
18+
```
19+
20+
**What Terraform Provider Version and Terraform Version did you experience this bug?**
21+
22+
<!--
23+
Run the command `astro version` to get the cli version
24+
-->
25+
26+
27+
**What Operating System is the above Terraform Provider installed on?**
28+
29+
**🪜 Steps To Reproduce**
30+
31+
<!--
32+
1. Go to '...'
33+
2. Click on '....'
34+
3. Scroll down to '....'
35+
4. See error
36+
-->
37+
38+
**📸 Screenshots**
39+
40+
<!--
41+
If applicable, add screenshots to help explain your problem.
42+
-->
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
---
8+
9+
- [ ] 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.
10+
11+
**✍️ Is your feature request related to a problem? Please describe.**
12+
13+
<!--
14+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
15+
-->
16+
17+
**🧩 Describe the solution you'd like**
18+
19+
<!--
20+
A clear and concise description of what you want to happen.
21+
-->
22+
23+
**🤔 Describe alternatives you've considered**
24+
25+
<!--
26+
A clear and concise description of any alternative solutions or features you've considered.
27+
-->
28+
29+
**💡 Additional context**
30+
31+
<!--
32+
Add any other context or screenshots about the feature request here.
33+
-->

.github/pull_request_template.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
## Description
22

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

55
## 🎟 Issue(s)
66

77
Related #XXX
88

99
## 🧪 Functional Testing
1010

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

1313
## 📸 Screenshots
1414

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

1717
## 📋 Checklist
1818

Makefile

+3-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
CORE_IAM_OPENAPI_SPEC=../astro-monorepo/apps/core/docs/iam/v1beta1/iam_v1beta1.yaml
2-
CORE_PLATFORM_OPENAPI_SPEC=../astro-monorepo/apps/core/docs/platform/v1beta1/platform_v1beta1.yaml
1+
CORE_IAM_OPENAPI_SPEC=../astro/apps/core/docs/iam/v1beta1/iam_v1beta1.yaml
2+
CORE_PLATFORM_OPENAPI_SPEC=../astro/apps/core/docs/platform/v1beta1/platform_v1beta1.yaml
33

44
DESIRED_OAPI_CODEGEN_VERSION=v2.1.0
5-
DESIRED_MOCKERY_VERSION=v2.40.2
65

76
## Location to install dependencies to
87
ENVTEST_ASSETS_DIR=$(shell pwd)/bin
98
$(ENVTEST_ASSETS_DIR):
109
mkdir -p $(ENVTEST_ASSETS_DIR)
11-
MOCKERY ?= $(ENVTEST_ASSETS_DIR)/mockery
1210
OAPI_CODEGEN ?= $(ENVTEST_ASSETS_DIR)/oapi-codegen
1311

1412
# Run acceptance tests
@@ -20,7 +18,7 @@ testacc:
2018
.PHONY: test
2119
test:
2220
go vet ./...
23-
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)
21+
go run github.com/onsi/ginkgo/v2/ginkgo run -r -v --cover --covermode atomic --junit-report=report.xml --output-dir=test_results $(ARGS)
2422

2523
.PHONY: fmt
2624
fmt:
@@ -47,13 +45,6 @@ dep:
4745
build:
4846
go build -o ${ENVTEST_ASSETS_DIR}/terraform-provider-astronomer
4947
go generate ./...
50-
#
51-
#.PHONY: mock
52-
#mock: $(ENVTEST_ASSETS_DIR)
53-
# # Install correct mockery version if not installed
54-
# (test -s $(MOCKERY) && $(MOCKERY) --version | grep -i $(DESIRED_MOCKERY_VERSION)) || GOBIN=$(ENVTEST_ASSETS_DIR) go install github.com/vektra/mockery/v2@$(DESIRED_MOCKERY_VERSION)
55-
# rm -rf internal/mocks
56-
# $(MOCKERY) --config .mockery.yaml
5748

5849
.PHONY: api_client_gen
5950
api_client_gen: $(ENVTEST_ASSETS_DIR)

README.md

+57
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,26 @@ go mod tidy
3333
Then commit the changes to `go.mod` and `go.sum`.
3434

3535
## 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.
37+
2. Create a `main.tf` file with the following content:
38+
```terraform
39+
terraform {
40+
required_providers {
41+
astronomer = {
42+
source = "registry.terraform.io/astronomer/astronomer"
43+
}
44+
}
45+
}
46+
47+
provider "astronomer" {
48+
organization_id = "<cuid>"
49+
}
3650
51+
# your terraform commands here
52+
```
53+
3. Run the following commands to apply the provider:
3754
```shell
55+
export ASTRO_API_TOKEN=<token>
3856
terraform apply
3957
terraform plan
4058
```
@@ -56,6 +74,45 @@ direct {}
5674
}
5775
```
5876

77+
## Example `main.tf` file for development and testing data sources and resources
78+
```terraform
79+
terraform {
80+
required_providers {
81+
astronomer = {
82+
source = "registry.terraform.io/astronomer/astronomer"
83+
}
84+
}
85+
}
86+
87+
variable "token" {
88+
type = string
89+
}
90+
91+
provider "astronomer" {
92+
organization_id = "<cuid>"
93+
host = "https://api.astronomer-dev.io"
94+
token = var.token
95+
}
96+
97+
data "astronomer_workspace" "example" {
98+
id = "<cuid>>"
99+
}
100+
101+
output "data_workspace_example" {
102+
value = data.astronomer_workspace.example
103+
}
104+
105+
resource "astronomer_workspace" "tf_workspace" {
106+
name = "my workspace"
107+
description = "my first workspace"
108+
cicd_enforced_default = false
109+
}
110+
111+
output "terraform_workspace" {
112+
value = astronomer_workspace.tf_workspace
113+
}
114+
```
115+
59116
## Testing
60117
TODO: In order to run the full suite of Acceptance tests, run `make testacc`.
61118

docs/data-sources/workspaces.md

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "astronomer_workspaces Data Source - astronomer"
4+
subcategory: ""
5+
description: |-
6+
Workspaces data source
7+
---
8+
9+
# astronomer_workspaces (Data Source)
10+
11+
Workspaces data source
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Optional
19+
20+
- `names` (List of String)
21+
- `workspace_ids` (List of String)
22+
23+
### Read-Only
24+
25+
- `workspaces` (Attributes List) (see [below for nested schema](#nestedatt--workspaces))
26+
27+
<a id="nestedatt--workspaces"></a>
28+
### Nested Schema for `workspaces`
29+
30+
Required:
31+
32+
- `id` (String) Workspace identifier
33+
34+
Read-Only:
35+
36+
- `cicd_enforced_default` (Boolean) Whether new Deployments enforce CI/CD deploys by default
37+
- `created_at` (String) Workspace creation timestamp
38+
- `created_by` (Attributes) Workspace creator (see [below for nested schema](#nestedatt--workspaces--created_by))
39+
- `description` (String) Workspace description
40+
- `name` (String) Workspace name
41+
- `organization_name` (String) Workspace organization name
42+
- `updated_at` (String) Workspace last updated timestamp
43+
- `updated_by` (Attributes) Workspace updater (see [below for nested schema](#nestedatt--workspaces--updated_by))
44+
45+
<a id="nestedatt--workspaces--created_by"></a>
46+
### Nested Schema for `workspaces.created_by`
47+
48+
Read-Only:
49+
50+
- `api_token_name` (String)
51+
- `avatar_url` (String)
52+
- `full_name` (String)
53+
- `id` (String)
54+
- `subject_type` (String)
55+
- `username` (String)
56+
57+
58+
<a id="nestedatt--workspaces--updated_by"></a>
59+
### Nested Schema for `workspaces.updated_by`
60+
61+
Read-Only:
62+
63+
- `api_token_name` (String)
64+
- `avatar_url` (String)
65+
- `full_name` (String)
66+
- `id` (String)
67+
- `subject_type` (String)
68+
- `username` (String)

examples/main.tf

-50
This file was deleted.

internal/provider/datasources/data_source_workspace.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ func (d *workspaceDataSource) Read(
107107
}
108108

109109
// Populate the model with the response data
110-
data.ReadFromResponse(ctx, workspace.JSON200)
110+
diags := data.ReadFromResponse(ctx, workspace.JSON200)
111+
if diags.HasError() {
112+
resp.Diagnostics.Append(diags...)
113+
return
114+
}
111115

112116
// Save data into Terraform state
113117
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)

0 commit comments

Comments
 (0)