Skip to content

Commit b5b8da0

Browse files
committed
done
1 parent 1880e2f commit b5b8da0

File tree

8 files changed

+73
-84
lines changed

8 files changed

+73
-84
lines changed

docs/data-sources/workspace.md

+2-8
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,24 @@ data "astronomer_workspace" "example" {
3939
<a id="nestedatt--created_by"></a>
4040
### Nested Schema for `created_by`
4141

42-
Required:
43-
44-
- `id` (String)
45-
4642
Read-Only:
4743

4844
- `api_token_name` (String)
4945
- `avatar_url` (String)
5046
- `full_name` (String)
47+
- `id` (String)
5148
- `subject_type` (String)
5249
- `username` (String)
5350

5451

5552
<a id="nestedatt--updated_by"></a>
5653
### Nested Schema for `updated_by`
5754

58-
Required:
59-
60-
- `id` (String)
61-
6255
Read-Only:
6356

6457
- `api_token_name` (String)
6558
- `avatar_url` (String)
6659
- `full_name` (String)
60+
- `id` (String)
6761
- `subject_type` (String)
6862
- `username` (String)

docs/resources/workspace.md

+2-8
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,24 @@ resource "workspace_resource" "example" {
4141
<a id="nestedatt--created_by"></a>
4242
### Nested Schema for `created_by`
4343

44-
Required:
45-
46-
- `id` (String)
47-
4844
Read-Only:
4945

5046
- `api_token_name` (String)
5147
- `avatar_url` (String)
5248
- `full_name` (String)
49+
- `id` (String)
5350
- `subject_type` (String)
5451
- `username` (String)
5552

5653

5754
<a id="nestedatt--updated_by"></a>
5855
### Nested Schema for `updated_by`
5956

60-
Required:
61-
62-
- `id` (String)
63-
6457
Read-Only:
6558

6659
- `api_token_name` (String)
6760
- `avatar_url` (String)
6861
- `full_name` (String)
62+
- `id` (String)
6963
- `subject_type` (String)
7064
- `username` (String)

examples/main.tf

+17-17
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,22 @@ resource "astronomer_workspace" "tf_workspace" {
2929
description = "This is a Terraform created workspace"
3030
cicd_enforced_default = false
3131
}
32-
#
33-
# output "terraform_workspace" {
34-
# value = astronomer_workspace.tf_workspace
35-
# }
32+
33+
output "terraform_workspace" {
34+
value = astronomer_workspace.tf_workspace
35+
}
3636

3737
// terraform import astronomer_workspace.imported_workspace cuid
38-
# import {
39-
# to = astronomer_workspace.imported_workspace
40-
# id = "clukf7a2p000e01oe9pup199x"
41-
# }
42-
# resource "astronomer_workspace" "imported_workspace" {
43-
# name = "imported_workspace"
44-
# description = "hi fred"
45-
# cicd_enforced_default = false
46-
# }
47-
#
48-
# output "imported_workspace" {
49-
# value = astronomer_workspace.imported_workspace
50-
# }
38+
import {
39+
to = astronomer_workspace.imported_workspace
40+
id = "clukhp501000401jdyc42imci"
41+
}
42+
resource "astronomer_workspace" "imported_workspace" {
43+
name = "imported_workspace"
44+
description = "hi fred"
45+
cicd_enforced_default = false
46+
}
47+
48+
output "imported_workspace" {
49+
value = astronomer_workspace.imported_workspace
50+
}

internal/provider/datasources/data_source_workspace.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (d *workspaceDataSource) Read(
7373
req datasource.ReadRequest,
7474
resp *datasource.ReadResponse,
7575
) {
76-
var data models.WorkspaceDataSourceModel
76+
var data models.WorkspaceDataSource
7777

7878
// Read Terraform configuration data into the model
7979
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
@@ -107,7 +107,7 @@ func (d *workspaceDataSource) Read(
107107
}
108108

109109
// Populate the model with the response data
110-
models.FillWorkspaceDataSourceState(ctx, workspace.JSON200, &data)
110+
data.ReadFromResponse(ctx, workspace.JSON200)
111111

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

internal/provider/models/subject_profile.go

+15-12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package models
22

33
import (
44
"context"
5+
"github.com/hashicorp/terraform-plugin-framework/attr"
56

67
"github.com/astronomer/astronomer-terraform-provider/internal/clients/iam"
78
"github.com/astronomer/astronomer-terraform-provider/internal/clients/platform"
@@ -10,7 +11,7 @@ import (
1011
"github.com/hashicorp/terraform-plugin-log/tflog"
1112
)
1213

13-
type SubjectProfileModel struct {
14+
type SubjectProfile struct {
1415
Id types.String `tfsdk:"id"`
1516
SubjectType types.String `tfsdk:"subject_type"`
1617
Username types.String `tfsdk:"username"`
@@ -19,10 +20,19 @@ type SubjectProfileModel struct {
1920
ApiTokenName types.String `tfsdk:"api_token_name"`
2021
}
2122

23+
var SubjectProfileTF map[string]attr.Type = map[string]attr.Type{
24+
"id": types.StringType,
25+
"subject_type": types.StringType,
26+
"username": types.StringType,
27+
"full_name": types.StringType,
28+
"avatar_url": types.StringType,
29+
"api_token_name": types.StringType,
30+
}
31+
2232
func SubjectProfileTypesObject(
2333
ctx context.Context,
2434
basicSubjectProfile any,
25-
) (*SubjectProfileModel, diag.Diagnostics) {
35+
) (types.Object, diag.Diagnostics) {
2636
// Check that the type passed in is a platform.BasicSubjectProfile or iam.BasicSubjectProfile
2737
bsp, ok := basicSubjectProfile.(*platform.BasicSubjectProfile)
2838
if !ok {
@@ -33,7 +43,7 @@ func SubjectProfileTypesObject(
3343
"Unexpected type passed into subject profile",
3444
map[string]interface{}{"value": basicSubjectProfile},
3545
)
36-
return nil, diag.Diagnostics{
46+
return types.Object{}, diag.Diagnostics{
3747
diag.NewErrorDiagnostic(
3848
"Internal Error",
3949
"SubjectProfileTypesObject expects a BasicSubjectProfile type but did not receive one",
@@ -51,7 +61,7 @@ func SubjectProfileTypesObject(
5161
}
5262
}
5363

54-
subjectProfile := SubjectProfileModel{
64+
subjectProfile := SubjectProfile{
5565
Id: types.StringValue(bsp.Id),
5666
}
5767

@@ -73,20 +83,13 @@ func SubjectProfileTypesObject(
7383
} else {
7484
subjectProfile.AvatarUrl = types.StringUnknown()
7585
}
76-
subjectProfile.ApiTokenName = types.StringNull()
7786
} else {
7887
if bsp.ApiTokenName != nil {
7988
subjectProfile.ApiTokenName = types.StringValue(*bsp.ApiTokenName)
8089
} else {
8190
subjectProfile.ApiTokenName = types.StringUnknown()
8291
}
8392
}
84-
} else {
85-
subjectProfile.SubjectType = types.StringUnknown()
86-
subjectProfile.Username = types.StringUnknown()
87-
subjectProfile.FullName = types.StringUnknown()
88-
subjectProfile.AvatarUrl = types.StringUnknown()
89-
subjectProfile.ApiTokenName = types.StringUnknown()
9093
}
91-
return &subjectProfile, nil
94+
return types.ObjectValueFrom(ctx, SubjectProfileTF, subjectProfile)
9295
}

internal/provider/models/workspace.go

+24-26
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,35 @@ import (
88
"github.com/hashicorp/terraform-plugin-framework/types"
99
)
1010

11-
// WorkspaceDataSourceModel describes the data source data model.
12-
type WorkspaceDataSourceModel struct {
13-
Id types.String `tfsdk:"id"`
14-
Name types.String `tfsdk:"name"`
15-
Description types.String `tfsdk:"description"`
16-
OrganizationName types.String `tfsdk:"organization_name"`
17-
CicdEnforcedDefault types.Bool `tfsdk:"cicd_enforced_default"`
18-
CreatedAt types.String `tfsdk:"created_at"`
19-
UpdatedAt types.String `tfsdk:"updated_at"`
20-
CreatedBy *SubjectProfileModel `tfsdk:"created_by"`
21-
UpdatedBy *SubjectProfileModel `tfsdk:"updated_by"`
11+
// WorkspaceDataSource describes the data source data model.
12+
type WorkspaceDataSource struct {
13+
Id types.String `tfsdk:"id"`
14+
Name types.String `tfsdk:"name"`
15+
Description types.String `tfsdk:"description"`
16+
OrganizationName types.String `tfsdk:"organization_name"`
17+
CicdEnforcedDefault types.Bool `tfsdk:"cicd_enforced_default"`
18+
CreatedAt types.String `tfsdk:"created_at"`
19+
UpdatedAt types.String `tfsdk:"updated_at"`
20+
CreatedBy types.Object `tfsdk:"created_by"`
21+
UpdatedBy types.Object `tfsdk:"updated_by"`
2222
}
2323

24-
// WorkspaceResourceModel describes the resource data model.
25-
type WorkspaceResourceModel struct {
26-
Id types.String `tfsdk:"id"`
27-
Name types.String `tfsdk:"name"`
28-
Description types.String `tfsdk:"description"`
29-
OrganizationName types.String `tfsdk:"organization_name"`
30-
CicdEnforcedDefault types.Bool `tfsdk:"cicd_enforced_default"`
31-
CreatedAt types.String `tfsdk:"created_at"`
32-
UpdatedAt types.String `tfsdk:"updated_at"`
33-
CreatedBy *SubjectProfileModel `tfsdk:"created_by"`
34-
UpdatedBy *SubjectProfileModel `tfsdk:"updated_by"`
24+
// WorkspaceResource describes the resource data model.
25+
type WorkspaceResource struct {
26+
Id types.String `tfsdk:"id"`
27+
Name types.String `tfsdk:"name"`
28+
Description types.String `tfsdk:"description"`
29+
OrganizationName types.String `tfsdk:"organization_name"`
30+
CicdEnforcedDefault types.Bool `tfsdk:"cicd_enforced_default"`
31+
CreatedAt types.String `tfsdk:"created_at"`
32+
UpdatedAt types.String `tfsdk:"updated_at"`
33+
CreatedBy types.Object `tfsdk:"created_by"`
34+
UpdatedBy types.Object `tfsdk:"updated_by"`
3535
}
3636

37-
func FillWorkspaceResourceState(
37+
func (data *WorkspaceResource) ReadFromResponse(
3838
ctx context.Context,
3939
workspace *platform.Workspace,
40-
data *WorkspaceResourceModel,
4140
) diag.Diagnostics {
4241
data.Id = types.StringValue(workspace.Id)
4342
data.Name = types.StringValue(workspace.Name)
@@ -63,10 +62,9 @@ func FillWorkspaceResourceState(
6362
return nil
6463
}
6564

66-
func FillWorkspaceDataSourceState(
65+
func (data *WorkspaceDataSource) ReadFromResponse(
6766
ctx context.Context,
6867
workspace *platform.Workspace,
69-
data *WorkspaceDataSourceModel,
7068
) diag.Diagnostics {
7169
data.Id = types.StringValue(workspace.Id)
7270
data.Name = types.StringValue(workspace.Name)

internal/provider/resources/resource_workspace.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (r *workspaceResource) Create(
7676
req resource.CreateRequest,
7777
resp *resource.CreateResponse,
7878
) {
79-
var data models.WorkspaceResourceModel
79+
var data models.WorkspaceResource
8080

8181
// Read Terraform plan data into the model
8282
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
@@ -110,7 +110,7 @@ func (r *workspaceResource) Create(
110110
return
111111
}
112112

113-
diags := models.FillWorkspaceResourceState(ctx, workspace.JSON200, &data)
113+
diags := data.ReadFromResponse(ctx, workspace.JSON200)
114114
if diags.HasError() {
115115
resp.Diagnostics.Append(diags...)
116116
return
@@ -127,7 +127,7 @@ func (r *workspaceResource) Read(
127127
req resource.ReadRequest,
128128
resp *resource.ReadResponse,
129129
) {
130-
var data models.WorkspaceResourceModel
130+
var data models.WorkspaceResource
131131

132132
// Read Terraform prior state data into the model
133133
resp.Diagnostics.Append(req.State.Get(ctx, &data)...)
@@ -162,7 +162,7 @@ func (r *workspaceResource) Read(
162162
return
163163
}
164164

165-
diags := models.FillWorkspaceResourceState(ctx, workspace.JSON200, &data)
165+
diags := data.ReadFromResponse(ctx, workspace.JSON200)
166166
if diags.HasError() {
167167
resp.Diagnostics.Append(diags...)
168168
return
@@ -179,7 +179,7 @@ func (r *workspaceResource) Update(
179179
req resource.UpdateRequest,
180180
resp *resource.UpdateResponse,
181181
) {
182-
var data models.WorkspaceResourceModel
182+
var data models.WorkspaceResource
183183

184184
// Read Terraform plan data into the model
185185
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
@@ -214,7 +214,7 @@ func (r *workspaceResource) Update(
214214
return
215215
}
216216

217-
diags := models.FillWorkspaceResourceState(ctx, workspace.JSON200, &data)
217+
diags := data.ReadFromResponse(ctx, workspace.JSON200)
218218
if diags.HasError() {
219219
resp.Diagnostics.Append(diags...)
220220
return
@@ -231,7 +231,7 @@ func (r *workspaceResource) Delete(
231231
req resource.DeleteRequest,
232232
resp *resource.DeleteResponse,
233233
) {
234-
var data models.WorkspaceResourceModel
234+
var data models.WorkspaceResource
235235

236236
// Read Terraform prior state data into the model
237237
resp.Diagnostics.Append(req.State.Get(ctx, &data)...)

internal/provider/schemas/subject_profile_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var _ = Describe("Common Test", func() {
3535

3636
DescribeTable(
3737
"should return subject profile model",
38-
func(input any, expected *models.SubjectProfileModel) {
38+
func(input any, expected *models.SubjectProfile) {
3939
subjectProfileModel, diags := models.SubjectProfileTypesObject(ctx, input)
4040
Expect(diags.HasError()).To(BeFalse())
4141
Expect(subjectProfileModel).To(Equal(expected))
@@ -46,7 +46,7 @@ var _ = Describe("Common Test", func() {
4646
Id: "id",
4747
SubjectType: (*platform.BasicSubjectProfileSubjectType)(lo.ToPtr("USER")),
4848
Username: lo.ToPtr("username"),
49-
}, &models.SubjectProfileModel{
49+
}, &models.SubjectProfile{
5050
Id: types.StringValue("id"),
5151
SubjectType: types.StringValue("USER"),
5252
Username: types.StringValue("username"),
@@ -58,7 +58,7 @@ var _ = Describe("Common Test", func() {
5858
Id: "id",
5959
SubjectType: (*iam.BasicSubjectProfileSubjectType)(lo.ToPtr("SERVICEKEY")),
6060
ApiTokenName: lo.ToPtr("api_token_name"),
61-
}, &models.SubjectProfileModel{
61+
}, &models.SubjectProfile{
6262
Id: types.StringValue("id"),
6363
SubjectType: types.StringValue("SERVICEKEY"),
6464
Username: types.StringNull(),
@@ -68,7 +68,7 @@ var _ = Describe("Common Test", func() {
6868
}),
6969
Entry("just id", &platform.BasicSubjectProfile{
7070
Id: "id",
71-
}, &models.SubjectProfileModel{
71+
}, &models.SubjectProfile{
7272
Id: types.StringValue("id"),
7373
SubjectType: types.StringUnknown(),
7474
Username: types.StringUnknown(),

0 commit comments

Comments
 (0)