Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subnet logconfig prepare for 3.0.0 #2572

Merged
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
2 changes: 1 addition & 1 deletion build/terraform-mapper
2 changes: 2 additions & 0 deletions products/compute/ansible.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ overrides: !ruby/object:Overrides::ResourceOverrides
fingerprint: !ruby/object:Overrides::Ansible::PropertyOverride
update_verb: :PATCH
update_url: projects/{{project}}/regions/{{region}}/subnetworks/{{name}}
logConfig: !ruby/object:Overrides::Ansible::PropertyOverride
exclude: true
TargetPool: !ruby/object:Overrides::Ansible::ResourceOverride
transport: !ruby/object:Overrides::Ansible::Transport
encoder: encode_request
Expand Down
8 changes: 7 additions & 1 deletion products/compute/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8731,6 +8731,9 @@ objects:
update_id: 'enableFlowLogs'
fingerprint_name: 'fingerprint'
send_empty_value: true
deprecation_message: >-
This field is being removed in favor of log_config. If log_config is present,
flow logs are enabled.
# TODO(rileykarson): Work with rambleraptor to remove this field from downstreams.
- !ruby/object:Api::Type::Fingerprint
name: 'fingerprint'
Expand Down Expand Up @@ -8814,10 +8817,13 @@ objects:
input: true
- !ruby/object:Api::Type::NestedObject
name: 'logConfig'
update_verb: :PATCH
update_url: projects/{{project}}/regions/{{region}}/subnetworks/{{name}}
fingerprint_name: 'fingerprint'
update_id: 'logConfig'
description: |
Denotes the logging options for the subnetwork flow logs. If logging is enabled
logs will be exported to Stackdriver.
min_version: beta
properties:
- !ruby/object:Api::Type::Enum
name: 'aggregationInterval'
Expand Down
11 changes: 7 additions & 4 deletions products/compute/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1669,6 +1669,12 @@ overrides: !ruby/object:Overrides::ResourceOverrides
function: 'validateIpCidrRange'
fingerprint: !ruby/object:Overrides::Terraform::PropertyOverride
exclude: false
enableFlowLogs: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
logConfig: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
custom_expand: 'templates/terraform/custom_expand/subnetwork_log_config.go.erb'
custom_flatten: 'templates/terraform/custom_flatten/subnetwork_log_config.go.erb'
ipCidrRange: !ruby/object:Overrides::Terraform::PropertyOverride
validation: !ruby/object:Provider::Terraform::Validation
function: 'validateIpCidrRange'
Expand All @@ -1677,8 +1683,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides
input: false
default_from_api: true
custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.erb'
logConfig: !ruby/object:Overrides::Terraform::PropertyOverride
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we able to keep the field O+C? I'm a little hesitant to start catching drift out of the blue, especially on our last 2.X release. However, it's beta-only so it's allowed imo.

default_from_api: true
purpose: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
custom_code: !ruby/object:Provider::Terraform::CustomCode
Expand All @@ -1692,9 +1696,8 @@ overrides: !ruby/object:Overrides::ResourceOverrides
subnetwork_name: "test-subnetwork"
network_name: "test-network"
- !ruby/object:Provider::Terraform::Examples
name: "subnetwork_logging_config_beta"
name: "subnetwork_logging_config"
primary_resource_id: "subnet-with-logging"
min_version: beta
vars:
subnetwork_name: "log-test-subnetwork"
network_name: "log-test-network"
Expand Down
34 changes: 34 additions & 0 deletions templates/terraform/custom_expand/subnetwork_log_config.go.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<%- # the license inside this block applies to this file
# Copyright 2018 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 expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})

v, ok := d.GetOkExists("enable_flow_logs")

transformed := make(map[string]interface{})
if !ok || v.(bool) {
transformed["enable"] = true
transformed["aggregationInterval"] = original["aggregation_interval"]
transformed["flowSampling"] = original["flow_sampling"]
transformed["metadata"] = original["metadata"]
}

return transformed, nil
}
34 changes: 34 additions & 0 deletions templates/terraform/custom_flatten/subnetwork_log_config.go.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<%# The license inside this block applies to this file.
# Copyright 2019 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 flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData) interface{} {
if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}

v, ok := original["enable"]
if ok && !v.(bool) {
return nil
}

transformed := make(map[string]interface{})
transformed["flow_sampling"] = original["flowSampling"]
transformed["aggregation_interval"] = original["aggregationInterval"]
transformed["metadata"] = original["metadata"]
return []interface{}{transformed}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
resource "google_compute_subnetwork" "subnet-with-logging" {
provider = "google-beta"
name = "<%= ctx[:vars]['subnetwork_name'] %>"
ip_cidr_range = "10.2.0.0/16"
region = "us-central1"
network = "${google_compute_network.custom-test.self_link}"

enable_flow_logs = true
log_config {
aggregation_interval = "INTERVAL_10_MIN"
flow_sampling = 0.5
metadata = "INCLUDE_ALL_METADATA"
flow_sampling = 0.5
metadata = "INCLUDE_ALL_METADATA"
}
}

resource "google_compute_network" "custom-test" {
provider = "google-beta"
name = "<%= ctx[:vars]['network_name'] %>"
auto_create_subnetworks = false
}

provider "google-beta"{
region = "us-central1"
zone = "us-central1-a"
}
Loading