Skip to content

Commit b0c239d

Browse files
authored
Fix hybrid cluster workspace authorization tests and doc fixes/updates (#84)
1 parent d87be6d commit b0c239d

18 files changed

+97
-71
lines changed

.github/workflows/testacc.yml

+3-5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ name: Acceptance Tests
44
# since creation of deployments and clusters are costly
55
on:
66
pull_request:
7-
paths-ignore:
8-
- 'README.md'
97
push:
108
branches:
119
- main
@@ -87,11 +85,11 @@ jobs:
8785
HOSTED_ORGANIZATION_API_TOKEN: ${{ secrets.DEV_HOSTED_ORGANIZATION_API_TOKEN }}
8886
HOSTED_ORGANIZATION_ID: clczfgzc3001o01kjlphpi6hv
8987
HYBRID_CLUSTER_ID: clnp86ly5000401ndagu20g81
88+
HYBRID_DRY_RUN_CLUSTER_ID: clx2amddm002p01lcni4zbpgf
9089
HYBRID_NODE_POOL_ID: clnp86ly5000301ndzfxz895w
9190
ASTRO_API_HOST: https://api.astronomer-dev.io
9291
SKIP_CLUSTER_RESOURCE_TESTS: ${{ env.SKIP_CLUSTER_RESOURCE_TESTS }}
9392
HOSTED_TEAM_ID: clwbclrc100bl01ozjj5s4jmq
94-
HYBRID_WORKSPACE_IDS: cl70oe7cu445571iynrkthtybl,cl8wpve4993871i37qe1k152c
9593
TESTARGS: "-failfast"
9694
run: make testacc
9795

@@ -130,10 +128,10 @@ jobs:
130128
HOSTED_ORGANIZATION_API_TOKEN: ${{ secrets.STAGE_HOSTED_ORGANIZATION_API_TOKEN }}
131129
HOSTED_ORGANIZATION_ID: clczfo8a111cz0t140nck8ubn
132130
HYBRID_CLUSTER_ID: clqqongl40fmv01m96dvxh2nu
131+
HYBRID_DRY_RUN_CLUSTER_ID: clx2b2iag0b6301nbg6ox1wd8
133132
HYBRID_NODE_POOL_ID: clqqongl40fmu01m94pwp4kct
134133
ASTRO_API_HOST: https://api.astronomer-stage.io
135134
HOSTED_TEAM_ID: clwv0r0x7091n01l0t1fm4vxy
136-
HYBRID_WORKSPACE_IDS: clwv06sva08vg01hovu1j7znw
137135
TESTARGS: "-failfast"
138136
run: make testacc
139137

@@ -172,9 +170,9 @@ jobs:
172170
HOSTED_ORGANIZATION_API_TOKEN: ${{ secrets.DEV_HOSTED_ORGANIZATION_API_TOKEN }}
173171
HOSTED_ORGANIZATION_ID: clczfgzc3001o01kjlphpi6hv
174172
HYBRID_CLUSTER_ID: clnp86ly5000401ndagu20g81
173+
HYBRID_DRY_RUN_CLUSTER_ID: clx2amddm002p01lcni4zbpgf
175174
HYBRID_NODE_POOL_ID: clnp86ly5000301ndzfxz895w
176175
ASTRO_API_HOST: https://api.astronomer-dev.io
177176
HOSTED_TEAM_ID: clwbclrc100bl01ozjj5s4jmq
178-
HYBRID_WORKSPACE_IDS: cl70oe7cu445571iynrkthtybl,cl8wpve4993871i37qe1k152c
179177
TESTARGS: "-failfast"
180178
run: make testacc

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Then commit the changes to `go.mod` and `go.sum`.
3939
terraform {
4040
required_providers {
4141
astro = {
42-
source = "registry.terraform.io/astronomer/astro"
42+
source = "astronomer/astro"
4343
}
4444
}
4545
}
@@ -82,7 +82,7 @@ provider_installation {
8282
terraform {
8383
required_providers {
8484
astro = {
85-
source = "registry.terraform.io/astronomer/astro"
85+
source = "astronomer/astro"
8686
}
8787
}
8888
}

docs/resources/cluster.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ resource "astro_cluster" "gcp_example" {
5252
}
5353
5454
// Import an existing cluster
55-
import = {
55+
import {
5656
id = "clozc036j01to01jrlgvuf98d" // ID of the existing cluster
5757
to = astro_cluster.imported_cluster
5858
}

docs/resources/deployment.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ resource "astro_deployment" "hybrid" {
9090
}
9191
9292
// Import an existing deployment
93-
import = {
93+
import {
9494
id = "clv17vgft000801kkydsws63x" // ID of the existing deployment
9595
to = astro_deployment.imported_deployment
9696
}

docs/resources/hybrid_cluster_workspace_authorization.md

+10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ resource "astro_hybrid_cluster_workspace_authorization" "example" {
1717
cluster_id = "clk8h0fv1006801j8yysfybbt"
1818
workspace_ids = ["cl70oe7cu445571iynrkthtybl", "cl70oe7cu445571iynrkthacsd"]
1919
}
20+
21+
// Import existing hybrid cluster workspace authorization
22+
import {
23+
id = "clk8h0fv1006801j8yysfybbt" // ID of the existing hybrid cluster
24+
to = astro_hybrid_cluster_workspace_authorization.imported_cluster_workspace_authorization
25+
}
26+
resource "astro_hybrid_cluster_workspace_authorization" "imported_cluster_workspace_authorization" {
27+
cluster_id = "clk8h0fv1006801j8yysfybbt"
28+
workspace_ids = ["cl70oe7cu445571iynrkthtybl"]
29+
}
2030
```
2131

2232
<!-- schema generated by tfplugindocs -->

docs/resources/team_roles.md

+16
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,22 @@ resource "astro_team_roles" "all_roles" {
6464
}
6565
]
6666
}
67+
68+
// Import existing team roles
69+
import {
70+
id = "clnp86ly5000401ndaga21g81" // ID of the existing team
71+
to = astro_team_roles.imported_team_roles
72+
}
73+
resource "astro_team_roles" "imported_team_roles" {
74+
team_id = "clnp86ly5000401ndaga21g81"
75+
organization_role = "ORGANIZATION_MEMBER"
76+
workspace_roles = [
77+
{
78+
workspace_id = "clwp86ly5000401ndaga21g85"
79+
role = "WORKSPACE_OWNER"
80+
}
81+
]
82+
}
6783
```
6884

6985
<!-- schema generated by tfplugindocs -->

docs/resources/workspace.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ resource "astro_workspace" "example" {
2020
}
2121
2222
// Import an existing workspace
23-
import = {
23+
import {
2424
id = "clozc036j01to01jrlgvu798d" // ID of the existing workspace
2525
to = astro_workspace.imported_workspace
2626
}

examples/resources/astro_cluster/resource.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ resource "astro_cluster" "gcp_example" {
3737
}
3838

3939
// Import an existing cluster
40-
import = {
40+
import {
4141
id = "clozc036j01to01jrlgvuf98d" // ID of the existing cluster
4242
to = astro_cluster.imported_cluster
4343
}

examples/resources/astro_deployment/resource.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ resource "astro_deployment" "hybrid" {
7575
}
7676

7777
// Import an existing deployment
78-
import = {
78+
import {
7979
id = "clv17vgft000801kkydsws63x" // ID of the existing deployment
8080
to = astro_deployment.imported_deployment
8181
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
resource "astro_hybrid_cluster_workspace_authorization" "example" {
22
cluster_id = "clk8h0fv1006801j8yysfybbt"
33
workspace_ids = ["cl70oe7cu445571iynrkthtybl", "cl70oe7cu445571iynrkthacsd"]
4+
}
5+
6+
// Import existing hybrid cluster workspace authorization
7+
import {
8+
id = "clk8h0fv1006801j8yysfybbt" // ID of the existing hybrid cluster
9+
to = astro_hybrid_cluster_workspace_authorization.imported_cluster_workspace_authorization
10+
}
11+
resource "astro_hybrid_cluster_workspace_authorization" "imported_cluster_workspace_authorization" {
12+
cluster_id = "clk8h0fv1006801j8yysfybbt"
13+
workspace_ids = ["cl70oe7cu445571iynrkthtybl"]
414
}

examples/resources/astro_team_roles/resource.tf

+16
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,20 @@ resource "astro_team_roles" "all_roles" {
4848
role = "my custom role"
4949
}
5050
]
51+
}
52+
53+
// Import existing team roles
54+
import {
55+
id = "clnp86ly5000401ndaga21g81" // ID of the existing team
56+
to = astro_team_roles.imported_team_roles
57+
}
58+
resource "astro_team_roles" "imported_team_roles" {
59+
team_id = "clnp86ly5000401ndaga21g81"
60+
organization_role = "ORGANIZATION_MEMBER"
61+
workspace_roles = [
62+
{
63+
workspace_id = "clwp86ly5000401ndaga21g85"
64+
role = "WORKSPACE_OWNER"
65+
}
66+
]
5167
}

examples/resources/astro_workspace/resource.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ resource "astro_workspace" "example" {
55
}
66

77
// Import an existing workspace
8-
import = {
8+
import {
99
id = "clozc036j01to01jrlgvu798d" // ID of the existing workspace
1010
to = astro_workspace.imported_workspace
1111
}

examples/scenarios/workspace_per_environment.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Prod Workspace
1919
terraform {
2020
required_providers {
2121
astro = {
22-
source = "registry.terraform.io/astronomer/astro"
22+
source = "astronomer/astro"
2323
}
2424
}
2525
}

examples/scenarios/workspace_per_team.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Team 3
1919
terraform {
2020
required_providers {
2121
astro = {
22-
source = "registry.terraform.io/astronomer/astro"
22+
source = "astronomer/astro"
2323
}
2424
}
2525
}

examples/scenarios/workspace_per_team_per_environment.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Team 3 workspace prod
2222
terraform {
2323
required_providers {
2424
astro = {
25-
source = "registry.terraform.io/astronomer/astro"
25+
source = "astronomer/astro"
2626
}
2727
}
2828
}

internal/provider/provider_test_utils.go

+15-26
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,21 @@ func TestAccPreCheck(t *testing.T) {
2323
// about the appropriate environment variables being set are common to see in a pre-check
2424
// function.
2525
var missingEnvVars []string
26-
if hostedToken := os.Getenv("HOSTED_ORGANIZATION_API_TOKEN"); len(hostedToken) == 0 {
27-
missingEnvVars = append(missingEnvVars, "HOSTED_ORGANIZATION_API_TOKEN")
28-
}
29-
if hostedOrgId := os.Getenv("HOSTED_ORGANIZATION_ID"); len(hostedOrgId) == 0 {
30-
missingEnvVars = append(missingEnvVars, "HOSTED_ORGANIZATION_ID")
31-
}
32-
if hybridToken := os.Getenv("HYBRID_ORGANIZATION_API_TOKEN"); len(hybridToken) == 0 {
33-
missingEnvVars = append(missingEnvVars, "HYBRID_ORGANIZATION_API_TOKEN")
34-
}
35-
if hybridOrgId := os.Getenv("HYBRID_ORGANIZATION_ID"); len(hybridOrgId) == 0 {
36-
missingEnvVars = append(missingEnvVars, "HYBRID_ORGANIZATION_ID")
37-
}
38-
if hybridWorkspaceIds := os.Getenv("HYBRID_WORKSPACE_IDS"); len(hybridWorkspaceIds) == 0 {
39-
missingEnvVars = append(missingEnvVars, "HYBRID_WORKSPACE_IDS")
40-
}
41-
if host := os.Getenv("ASTRO_API_HOST"); len(host) == 0 {
42-
missingEnvVars = append(missingEnvVars, "ASTRO_API_HOST")
43-
}
44-
if hybridClusterId := os.Getenv("HYBRID_CLUSTER_ID"); len(hybridClusterId) == 0 {
45-
missingEnvVars = append(missingEnvVars, "HYBRID_CLUSTER_ID")
46-
}
47-
if hybridNodePoolId := os.Getenv("HYBRID_NODE_POOL_ID"); len(hybridNodePoolId) == 0 {
48-
missingEnvVars = append(missingEnvVars, "HYBRID_NODE_POOL_ID")
49-
}
50-
if hostedTeamId := os.Getenv("HOSTED_TEAM_ID"); len(hostedTeamId) == 0 {
51-
missingEnvVars = append(missingEnvVars, "HOSTED_TEAM_ID")
26+
envVars := []string{
27+
"HOSTED_ORGANIZATION_API_TOKEN",
28+
"HOSTED_ORGANIZATION_ID",
29+
"HYBRID_ORGANIZATION_API_TOKEN",
30+
"HYBRID_ORGANIZATION_ID",
31+
"HYBRID_DRY_RUN_CLUSTER_ID",
32+
"ASTRO_API_HOST",
33+
"HYBRID_CLUSTER_ID",
34+
"HYBRID_NODE_POOL_ID",
35+
"HOSTED_TEAM_ID",
36+
}
37+
for _, envVar := range envVars {
38+
if val := os.Getenv(envVar); len(val) == 0 {
39+
missingEnvVars = append(missingEnvVars, envVar)
40+
}
5241
}
5342
if len(missingEnvVars) > 0 {
5443
t.Fatalf("Pre-check failed: %+v must be set for acceptance tests", strings.Join(missingEnvVars, ", "))

internal/provider/resources/resource_deployment_test.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ func TestAcc_ResourceDeploymentStandardRemovedOutsideOfTerraform(t *testing.T) {
500500
Check: resource.ComposeTestCheckFunc(
501501
resource.TestCheckResourceAttr(standardDeploymentResource, "name", standardDeploymentName),
502502
resource.TestCheckResourceAttr(standardDeploymentResource, "description", utils.TestResourceDescription),
503-
// Check via API that workspace exists
503+
// Check via API that deployment exists
504504
testAccCheckDeploymentExistence(t, standardDeploymentName, true, true),
505505
),
506506
},
@@ -516,7 +516,7 @@ func TestAcc_ResourceDeploymentStandardRemovedOutsideOfTerraform(t *testing.T) {
516516
Check: resource.ComposeTestCheckFunc(
517517
resource.TestCheckResourceAttr(standardDeploymentResource, "name", standardDeploymentName),
518518
resource.TestCheckResourceAttr(standardDeploymentResource, "description", utils.TestResourceDescription),
519-
// Check via API that workspace exists
519+
// Check via API that deployment exists
520520
testAccCheckDeploymentExistence(t, standardDeploymentName, true, true),
521521
),
522522
},
@@ -575,8 +575,12 @@ func hybridDeployment(input hybridDeploymentInput) string {
575575
taskPodNodePoolIdStr = fmt.Sprintf(`task_pod_node_pool_id = "%v"`, input.NodePoolId)
576576
}
577577

578-
workspaceId := strings.Split(os.Getenv("HYBRID_WORKSPACE_IDS"), ",")[0]
579578
return fmt.Sprintf(`
579+
resource "astro_workspace" "%v_workspace" {
580+
name = "%s"
581+
description = "%s"
582+
cicd_enforced_default = true
583+
}
580584
resource "astro_deployment" "%v" {
581585
name = "%s"
582586
description = "%s"
@@ -588,13 +592,15 @@ resource "astro_deployment" "%v" {
588592
is_dag_deploy_enabled = true
589593
scheduler_au = %v
590594
scheduler_replicas = 1
591-
workspace_id = "%v"
595+
workspace_id = astro_workspace.%v_workspace.id
592596
%v
593597
%v
594598
%v
595599
}
596600
`,
597-
input.Name, input.Name, utils.TestResourceDescription, input.ClusterId, input.Executor, input.SchedulerAu, workspaceId,
601+
input.Name, input.Name, utils.TestResourceDescription,
602+
input.Name, input.Name, utils.TestResourceDescription,
603+
input.ClusterId, input.Executor, input.SchedulerAu, input.Name,
598604
envVarsStr(input.IncludeEnvironmentVariables), wqStr, taskPodNodePoolIdStr)
599605
}
600606

internal/provider/resources/resource_hybrid_cluster_workspace_authorization_test.go

+5-24
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package resources_test
33
import (
44
"context"
55
"fmt"
6-
"strconv"
76
"strings"
87

98
"github.com/samber/lo"
@@ -26,10 +25,8 @@ func TestAcc_ResourceHybridClusterWorkspaceAuthorization(t *testing.T) {
2625

2726
workspaceName := fmt.Sprintf("%v_workspace", namePrefix)
2827
workspaceResourceVar := fmt.Sprintf("astro_workspace.%v", workspaceName)
29-
hybridWorkspaceIdsStr := os.Getenv("HYBRID_WORKSPACE_IDS")
30-
hybridWorkspaceIds := strings.Split(hybridWorkspaceIdsStr, ",")
3128

32-
clusterId := os.Getenv("HYBRID_CLUSTER_ID")
29+
clusterId := os.Getenv("HYBRID_DRY_RUN_CLUSTER_ID")
3330
clusterWorkspaceAuth := fmt.Sprintf("%v_auth", namePrefix)
3431
resourceVar := fmt.Sprintf("astro_hybrid_cluster_workspace_authorization.%v", clusterWorkspaceAuth)
3532

@@ -41,35 +38,19 @@ func TestAcc_ResourceHybridClusterWorkspaceAuthorization(t *testing.T) {
4138
testAccCheckHybridClusterWorkspaceAuthorizationExistence(t, clusterWorkspaceAuth, false),
4239
),
4340
Steps: []resource.TestStep{
44-
// Test with existing workspaces and one created through terraform
41+
// Test with workspace created through terraform
4542
{
4643
Config: astronomerprovider.ProviderConfig(t, false) +
4744
workspace(workspaceName, workspaceName, utils.TestResourceDescription, false) +
4845
hybridClusterWorkspaceAuthorization(hybridClusterWorkspaceAuthorizationInput{
4946
Name: clusterWorkspaceAuth,
5047
ClusterId: clusterId,
51-
WorkspaceIds: append(hybridWorkspaceIds, fmt.Sprintf("%v.id", workspaceResourceVar)),
48+
WorkspaceIds: []string{fmt.Sprintf("%v.id", workspaceResourceVar)},
5249
}),
5350
Check: resource.ComposeTestCheckFunc(
5451
// Check hybrid cluster workspace authorization
5552
resource.TestCheckResourceAttr(resourceVar, "cluster_id", clusterId),
56-
resource.TestCheckResourceAttr(resourceVar, "workspace_ids.#", strconv.Itoa(len(hybridWorkspaceIds)+1)),
57-
58-
testAccCheckHybridClusterWorkspaceAuthorizationExistence(t, clusterWorkspaceAuth, true),
59-
),
60-
},
61-
// Remove terraform created workspace from cluster workspace authorization
62-
{
63-
Config: astronomerprovider.ProviderConfig(t, false) +
64-
hybridClusterWorkspaceAuthorization(hybridClusterWorkspaceAuthorizationInput{
65-
Name: clusterWorkspaceAuth,
66-
ClusterId: clusterId,
67-
WorkspaceIds: hybridWorkspaceIds,
68-
}),
69-
Check: resource.ComposeTestCheckFunc(
70-
// Check hybrid cluster workspace authorization
71-
resource.TestCheckResourceAttr(resourceVar, "cluster_id", clusterId),
72-
resource.TestCheckResourceAttr(resourceVar, "workspace_ids.#", strconv.Itoa(len(hybridWorkspaceIds))),
53+
resource.TestCheckResourceAttr(resourceVar, "workspace_ids.#", "1"),
7354

7455
testAccCheckHybridClusterWorkspaceAuthorizationExistence(t, clusterWorkspaceAuth, true),
7556
),
@@ -133,7 +114,7 @@ func testAccCheckHybridClusterWorkspaceAuthorizationExistence(t *testing.T, name
133114
assert.NoError(t, err)
134115

135116
organizationId := os.Getenv("HYBRID_ORGANIZATION_ID")
136-
clusterId := os.Getenv("HYBRID_CLUSTER_ID")
117+
clusterId := os.Getenv("HYBRID_DRY_RUN_CLUSTER_ID")
137118

138119
ctx := context.Background()
139120
resp, err := client.GetClusterWithResponse(ctx, organizationId, clusterId)

0 commit comments

Comments
 (0)