Skip to content

Commit

Permalink
auto_rotate fix (IBM-Cloud#4649)
Browse files Browse the repository at this point in the history
  • Loading branch information
yonatanyell authored and omaraibrahim committed Jul 20, 2023
1 parent 9aac73d commit 46a08e0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,18 @@ func ResourceIbmSmIamCredentialsSecret() *schema.Resource {
Description: "Determines whether Secrets Manager rotates your secret automatically.Default is `false`. If `auto_rotate` is set to `true` the service rotates your secret based on the defined interval.",
},
"interval": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "The length of the secret rotation time interval.",
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "The length of the secret rotation time interval.",
DiffSuppressFunc: rotationAttributesDiffSuppress,
},
"unit": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The units for the secret rotation time interval.",
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The units for the secret rotation time interval.",
DiffSuppressFunc: rotationAttributesDiffSuppress,
},
"rotate_keys": &schema.Schema{
Type: schema.TypeBool,
Expand Down Expand Up @@ -566,7 +568,9 @@ func resourceIbmSmIamCredentialsSecretMapToRotationPolicy(modelMap map[string]in
if modelMap["auto_rotate"] != nil {
model.AutoRotate = core.BoolPtr(modelMap["auto_rotate"].(bool))
}
if modelMap["interval"] != nil {
if modelMap["interval"].(int) == 0 {
model.Interval = nil
} else {
model.Interval = core.Int64Ptr(int64(modelMap["interval"].(int)))
}
if modelMap["unit"] != nil && modelMap["unit"].(string) != "" {
Expand Down
22 changes: 13 additions & 9 deletions ibm/service/secretsmanager/resource_ibm_sm_private_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,18 @@ func ResourceIbmSmPrivateCertificate() *schema.Resource {
Description: "Determines whether Secrets Manager rotates your secret automatically.Default is `false`. If `auto_rotate` is set to `true` the service rotates your secret based on the defined interval.",
},
"interval": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "The length of the secret rotation time interval.",
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "The length of the secret rotation time interval.",
DiffSuppressFunc: rotationAttributesDiffSuppress,
},
"unit": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The units for the secret rotation time interval.",
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The units for the secret rotation time interval.",
DiffSuppressFunc: rotationAttributesDiffSuppress,
},
},
},
Expand Down Expand Up @@ -723,7 +725,9 @@ func resourceIbmSmPrivateCertificateMapToRotationPolicy(modelMap map[string]inte
if modelMap["auto_rotate"] != nil {
model.AutoRotate = core.BoolPtr(modelMap["auto_rotate"].(bool))
}
if modelMap["interval"] != nil {
if modelMap["interval"].(int) == 0 {
model.Interval = nil
} else {
model.Interval = core.Int64Ptr(int64(modelMap["interval"].(int)))
}
if modelMap["unit"] != nil && modelMap["unit"].(string) != "" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,18 @@ func ResourceIbmSmUsernamePasswordSecret() *schema.Resource {
Description: "Determines whether Secrets Manager rotates your secret automatically.Default is `false`. If `auto_rotate` is set to `true` the service rotates your secret based on the defined interval.",
},
"interval": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "The length of the secret rotation time interval.",
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "The length of the secret rotation time interval.",
DiffSuppressFunc: rotationAttributesDiffSuppress,
},
"unit": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The units for the secret rotation time interval.",
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The units for the secret rotation time interval.",
DiffSuppressFunc: rotationAttributesDiffSuppress,
},
},
},
Expand Down Expand Up @@ -520,7 +522,9 @@ func resourceIbmSmUsernamePasswordSecretMapToRotationPolicy(modelMap map[string]
if modelMap["auto_rotate"] != nil {
model.AutoRotate = core.BoolPtr(modelMap["auto_rotate"].(bool))
}
if modelMap["interval"] != nil {
if modelMap["interval"].(int) == 0 {
model.Interval = nil
} else {
model.Interval = core.Int64Ptr(int64(modelMap["interval"].(int)))
}
if modelMap["unit"] != nil && modelMap["unit"].(string) != "" {
Expand Down Expand Up @@ -561,3 +565,12 @@ func resourceIbmSmUsernamePasswordSecretCommonRotationPolicyToMap(model *secrets
}
return modelMap, nil
}

func rotationAttributesDiffSuppress(key, oldValue, newValue string, d *schema.ResourceData) bool {
autoRotate := d.Get("rotation").([]interface{})[0].(map[string]interface{})["auto_rotate"].(bool)
if autoRotate == false {
return true
}

return oldValue == newValue
}

0 comments on commit 46a08e0

Please sign in to comment.