From 1618b0d5fbad3a23ce255ed567751b1371b42daf Mon Sep 17 00:00:00 2001 From: Sam Levenick Date: Fri, 8 Nov 2019 15:14:34 -0800 Subject: [PATCH 1/2] Send null logConfig if subnetwork is L7ILB --- products/compute/api.yaml | 3 ++- .../terraform/custom_expand/subnetwork_log_config.go.erb | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/products/compute/api.yaml b/products/compute/api.yaml index 42832938df98..e6873ce74e19 100644 --- a/products/compute/api.yaml +++ b/products/compute/api.yaml @@ -9182,7 +9182,8 @@ objects: update_id: 'logConfig' description: | Denotes the logging options for the subnetwork flow logs. If logging is enabled - logs will be exported to Stackdriver. + logs will be exported to Stackdriver. This field cannot be set if the `purpose` of this + subnetwork is `INTERNAL_HTTPS_LOAD_BALANCER` properties: - !ruby/object:Api::Type::Enum name: 'aggregationInterval' diff --git a/templates/terraform/custom_expand/subnetwork_log_config.go.erb b/templates/terraform/custom_expand/subnetwork_log_config.go.erb index 6a1ca64370b5..4a8559848d9f 100644 --- a/templates/terraform/custom_expand/subnetwork_log_config.go.erb +++ b/templates/terraform/custom_expand/subnetwork_log_config.go.erb @@ -13,6 +13,13 @@ # limitations under the License. -%> func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + purpose, ok := d.GetOkExists("purpose") + + if ok && purpose.(string) == "INTERNAL_HTTPS_LOAD_BALANCER" { + // Subnetworks for L7ILB do not accept any values for logConfig + return nil, nil + } + l := v.([]interface{}) transformed := make(map[string]interface{}) if len(l) == 0 || l[0] == nil { @@ -20,6 +27,7 @@ func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d T transformed["enable"] = false return transformed, nil } + raw := l[0] original := raw.(map[string]interface{}) From 1ea027cbea199b84f1a9c8848c257cf4cd60576c Mon Sep 17 00:00:00 2001 From: Sam Levenick Date: Fri, 8 Nov 2019 15:35:22 -0800 Subject: [PATCH 2/2] Move subnet ilb check to only if logConfig unspecified --- .../custom_expand/subnetwork_log_config.go.erb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/templates/terraform/custom_expand/subnetwork_log_config.go.erb b/templates/terraform/custom_expand/subnetwork_log_config.go.erb index 4a8559848d9f..a293f1b97562 100644 --- a/templates/terraform/custom_expand/subnetwork_log_config.go.erb +++ b/templates/terraform/custom_expand/subnetwork_log_config.go.erb @@ -13,16 +13,15 @@ # limitations under the License. -%> func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { - purpose, ok := d.GetOkExists("purpose") - - if ok && purpose.(string) == "INTERNAL_HTTPS_LOAD_BALANCER" { - // Subnetworks for L7ILB do not accept any values for logConfig - return nil, nil - } - l := v.([]interface{}) transformed := make(map[string]interface{}) if len(l) == 0 || l[0] == nil { + purpose, ok := d.GetOkExists("purpose") + + if ok && purpose.(string) == "INTERNAL_HTTPS_LOAD_BALANCER" { + // Subnetworks for L7ILB do not accept any values for logConfig + return nil, nil + } // send enable = false to ensure logging is disabled if there is no config transformed["enable"] = false return transformed, nil