Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions mmv1/products/secretmanager/Secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ examples:
import_format: ['projects/{{project}}/secrets/{{secret_id}}']
custom_code: !ruby/object:Provider::Terraform::CustomCode
pre_update: templates/terraform/pre_update/secret_manager_secret.go.erb
constants: templates/terraform/constants/secret_manager_secret.go
custom_diff: ['secretManagerSecretAutoCustomizeDiff']
parameters:
- !ruby/object:Api::Type::String
name: secretId
Expand Down Expand Up @@ -125,7 +127,8 @@ properties:
properties:
- !ruby/object:Api::Type::Boolean
name: automatic
immutable: true
# Immutability is handled by the custom diff function until "automatic" is removed
# immutable: true
exactly_one_of:
- replication.0.automatic
- replication.0.user_managed
Expand All @@ -137,7 +140,8 @@ properties:
- !ruby/object:Api::Type::NestedObject
name: auto
api_name: automatic
immutable: true
# Immutability is handled by the custom diff function until "automatic" is removed
# immutable: true
exactly_one_of:
- replication.0.automatic
- replication.0.user_managed
Expand Down
25 changes: 25 additions & 0 deletions mmv1/templates/terraform/constants/secret_manager_secret.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Prevent ForceNew when upgrading replication.automatic -> replication.auto
func secretManagerSecretAutoCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, meta interface{}) error {
oAutomatic, nAutomatic := diff.GetChange("replication.0.automatic")
_, nAuto := diff.GetChange("replication.0.auto")
autoLen := len(nAuto.([]interface{}))

// Do not ForceNew if we are removing "automatic" while adding "auto"
if oAutomatic == true && nAutomatic == false && autoLen > 0 {
return nil
}

if diff.HasChange("replication.0.automatic") {
if err := diff.ForceNew("replication.0.automatic"); err != nil {
return err
}
}

if diff.HasChange("replication.0.auto") {
if err := diff.ForceNew("replication.0.auto"); err != nil {
return err
}
}

return nil
}