Skip to content

Commit f7de501

Browse files
authored
tgc-revival: allow the fields with empty string to show up in HCL (GoogleCloudPlatform#16507)
1 parent e24eb2e commit f7de501

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

mmv1/products/compute/Subnetwork.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ properties:
223223
validation:
224224
function: verify.ValidateIpCidrRange
225225
default_from_api: true
226+
custom_tgc_flatten: 'templates/tgc_next/custom_flatten/compute_subnetwork_ip_cidr_range.go.tmpl'
226227
- name: reservedInternalRange
227228
type: ResourceRef
228229
description: |

mmv1/products/datastream/ConnectionProfile.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ properties:
208208
Password for the Oracle connection.
209209
sensitive: true
210210
custom_flatten: 'templates/terraform/custom_flatten/datastream_connection_profile_oracle_profile_password.go.tmpl'
211+
tgc_ignore_terraform_custom_flatten: true
211212
- name: 'secretManagerStoredPassword'
212213
type: String
213214
description: |
@@ -280,6 +281,7 @@ properties:
280281
Password for the MySQL connection.
281282
sensitive: true
282283
custom_flatten: 'templates/terraform/custom_flatten/datastream_connection_profile_mysql_profile_password.go.tmpl'
284+
tgc_ignore_terraform_custom_flatten: true
283285
is_missing_in_cai: true
284286
- name: 'secretManagerStoredPassword'
285287
type: String
@@ -299,6 +301,7 @@ properties:
299301
immutable: true
300302
sensitive: true
301303
custom_flatten: 'templates/terraform/custom_flatten/datastream_connection_profile_mysql_profile_ssl_config_client_key.go.tmpl'
304+
tgc_ignore_terraform_custom_flatten: true
302305
- name: 'clientKeySet'
303306
type: Boolean
304307
description: |
@@ -314,6 +317,7 @@ properties:
314317
immutable: true
315318
sensitive: true
316319
custom_flatten: 'templates/terraform/custom_flatten/datastream_connection_profile_mysql_profile_ssl_config_client_certificate.go.tmpl'
320+
tgc_ignore_terraform_custom_flatten: true
317321
- name: 'clientCertificateSet'
318322
type: Boolean
319323
description: |
@@ -327,6 +331,7 @@ properties:
327331
immutable: true
328332
sensitive: true
329333
custom_flatten: 'templates/terraform/custom_flatten/datastream_connection_profile_mysql_profile_ssl_config_ca_certificate.go.tmpl'
334+
tgc_ignore_terraform_custom_flatten: true
330335
- name: 'caCertificateSet'
331336
type: Boolean
332337
description: |
@@ -387,6 +392,7 @@ properties:
387392
sensitive: true
388393
is_missing_in_cai: true
389394
custom_flatten: 'templates/terraform/custom_flatten/datastream_connection_profile_postgresql_profile_password.go.tmpl'
395+
tgc_ignore_terraform_custom_flatten: true
390396
- name: 'secretManagerStoredPassword'
391397
type: String
392398
description: |
@@ -590,6 +596,7 @@ properties:
590596
Password for the SQL Server connection.
591597
sensitive: true
592598
custom_flatten: 'templates/terraform/custom_flatten/datastream_connection_profile_sql_server_profile_password.go.tmpl'
599+
tgc_ignore_terraform_custom_flatten: true
593600
- name: 'secretManagerStoredPassword'
594601
type: String
595602
description: |
@@ -774,6 +781,7 @@ properties:
774781
conflicts:
775782
- forward_ssh_connectivity.0.private_key
776783
custom_flatten: 'templates/terraform/custom_flatten/datastream_connection_profile_forward_ssh_connectivity_password.go.tmpl'
784+
tgc_ignore_terraform_custom_flatten: true
777785
is_missing_in_cai: true
778786
- name: 'privateKey'
779787
type: String
@@ -783,6 +791,7 @@ properties:
783791
conflicts:
784792
- forward_ssh_connectivity.0.password
785793
custom_flatten: 'templates/terraform/custom_flatten/datastream_connection_profile_forward_ssh_connectivity_private_key.go.tmpl'
794+
tgc_ignore_terraform_custom_flatten: true
786795
is_missing_in_cai: true
787796
- name: 'privateConnectivity'
788797
type: NestedObject
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// flatten{{$.GetPrefix}}{{$.TitlelizeProperty}} handles empty strings for IpCidrRange which occur in IPV6_ONLY subnets.
2+
// Terraform validation fails on empty string, so we convert it to nil.
3+
func flatten{{$.GetPrefix}}{{$.TitlelizeProperty}}(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
4+
if v == nil {
5+
return nil
6+
}
7+
if s, ok := v.(string); ok && s == "" {
8+
return nil
9+
}
10+
return v
11+
}

mmv1/third_party/tgc_next/pkg/cai2hcl/models/hcl_block.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ func hclWriteBlock(val cty.Value, body *hclwrite.Body) error {
6565
}
6666
fallthrough
6767
default:
68-
if objValType.FriendlyName() == "string" && objVal.AsString() == "" {
69-
continue
70-
}
7168
body.SetAttributeValue(objKey.AsString(), objVal)
7269
}
7370
}

0 commit comments

Comments
 (0)