Skip to content

Commit f920756

Browse files
committed
fill tags, check for replacement
1 parent a139d31 commit f920756

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

internal/provider/provisioner_key_resource.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,11 @@ func (r *ProvisionerKeyResource) Create(ctx context.Context, req resource.Create
103103
return
104104
}
105105

106+
var tags map[string]string
107+
resp.Diagnostics.Append(data.Tags.ElementsAs(ctx, &tags, false)...)
106108
createKeyResult, err := r.Client.CreateProvisionerKey(ctx, data.OrganizationID.ValueUUID(), codersdk.CreateProvisionerKeyRequest{
107109
Name: data.Name.ValueString(),
108-
Tags: map[string]string{},
110+
Tags: tags,
109111
})
110112
if err != nil {
111113
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to create provisioner_key, got error: %s", err))

internal/provider/provisioner_key_resource_test.go

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import (
77
"testing"
88
"text/template"
99

10+
"github.com/coder/coder/v2/coderd/util/ptr"
1011
"github.com/coder/terraform-provider-coderd/integration"
1112
"github.com/google/uuid"
1213
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
14+
"github.com/hashicorp/terraform-plugin-testing/plancheck"
1315
"github.com/stretchr/testify/require"
1416
)
1517

@@ -27,15 +29,17 @@ func TestAccProvisionerKeyResource(t *testing.T) {
2729
URL: client.URL.String(),
2830
Token: client.SessionToken(),
2931

30-
OrganizationID: firstOrg,
31-
Name: "example-provisioner-key",
32+
OrganizationID: &firstOrg,
33+
Name: ptr.Ref("example-provisioner-key"),
3234
}
3335

3436
cfg2 := cfg1
35-
cfg2.Name = "different-provisioner-key"
36-
cfg2.Tags = map[string]string{
37+
cfg2.Tags = ptr.Ref(map[string]string{
3738
"wibble": "wobble",
38-
}
39+
})
40+
41+
cfg3 := cfg2
42+
cfg3.Name = ptr.Ref("different-provisioner-key")
3943

4044
resource.Test(t, resource.TestCase{
4145
IsUnitTest: true,
@@ -47,6 +51,27 @@ func TestAccProvisionerKeyResource(t *testing.T) {
4751
},
4852
{
4953
Config: cfg2.String(t),
54+
ConfigPlanChecks: resource.ConfigPlanChecks{
55+
PreApply: []plancheck.PlanCheck{
56+
plancheck.ExpectResourceAction("coderd_provisioner_key.test", plancheck.ResourceActionReplace),
57+
},
58+
},
59+
},
60+
{
61+
Config: cfg2.String(t),
62+
ConfigPlanChecks: resource.ConfigPlanChecks{
63+
PreApply: []plancheck.PlanCheck{
64+
plancheck.ExpectResourceAction("coderd_provisioner_key.test", plancheck.ResourceActionReplace),
65+
},
66+
},
67+
},
68+
{
69+
Config: cfg3.String(t),
70+
ConfigPlanChecks: resource.ConfigPlanChecks{
71+
PreApply: []plancheck.PlanCheck{
72+
plancheck.ExpectResourceAction("coderd_provisioner_key.test", plancheck.ResourceActionReplace),
73+
},
74+
},
5075
},
5176
},
5277
})
@@ -56,9 +81,9 @@ type testAccProvisionerKeyResourceConfig struct {
5681
URL string
5782
Token string
5883

59-
OrganizationID uuid.UUID
60-
Name string
61-
Tags map[string]string
84+
OrganizationID *uuid.UUID
85+
Name *string
86+
Tags *map[string]string
6287
}
6388

6489
func (c testAccProvisionerKeyResourceConfig) String(t *testing.T) string {

0 commit comments

Comments
 (0)