Skip to content

Commit 0200ed8

Browse files
authored
Merge pull request #790 from rcatolino/dev/rca/fix-okms-cred-update
fix(okms): require replacement of credential on identity_urn change
2 parents d62f00c + fc30790 commit 0200ed8

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

ovh/resource_okms_credential_gen.go

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
99
"github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier"
1010
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
11+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier"
1112
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
1213
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1314
)
@@ -111,6 +112,9 @@ func OkmsCredentialResourceSchema(ctx context.Context) schema.Schema {
111112
Required: true,
112113
Description: "List of identity URNs associated with the credential (max 25)",
113114
MarkdownDescription: "List of identity URNs associated with the credential (max 25)",
115+
PlanModifiers: []planmodifier.List{
116+
listplanmodifier.RequiresReplace(),
117+
},
114118
},
115119
"name": schema.StringAttribute{
116120
CustomType: ovhtypes.TfStringType{},

ovh/resource_okms_credential_test.go

+27-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1111
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1212
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
13+
"github.com/hashicorp/terraform-plugin-testing/plancheck"
1314
"github.com/hashicorp/terraform-plugin-testing/statecheck"
1415
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
1516
)
@@ -117,7 +118,7 @@ resource "ovh_okms" "kms" {
117118
resource "ovh_okms_credential" "cred" {
118119
okms_id = ovh_okms.kms.id
119120
name = "%[2]s"
120-
identity_urns = ["urn:v1:eu:identity:account:${data.ovh_me.current_account.nichandle}"]
121+
identity_urns = ["%[3]s"]
121122
}
122123
123124
resource "ovh_okms_credential" "credcsr" {
@@ -159,22 +160,45 @@ func getAllCredsChecks(resName string, displayName string, resNameCsr string, di
159160
func TestAccOkmsCredCreate(t *testing.T) {
160161
kmsName := acctest.RandomWithPrefix(test_prefix)
161162
credName := acctest.RandomWithPrefix(test_prefix)
163+
oldIdUrn := "urn:v1:eu:identity:account:${data.ovh_me.current_account.nichandle}"
164+
newIdUrn := "urn:v1:eu:identity:user:badnic-ovh/user1"
162165

163166
resource.Test(t, resource.TestCase{
164167
PreCheck: func() { testAccPreCheckCredentials(t) },
165168
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
166169
Steps: []resource.TestStep{
167170
{
168-
Config: fmt.Sprintf(confOkmsCredTest, kmsName, credName),
171+
Config: fmt.Sprintf(confOkmsCredTest, kmsName, credName, oldIdUrn),
169172
ConfigStateChecks: getAllCredsChecks(
170173
"ovh_okms_credential.cred",
171174
credName,
172175
"ovh_okms_credential.credcsr",
173176
credName+"csr"),
174177
},
178+
{
179+
// Test update
180+
Config: fmt.Sprintf(confOkmsCredTest, kmsName, credName, newIdUrn),
181+
ConfigPlanChecks: resource.ConfigPlanChecks{
182+
PreApply: []plancheck.PlanCheck{
183+
plancheck.ExpectNonEmptyPlan(),
184+
plancheck.ExpectResourceAction(
185+
"ovh_okms_credential.cred",
186+
plancheck.ResourceActionReplace),
187+
},
188+
},
189+
ConfigStateChecks: []statecheck.StateCheck{
190+
statecheck.ExpectKnownValue(
191+
"ovh_okms_credential.cred",
192+
tfjsonpath.New("identity_urns"),
193+
knownvalue.ListExact([]knownvalue.Check{
194+
knownvalue.StringExact(newIdUrn),
195+
}),
196+
),
197+
},
198+
},
175199
{
176200
// Test datasource
177-
Config: fmt.Sprintf(confOkmsCredTest+confOkmsDatasourceTest, kmsName, credName),
201+
Config: fmt.Sprintf(confOkmsCredTest+confOkmsDatasourceTest, kmsName, credName, newIdUrn),
178202
ConfigStateChecks: append(
179203
kmsCredDatasourceChecks("ovh_okms_credential.cred", "data.ovh_okms_credential.data_cred"),
180204
kmsCredDatasourceChecks("ovh_okms_credential.credcsr", "data.ovh_okms_credential.data_credcsr")...,

0 commit comments

Comments
 (0)