Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add path to invoke update without determining changed CRN data, add validator for name of secrets #4859

76 changes: 48 additions & 28 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"files": "go.mod|go.sum|.*.map|^.secrets.baseline$",
"lines": null
},
"generated_at": "2023-10-06T11:01:49Z",
"generated_at": "2023-10-18T18:46:12Z",
"plugins_used": [
{
"name": "ArtifactoryDetector"
Expand Down Expand Up @@ -624,7 +624,7 @@
"hashed_secret": "ba02c5a1aad447298fcfbd962a953e7706b8b430",
"is_secret": false,
"is_verified": false,
"line_number": 25,
"line_number": 27,
"type": "Hex High Entropy String",
"verified_result": null
}
Expand Down Expand Up @@ -724,23 +724,23 @@
"hashed_secret": "731438016c5ab94431f61820f35e3ae5f8ad6004",
"is_secret": false,
"is_verified": false,
"line_number": 355,
"line_number": 383,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "12da2e35d6b50c902c014f1ab9e3032650368df7",
"is_secret": false,
"is_verified": false,
"line_number": 361,
"line_number": 389,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "813274ccae5b6b509379ab56982d862f7b5969b6",
"is_secret": false,
"is_verified": false,
"line_number": 1072,
"line_number": 1100,
"type": "Base64 High Entropy String",
"verified_result": null
}
Expand Down Expand Up @@ -774,23 +774,23 @@
"hashed_secret": "1f614c2eb6b3da22d89bd1b9fd47d7cb7c8fc670",
"is_secret": false,
"is_verified": false,
"line_number": 3248,
"line_number": 3250,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "7abfce65b8504403afc25c9790f358d513dfbcc6",
"is_secret": false,
"is_verified": false,
"line_number": 3261,
"line_number": 3263,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "0c2d85bf9a9b1579b16f220a4ea8c3d62b2e24b1",
"is_secret": false,
"is_verified": false,
"line_number": 3302,
"line_number": 3304,
"type": "Secret Keyword",
"verified_result": null
}
Expand Down Expand Up @@ -818,7 +818,7 @@
"hashed_secret": "1a0334cfa65f4be58b9d914b8e96e9d9478bfbac",
"is_secret": false,
"is_verified": false,
"line_number": 3242,
"line_number": 3226,
"type": "Secret Keyword",
"verified_result": null
}
Expand Down Expand Up @@ -2754,7 +2754,17 @@
"hashed_secret": "b732fb611fd46a38e8667f9972e0cde777fbe37f",
"is_secret": false,
"is_verified": false,
"line_number": 373,
"line_number": 403,
"type": "Secret Keyword",
"verified_result": null
}
],
"ibm/service/kubernetes/resource_ibm_container_ingress_secret_opaque_test.go": [
{
"hashed_secret": "5df29b80b97dab81130058ac9af4a9b9d1c091b4",
"is_secret": false,
"is_verified": false,
"line_number": 247,
"type": "Secret Keyword",
"verified_result": null
}
Expand All @@ -2764,7 +2774,17 @@
"hashed_secret": "b732fb611fd46a38e8667f9972e0cde777fbe37f",
"is_secret": false,
"is_verified": false,
"line_number": 267,
"line_number": 292,
"type": "Secret Keyword",
"verified_result": null
}
],
"ibm/service/kubernetes/resource_ibm_container_ingress_secret_tls_test.go": [
{
"hashed_secret": "5df29b80b97dab81130058ac9af4a9b9d1c091b4",
"is_secret": false,
"is_verified": false,
"line_number": 216,
"type": "Secret Keyword",
"verified_result": null
}
Expand Down Expand Up @@ -2882,7 +2902,7 @@
"hashed_secret": "83747cea2b26d7652ed39218ddcdb1461c570535",
"is_secret": false,
"is_verified": false,
"line_number": 80,
"line_number": 79,
"type": "Hex High Entropy String",
"verified_result": null
}
Expand All @@ -2902,7 +2922,7 @@
"hashed_secret": "83747cea2b26d7652ed39218ddcdb1461c570535",
"is_secret": false,
"is_verified": false,
"line_number": 95,
"line_number": 94,
"type": "Hex High Entropy String",
"verified_result": null
}
Expand Down Expand Up @@ -2996,15 +3016,15 @@
"hashed_secret": "3046d9f6cfaaeea6eed9bb7a4ab010fe49b0cfd4",
"is_secret": false,
"is_verified": false,
"line_number": 181,
"line_number": 185,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "b732fb611fd46a38e8667f9972e0cde777fbe37f",
"is_secret": false,
"is_verified": false,
"line_number": 308,
"line_number": 312,
"type": "Secret Keyword",
"verified_result": null
}
Expand Down Expand Up @@ -3052,15 +3072,15 @@
"hashed_secret": "3046d9f6cfaaeea6eed9bb7a4ab010fe49b0cfd4",
"is_secret": false,
"is_verified": false,
"line_number": 193,
"line_number": 197,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "b732fb611fd46a38e8667f9972e0cde777fbe37f",
"is_secret": false,
"is_verified": false,
"line_number": 335,
"line_number": 339,
"type": "Secret Keyword",
"verified_result": null
}
Expand All @@ -3070,15 +3090,15 @@
"hashed_secret": "3046d9f6cfaaeea6eed9bb7a4ab010fe49b0cfd4",
"is_secret": false,
"is_verified": false,
"line_number": 231,
"line_number": 235,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "b732fb611fd46a38e8667f9972e0cde777fbe37f",
"is_secret": false,
"is_verified": false,
"line_number": 410,
"line_number": 414,
"type": "Secret Keyword",
"verified_result": null
}
Expand Down Expand Up @@ -3124,15 +3144,15 @@
"hashed_secret": "3046d9f6cfaaeea6eed9bb7a4ab010fe49b0cfd4",
"is_secret": false,
"is_verified": false,
"line_number": 296,
"line_number": 299,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "b732fb611fd46a38e8667f9972e0cde777fbe37f",
"is_secret": false,
"is_verified": false,
"line_number": 479,
"line_number": 482,
"type": "Secret Keyword",
"verified_result": null
}
Expand Down Expand Up @@ -3226,7 +3246,7 @@
"hashed_secret": "347cd9c53ff77d41a7b22aa56c7b4efaf54658e3",
"is_secret": false,
"is_verified": false,
"line_number": 46,
"line_number": 48,
"type": "Secret Keyword",
"verified_result": null
}
Expand Down Expand Up @@ -3254,15 +3274,15 @@
"hashed_secret": "3046d9f6cfaaeea6eed9bb7a4ab010fe49b0cfd4",
"is_secret": false,
"is_verified": false,
"line_number": 158,
"line_number": 162,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "b732fb611fd46a38e8667f9972e0cde777fbe37f",
"is_secret": false,
"is_verified": false,
"line_number": 274,
"line_number": 278,
"type": "Secret Keyword",
"verified_result": null
}
Expand Down Expand Up @@ -3598,7 +3618,7 @@
"hashed_secret": "4d55af37dbbb6a42088d917caa1ca25428ec42c9",
"is_secret": false,
"is_verified": false,
"line_number": 788,
"line_number": 849,
"type": "Secret Keyword",
"verified_result": null
}
Expand Down Expand Up @@ -3628,23 +3648,23 @@
"hashed_secret": "f855f5027fd8fdb2df3f6a6f1cf858fffcbedb0c",
"is_secret": false,
"is_verified": false,
"line_number": 92841,
"line_number": 93883,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "5fb0fa884132a8724a8d7cba55853737e442adbd",
"is_secret": false,
"is_verified": false,
"line_number": 115304,
"line_number": 116309,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "1e5c2f367f02e47a8c160cda1cd9d91decbac441",
"is_secret": false,
"is_verified": false,
"line_number": 145758,
"line_number": 147225,
"type": "Secret Keyword",
"verified_result": null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ func ResourceIBMContainerIngressSecretOpaque() *schema.Resource {
Required: true,
Description: "Secret name",
ForceNew: true,
ValidateFunc: validate.InvokeValidator(
"ibm_container_ingress_secret_opaque",
"secret_name"),
},
"secret_namespace": {
Type: schema.TypeString,
Expand Down Expand Up @@ -73,6 +76,16 @@ func ResourceIBMContainerIngressSecretOpaque() *schema.Resource {
Computed: true,
Description: "Status of the secret",
},
"update_secret": {
Type: schema.TypeInt,
Optional: true,
Description: "Updates secret from secrets manager if value is changed (increment each usage)",
},
Comment on lines +79 to +83
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update_secret is never set in the code with d.Set. if I get it right, terraform will detect this field as changed on every apply, if the field is not empty.
this can be verified with a test, where you apply the same testAccCheckIBMContainerIngressSecretOpaqueForceUpdate configuration twice.

you can to use d.Set and update the state after the ingressAPI.UpdateIngressSecret .

( or if this behaviour works for you, the field can be modified to a boolean. )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was unable to replicate the behavior you mentioned either by running the test in the code with the same config again or by manually using my own terraform plan/resources. I see the update_secret field reflected in the state file and terraform doesn't execute an update on a repeat apply of the same config should the variable remain unchanged. I also took a look at the above mentioned field retry_patch_version whose pattern update_secret was modeled after and I didn't see any instances of that implementation using the d.set either. Although even in the case it did update every time that would be acceptable behavior. Please let me know if there are any other concerns.

I also went ahead and updated the tests to validate this behavior:

make testacc TEST=./ibm/service/kubernetes TESTARGS='-run=TestAccIBMContainerIngressSecretOpaque_ForceUpdate'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./ibm/service/kubernetes -v -run=TestAccIBMContainerIngressSecretOpaque_ForceUpdate -timeout 700m
=== RUN   TestAccIBMContainerIngressSecretOpaque_ForceUpdate
--- PASS: TestAccIBMContainerIngressSecretOpaque_ForceUpdate (84.83s)
PASS
ok  	github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/kubernetes	86.414s
make testacc TEST=./ibm/service/kubernetes TESTARGS='-run=TestAccIBMContainerIngressSecretTLS_BasicForceUpdate'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./ibm/service/kubernetes -v -run=TestAccIBMContainerIngressSecretTLS_BasicForceUpdate -timeout 700m
=== RUN   TestAccIBMContainerIngressSecretTLS_BasicForceUpdate
--- PASS: TestAccIBMContainerIngressSecretTLS_BasicForceUpdate (63.88s)
PASS
ok  	github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/kubernetes	65.472s

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure about this one.
thank you Jared for looking into it!

"last_updated_timestamp": {
Type: schema.TypeString,
Computed: true,
Description: "Timestamp secret was last updated",
},
"fields": {
Type: schema.TypeSet,
Required: true,
Expand Down Expand Up @@ -122,6 +135,16 @@ func ResourceIBMContainerIngressSecretOpaqueValidator() *validate.ResourceValida
CloudDataType: "cluster",
CloudDataRange: []string{"resolved_to:id"}})

validateSchema = append(validateSchema, validate.ValidateSchema{
Identifier: "secret_name",
ValidateFunctionIdentifier: validate.ValidateRegexpLen,
Type: validate.TypeString,
Required: true,
Regexp: `^([a-z0-9]([-a-z0-9]*[a-z0-9])?(.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*)$`,
MinValueLength: 1,
MaxValueLength: 63,
})

iBMContainerIngressInstanceValidator := validate.ResourceValidator{ResourceName: "ibm_container_ingress_secret_opaque", Schema: validateSchema}
return &iBMContainerIngressInstanceValidator
}
Expand Down Expand Up @@ -205,6 +228,7 @@ func resourceIBMContainerIngressSecretOpaqueRead(d *schema.ResourceData, meta in
d.Set("persistence", ingressSecretConfig.Persistence)
d.Set("user_managed", ingressSecretConfig.UserManaged)
d.Set("status", ingressSecretConfig.Status)
d.Set("last_updated_timestamp", ingressSecretConfig.LastUpdatedTimestamp)

if len(ingressSecretConfig.Fields) > 0 {
d.Set("fields", flex.FlattenOpaqueSecret(ingressSecretConfig.Fields))
Expand Down Expand Up @@ -261,6 +285,7 @@ func resourceIBMContainerIngressSecretOpaqueUpdate(d *schema.ResourceData, meta
Namespace: secretNamespace,
}

ingressAPI := ingressClient.Ingresses()
if d.HasChange("fields") {
oldList, newList := d.GetChange("fields")

Expand All @@ -276,7 +301,6 @@ func resourceIBMContainerIngressSecretOpaqueUpdate(d *schema.ResourceData, meta
remove := os.Difference(ns).List()
add := ns.Difference(os).List()

ingressAPI := ingressClient.Ingresses()
if len(remove) > 0 {
actualSecret, err := ingressAPI.GetIngressSecret(cluster, secretName, secretNamespace)
if err != nil {
Expand Down Expand Up @@ -342,8 +366,13 @@ func resourceIBMContainerIngressSecretOpaqueUpdate(d *schema.ResourceData, meta
return err
}
}
} else if d.HasChange("update_secret") {
// user wants to force an upstream secret update from secrets manager onto kube cluster w/out changing crn
_, err = ingressAPI.UpdateIngressSecret(params)
if err != nil {
return err
}
}

return resourceIBMContainerIngressSecretOpaqueRead(d, meta)
}

Expand Down
Loading
Loading