-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for
auto
and deprecated automatic
field in `google_…
…secret_manager_secret` resource (#8838) * Added support for automatic_replication field in google_secret_manager_secret resource * Replaced deprecated field automatic with automatic_replication in terraform configs * Improved the deprecation_message * Changed the name of field from automatic_replication to auto * Adjusted white spaces * Added test case to cover the automatic field
- Loading branch information
1 parent
20d170f
commit 1e2b51e
Showing
28 changed files
with
592 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
180 changes: 180 additions & 0 deletions
180
mmv1/templates/terraform/custom_expand/secret_manager_replication.go.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
<%# The license inside this block applies to this file. | ||
# Copyright 2023 Google Inc. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
-%> | ||
func expandSecretManagerSecretReplication(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
l := v.([]interface{}) | ||
if len(l) == 0 || l[0] == nil { | ||
return nil, nil | ||
} | ||
raw := l[0] | ||
original := raw.(map[string]interface{}) | ||
transformed := make(map[string]interface{}) | ||
|
||
if _, ok := d.GetOk("replication.0.automatic"); ok{ | ||
transformedAutomatic, err := expandSecretManagerSecretReplicationAutomatic(original["automatic"], d, config) | ||
if err != nil { | ||
return nil, err | ||
} else if val := reflect.ValueOf(transformedAutomatic); val.IsValid() && !tpgresource.IsEmptyValue(val) { | ||
transformed["automatic"] = transformedAutomatic | ||
} | ||
} | ||
|
||
if _, ok := d.GetOk("replication.0.auto"); ok{ | ||
transformedAuto, err := expandSecretManagerSecretReplicationAuto(original["auto"], d, config) | ||
if err != nil { | ||
return nil, err | ||
} else { | ||
transformed["automatic"] = transformedAuto | ||
} | ||
} | ||
|
||
transformedUserManaged, err := expandSecretManagerSecretReplicationUserManaged(original["user_managed"], d, config) | ||
if err != nil { | ||
return nil, err | ||
} else if val := reflect.ValueOf(transformedUserManaged); val.IsValid() && !tpgresource.IsEmptyValue(val) { | ||
transformed["userManaged"] = transformedUserManaged | ||
} | ||
|
||
return transformed, nil | ||
} | ||
|
||
func expandSecretManagerSecretReplicationAutomatic(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
if v == nil || !v.(bool) { | ||
return nil, nil | ||
} | ||
|
||
return struct{}{}, nil | ||
} | ||
|
||
func expandSecretManagerSecretReplicationAuto(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
l := v.([]interface{}) | ||
if len(l) == 0 { | ||
return nil, nil | ||
} | ||
|
||
if l[0] == nil { | ||
transformed := make(map[string]interface{}) | ||
return transformed, nil | ||
} | ||
raw := l[0] | ||
original := raw.(map[string]interface{}) | ||
transformed := make(map[string]interface{}) | ||
|
||
transformedCustomerManagedEncryption, err := expandSecretManagerSecretReplicationAutoCustomerManagedEncryption(original["customer_managed_encryption"], d, config) | ||
if err != nil { | ||
return nil, err | ||
} else if val := reflect.ValueOf(transformedCustomerManagedEncryption); val.IsValid() && !tpgresource.IsEmptyValue(val) { | ||
transformed["customerManagedEncryption"] = transformedCustomerManagedEncryption | ||
} | ||
|
||
return transformed, nil | ||
} | ||
|
||
func expandSecretManagerSecretReplicationAutoCustomerManagedEncryption(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
l := v.([]interface{}) | ||
if len(l) == 0 || l[0] == nil { | ||
return nil, nil | ||
} | ||
raw := l[0] | ||
original := raw.(map[string]interface{}) | ||
transformed := make(map[string]interface{}) | ||
|
||
transformedKmsKeyName, err := expandSecretManagerSecretReplicationAutoCustomerManagedEncryptionKmsKeyName(original["kms_key_name"], d, config) | ||
if err != nil { | ||
return nil, err | ||
} else if val := reflect.ValueOf(transformedKmsKeyName); val.IsValid() && !tpgresource.IsEmptyValue(val) { | ||
transformed["kmsKeyName"] = transformedKmsKeyName | ||
} | ||
|
||
return transformed, nil | ||
} | ||
|
||
func expandSecretManagerSecretReplicationAutoCustomerManagedEncryptionKmsKeyName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
return v, nil | ||
} | ||
|
||
func expandSecretManagerSecretReplicationUserManaged(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
l := v.([]interface{}) | ||
if len(l) == 0 || l[0] == nil { | ||
return nil, nil | ||
} | ||
raw := l[0] | ||
original := raw.(map[string]interface{}) | ||
transformed := make(map[string]interface{}) | ||
|
||
transformedReplicas, err := expandSecretManagerSecretReplicationUserManagedReplicas(original["replicas"], d, config) | ||
if err != nil { | ||
return nil, err | ||
} else if val := reflect.ValueOf(transformedReplicas); val.IsValid() && !tpgresource.IsEmptyValue(val) { | ||
transformed["replicas"] = transformedReplicas | ||
} | ||
|
||
return transformed, nil | ||
} | ||
|
||
func expandSecretManagerSecretReplicationUserManagedReplicas(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
l := v.([]interface{}) | ||
req := make([]interface{}, 0, len(l)) | ||
for _, raw := range l { | ||
if raw == nil { | ||
continue | ||
} | ||
original := raw.(map[string]interface{}) | ||
transformed := make(map[string]interface{}) | ||
|
||
transformedLocation, err := expandSecretManagerSecretReplicationUserManagedReplicasLocation(original["location"], d, config) | ||
if err != nil { | ||
return nil, err | ||
} else if val := reflect.ValueOf(transformedLocation); val.IsValid() && !tpgresource.IsEmptyValue(val) { | ||
transformed["location"] = transformedLocation | ||
} | ||
|
||
transformedCustomerManagedEncryption, err := expandSecretManagerSecretReplicationUserManagedReplicasCustomerManagedEncryption(original["customer_managed_encryption"], d, config) | ||
if err != nil { | ||
return nil, err | ||
} else if val := reflect.ValueOf(transformedCustomerManagedEncryption); val.IsValid() && !tpgresource.IsEmptyValue(val) { | ||
transformed["customerManagedEncryption"] = transformedCustomerManagedEncryption | ||
} | ||
|
||
req = append(req, transformed) | ||
} | ||
return req, nil | ||
} | ||
|
||
func expandSecretManagerSecretReplicationUserManagedReplicasLocation(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
return v, nil | ||
} | ||
|
||
func expandSecretManagerSecretReplicationUserManagedReplicasCustomerManagedEncryption(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
l := v.([]interface{}) | ||
if len(l) == 0 || l[0] == nil { | ||
return nil, nil | ||
} | ||
raw := l[0] | ||
original := raw.(map[string]interface{}) | ||
transformed := make(map[string]interface{}) | ||
|
||
transformedKmsKeyName, err := expandSecretManagerSecretReplicationUserManagedReplicasCustomerManagedEncryptionKmsKeyName(original["kms_key_name"], d, config) | ||
if err != nil { | ||
return nil, err | ||
} else if val := reflect.ValueOf(transformedKmsKeyName); val.IsValid() && !tpgresource.IsEmptyValue(val) { | ||
transformed["kmsKeyName"] = transformedKmsKeyName | ||
} | ||
|
||
return transformed, nil | ||
} | ||
|
||
func expandSecretManagerSecretReplicationUserManagedReplicasCustomerManagedEncryptionKmsKeyName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
return v, nil | ||
} |
118 changes: 118 additions & 0 deletions
118
mmv1/templates/terraform/custom_flatten/secret_manager_replication.go.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<%# The license inside this block applies to this file. | ||
# Copyright 2023 Google Inc. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
-%> | ||
func flattenSecretManagerSecretReplication(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { | ||
if v == nil { | ||
return nil | ||
} | ||
original := v.(map[string]interface{}) | ||
if len(original) == 0 { | ||
return nil | ||
} | ||
transformed := make(map[string]interface{}) | ||
_, ok := d.GetOk("replication.0.automatic") | ||
if ok { | ||
transformed["automatic"] = | ||
flattenSecretManagerSecretReplicationAutomatic(original["automatic"], d, config) | ||
} else { | ||
transformed["auto"] = | ||
flattenSecretManagerSecretReplicationAuto(original["automatic"], d, config) | ||
} | ||
transformed["user_managed"] = | ||
flattenSecretManagerSecretReplicationUserManaged(original["userManaged"], d, config) | ||
return []interface{}{transformed} | ||
} | ||
func flattenSecretManagerSecretReplicationAutomatic(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { | ||
return v != nil | ||
} | ||
|
||
func flattenSecretManagerSecretReplicationAuto(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { | ||
if v == nil { | ||
return nil | ||
} | ||
original := v.(map[string]interface{}) | ||
transformed := make(map[string]interface{}) | ||
transformed["customer_managed_encryption"] = | ||
flattenSecretManagerSecretReplicationAutoCustomerManagedEncryption(original["customerManagedEncryption"], d, config) | ||
return []interface{}{transformed} | ||
} | ||
func flattenSecretManagerSecretReplicationAutoCustomerManagedEncryption(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { | ||
if v == nil { | ||
return nil | ||
} | ||
original := v.(map[string]interface{}) | ||
if len(original) == 0 { | ||
return nil | ||
} | ||
transformed := make(map[string]interface{}) | ||
transformed["kms_key_name"] = | ||
flattenSecretManagerSecretReplicationAutoCustomerManagedEncryptionKmsKeyName(original["kmsKeyName"], d, config) | ||
return []interface{}{transformed} | ||
} | ||
func flattenSecretManagerSecretReplicationAutoCustomerManagedEncryptionKmsKeyName(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { | ||
return v | ||
} | ||
|
||
func flattenSecretManagerSecretReplicationUserManaged(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { | ||
if v == nil { | ||
return nil | ||
} | ||
original := v.(map[string]interface{}) | ||
if len(original) == 0 { | ||
return nil | ||
} | ||
transformed := make(map[string]interface{}) | ||
transformed["replicas"] = | ||
flattenSecretManagerSecretReplicationUserManagedReplicas(original["replicas"], d, config) | ||
return []interface{}{transformed} | ||
} | ||
func flattenSecretManagerSecretReplicationUserManagedReplicas(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { | ||
if v == nil { | ||
return v | ||
} | ||
l := v.([]interface{}) | ||
transformed := make([]interface{}, 0, len(l)) | ||
for _, raw := range l { | ||
original := raw.(map[string]interface{}) | ||
if len(original) < 1 { | ||
// Do not include empty json objects coming back from the api | ||
continue | ||
} | ||
transformed = append(transformed, map[string]interface{}{ | ||
"location": flattenSecretManagerSecretReplicationUserManagedReplicasLocation(original["location"], d, config), | ||
"customer_managed_encryption": flattenSecretManagerSecretReplicationUserManagedReplicasCustomerManagedEncryption(original["customerManagedEncryption"], d, config), | ||
}) | ||
} | ||
return transformed | ||
} | ||
func flattenSecretManagerSecretReplicationUserManagedReplicasLocation(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { | ||
return v | ||
} | ||
|
||
func flattenSecretManagerSecretReplicationUserManagedReplicasCustomerManagedEncryption(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { | ||
if v == nil { | ||
return nil | ||
} | ||
original := v.(map[string]interface{}) | ||
if len(original) == 0 { | ||
return nil | ||
} | ||
transformed := make(map[string]interface{}) | ||
transformed["kms_key_name"] = | ||
flattenSecretManagerSecretReplicationUserManagedReplicasCustomerManagedEncryptionKmsKeyName(original["kmsKeyName"], d, config) | ||
return []interface{}{transformed} | ||
} | ||
func flattenSecretManagerSecretReplicationUserManagedReplicasCustomerManagedEncryptionKmsKeyName(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { | ||
return v | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.