Skip to content

Commit 2e7b969

Browse files
alkobi-googleBBBmau
authored andcommitted
Add VPC Flow Logs Config Terraform API (GoogleCloudPlatform#12161)
Signed-off-by: alkobi-google <[email protected]>
1 parent 14dfd4e commit 2e7b969

7 files changed

+680
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
# Copyright 2024 Google Inc.
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
---
15+
name: 'VpcFlowLogsConfig'
16+
description:
17+
VPC Flow Logs Config is a resource that lets you configure
18+
Flow Logs for VPC, Interconnect attachments or VPN Tunnels.
19+
min_version: beta
20+
id_format: 'projects/{{project}}/locations/{{location}}/vpcFlowLogsConfigs/{{vpc_flow_logs_config_id}}'
21+
base_url: 'projects/{{project}}/locations/{{location}}/vpcFlowLogsConfigs'
22+
self_link: 'projects/{{project}}/locations/{{location}}/vpcFlowLogsConfigs/{{vpc_flow_logs_config_id}}'
23+
create_url: 'projects/{{project}}/locations/{{location}}/vpcFlowLogsConfigs?vpcFlowLogsConfigId={{vpc_flow_logs_config_id}}'
24+
update_verb: 'PATCH'
25+
update_mask: true
26+
import_format:
27+
- 'projects/{{project}}/locations/{{location}}/vpcFlowLogsConfigs/{{vpc_flow_logs_config_id}}'
28+
timeouts:
29+
insert_minutes: 20
30+
update_minutes: 20
31+
delete_minutes: 20
32+
autogen_async: true
33+
async:
34+
actions: ['create', 'delete', 'update']
35+
type: 'OpAsync'
36+
operation:
37+
base_url: '{{op_id}}'
38+
path: 'name'
39+
wait_ms: 1000
40+
result:
41+
path: 'response'
42+
resource_inside_response: true
43+
error:
44+
path: 'error'
45+
message: 'message'
46+
custom_code:
47+
examples:
48+
- name: 'network_management_vpc_flow_logs_config_interconnect_full'
49+
primary_resource_id: 'interconnect-test'
50+
min_version: 'beta'
51+
vars:
52+
network_name: 'full-interconnect-test-network'
53+
router_name: 'full-interconnect-test-router'
54+
vpc_flow_logs_config_id: 'full-interconnect-test-id'
55+
interconnect_attachment_name: 'full-interconnect-test-id'
56+
- name: 'network_management_vpc_flow_logs_config_interconnect_basic'
57+
primary_resource_id: 'interconnect-test'
58+
min_version: 'beta'
59+
vars:
60+
network_name: 'basic-interconnect-test-network'
61+
router_name: 'basic-interconnect-test-router'
62+
vpc_flow_logs_config_id: 'basic-interconnect-test-id'
63+
interconnect_attachment_name: 'basic-interconnect-test-id'
64+
- name: 'network_management_vpc_flow_logs_config_vpn_basic'
65+
primary_resource_id: 'vpn-test'
66+
min_version: 'beta'
67+
vars:
68+
network_name: 'basic-test-network'
69+
vpn_tunnel_name: 'basic-test-tunnel'
70+
target_vpn_gateway_name: 'basic-test-gateway'
71+
address_name: 'basic-test-address'
72+
udp500_forwarding_rule_name: 'basic-test-fr500'
73+
udp4500_forwarding_rule_name: 'basic-test-fr4500'
74+
esp_forwarding_rule_name: 'basic-test-fresp'
75+
route_name: 'basic-test-route'
76+
vpc_flow_logs_config_id: 'basic-test-id'
77+
- name: 'network_management_vpc_flow_logs_config_vpn_full'
78+
primary_resource_id: 'vpn-test'
79+
min_version: 'beta'
80+
vars:
81+
network_name: 'full-test-network'
82+
vpn_tunnel_name: 'full-test-tunnel'
83+
target_vpn_gateway_name: 'full-test-gateway'
84+
address_name: 'full-test-address'
85+
udp500_forwarding_rule_name: 'full-test-fr500'
86+
udp4500_forwarding_rule_name: 'full-test-fr4500'
87+
esp_forwarding_rule_name: 'full-test-fresp'
88+
route_name: 'full-test-route'
89+
vpc_flow_logs_config_id: 'full-test-id'
90+
parameters:
91+
- name: 'location'
92+
type: String
93+
description: |
94+
Resource ID segment making up resource `name`. It identifies the resource
95+
within its parent collection as described in https://google.aip.dev/122. See documentation
96+
for resource type `networkmanagement.googleapis.com/VpcFlowLogsConfig`.
97+
url_param_only: true
98+
required: true
99+
immutable: true
100+
- name: 'vpcFlowLogsConfigId'
101+
type: String
102+
description: |
103+
Required. ID of the `VpcFlowLogsConfig`.
104+
url_param_only: true
105+
required: true
106+
immutable: true
107+
properties:
108+
- name: 'name'
109+
type: String
110+
description: |
111+
Identifier. Unique name of the configuration using the form: `projects/{project_id}/locations/global/vpcFlowLogsConfigs/{vpc_flow_logs_config_id}`
112+
output: true
113+
- name: 'description'
114+
type: String
115+
description: |
116+
Optional. The user-supplied description of the VPC Flow Logs configuration. Maximum
117+
of 512 characters.
118+
- name: 'state'
119+
type: String
120+
default_from_api: true
121+
description: |
122+
Optional. The state of the VPC Flow Log configuration. Default value
123+
is ENABLED. When creating a new configuration, it must be enabled. Possible
124+
- name: 'aggregationInterval'
125+
type: String
126+
default_from_api: true
127+
description: |
128+
Optional. The aggregation interval for the logs. Default value is
129+
INTERVAL_5_SEC. Possible values: AGGREGATION_INTERVAL_UNSPECIFIED INTERVAL_5_SEC INTERVAL_30_SEC INTERVAL_1_MIN INTERVAL_5_MIN INTERVAL_10_MIN INTERVAL_15_MIN"
130+
- name: 'flowSampling'
131+
type: Double
132+
default_from_api: true
133+
description: |
134+
Optional. The value of the field must be in (0, 1]. The sampling rate
135+
of VPC Flow Logs where 1.0 means all collected logs are reported. Setting the
136+
sampling rate to 0.0 is not allowed. If you want to disable VPC Flow Logs, use
137+
the state field instead. Default value is 1.0.
138+
- name: 'metadata'
139+
type: String
140+
default_from_api: true
141+
description: |
142+
Optional. Configures whether all, none or a subset of metadata fields
143+
should be added to the reported VPC flow logs. Default value is INCLUDE_ALL_METADATA.
144+
Possible values: METADATA_UNSPECIFIED INCLUDE_ALL_METADATA EXCLUDE_ALL_METADATA CUSTOM_METADATA
145+
- name: 'metadataFields'
146+
type: Array
147+
description: |
148+
Optional. Custom metadata fields to include in the reported VPC flow
149+
logs. Can only be specified if \"metadata\" was set to CUSTOM_METADATA.
150+
item_type:
151+
type: String
152+
- name: 'filterExpr'
153+
type: String
154+
description: |
155+
Optional. Export filter used to define which VPC Flow Logs should be logged.
156+
- name: 'interconnectAttachment'
157+
type: String
158+
description: |
159+
Traffic will be logged from the Interconnect Attachment. Format: projects/{project_id}/regions/{region}/interconnectAttachments/{name}
160+
- name: 'vpnTunnel'
161+
type: String
162+
description: |
163+
Traffic will be logged from the VPN Tunnel. Format: projects/{project_id}/regions/{region}/vpnTunnels/{name}
164+
- name: 'labels'
165+
type: KeyValueLabels
166+
description: |
167+
Optional. Resource labels to represent user-provided metadata.
168+
- name: 'createTime'
169+
type: String
170+
description: |
171+
Output only. The time the config was created.
172+
output: true
173+
- name: 'updateTime'
174+
type: String
175+
description: |
176+
Output only. The time the config was updated.
177+
output: true

mmv1/products/networkmanagement/product.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ display_name: 'NetworkManagement'
1717
versions:
1818
- name: 'ga'
1919
base_url: 'https://networkmanagement.googleapis.com/v1/'
20+
- name: 'beta'
21+
base_url: 'https://networkmanagement.googleapis.com/v1beta1/'
2022
scopes:
2123
- 'https://www.googleapis.com/auth/cloud-platform'
2224
async:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
data "google_project" "project" {
2+
provider = google-beta
3+
}
4+
5+
resource "google_network_management_vpc_flow_logs_config" "{{$.PrimaryResourceId}}" {
6+
provider = google-beta
7+
vpc_flow_logs_config_id = "{{index $.Vars "vpc_flow_logs_config_id"}}"
8+
location = "global"
9+
interconnect_attachment = "projects/${data.google_project.project.number}/regions/us-east4/interconnectAttachments/${google_compute_interconnect_attachment.attachment.name}"
10+
}
11+
12+
resource "google_compute_network" "network" {
13+
provider = google-beta
14+
name = "{{index $.Vars "network_name"}}"
15+
}
16+
17+
resource "google_compute_router" "router" {
18+
provider = google-beta
19+
name = "{{index $.Vars "router_name"}}"
20+
network = google_compute_network.network.name
21+
bgp {
22+
asn = 16550
23+
}
24+
}
25+
26+
resource "google_compute_interconnect_attachment" "attachment" {
27+
provider = google-beta
28+
name = "{{index $.Vars "interconnect_attachment_name"}}"
29+
edge_availability_domain = "AVAILABILITY_DOMAIN_1"
30+
type = "PARTNER"
31+
router = google_compute_router.router.id
32+
mtu = 1500
33+
}
34+
35+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
data "google_project" "project" {
2+
provider = google-beta
3+
}
4+
5+
resource "google_network_management_vpc_flow_logs_config" "{{$.PrimaryResourceId}}" {
6+
provider = google-beta
7+
vpc_flow_logs_config_id = "{{index $.Vars "vpc_flow_logs_config_id"}}"
8+
location = "global"
9+
interconnect_attachment = "projects/${data.google_project.project.number}/regions/us-east4/interconnectAttachments/${google_compute_interconnect_attachment.attachment.name}"
10+
state = "ENABLED"
11+
aggregation_interval = "INTERVAL_5_SEC"
12+
description = "VPC Flow Logs over a VPN Gateway."
13+
flow_sampling = 0.5
14+
metadata = "INCLUDE_ALL_METADATA"
15+
}
16+
17+
resource "google_compute_network" "network" {
18+
provider = google-beta
19+
name = "{{index $.Vars "network_name"}}"
20+
}
21+
22+
resource "google_compute_router" "router" {
23+
provider = google-beta
24+
name = "{{index $.Vars "router_name"}}"
25+
network = google_compute_network.network.name
26+
bgp {
27+
asn = 16550
28+
}
29+
}
30+
31+
resource "google_compute_interconnect_attachment" "attachment" {
32+
provider = google-beta
33+
name = "{{index $.Vars "interconnect_attachment_name"}}"
34+
edge_availability_domain = "AVAILABILITY_DOMAIN_1"
35+
type = "PARTNER"
36+
router = google_compute_router.router.id
37+
mtu = 1500
38+
}
39+
40+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
data "google_project" "project" {
2+
provider = google-beta
3+
}
4+
5+
resource "google_network_management_vpc_flow_logs_config" "{{$.PrimaryResourceId}}" {
6+
provider = google-beta
7+
vpc_flow_logs_config_id = "{{index $.Vars "vpc_flow_logs_config_id"}}"
8+
location = "global"
9+
vpn_tunnel = "projects/${data.google_project.project.number}/regions/us-central1/vpnTunnels/${google_compute_vpn_tunnel.tunnel.name}"
10+
}
11+
12+
resource "google_compute_vpn_tunnel" "tunnel" {
13+
provider = google-beta
14+
name = "{{index $.Vars "vpn_tunnel_name"}}"
15+
peer_ip = "15.0.0.120"
16+
shared_secret = "a secret message"
17+
target_vpn_gateway = google_compute_vpn_gateway.target_gateway.id
18+
19+
depends_on = [
20+
google_compute_forwarding_rule.fr_esp,
21+
google_compute_forwarding_rule.fr_udp500,
22+
google_compute_forwarding_rule.fr_udp4500,
23+
]
24+
}
25+
26+
resource "google_compute_vpn_gateway" "target_gateway" {
27+
provider = google-beta
28+
name = "{{index $.Vars "target_vpn_gateway_name"}}"
29+
network = google_compute_network.network.id
30+
}
31+
32+
resource "google_compute_network" "network" {
33+
provider = google-beta
34+
name = "{{index $.Vars "network_name"}}"
35+
}
36+
37+
resource "google_compute_address" "vpn_static_ip" {
38+
provider = google-beta
39+
name = "{{index $.Vars "address_name"}}"
40+
}
41+
42+
resource "google_compute_forwarding_rule" "fr_esp" {
43+
provider = google-beta
44+
name = "{{index $.Vars "esp_forwarding_rule_name"}}"
45+
ip_protocol = "ESP"
46+
ip_address = google_compute_address.vpn_static_ip.address
47+
target = google_compute_vpn_gateway.target_gateway.id
48+
}
49+
50+
resource "google_compute_forwarding_rule" "fr_udp500" {
51+
provider = google-beta
52+
name = "{{index $.Vars "udp500_forwarding_rule_name"}}"
53+
ip_protocol = "UDP"
54+
port_range = "500"
55+
ip_address = google_compute_address.vpn_static_ip.address
56+
target = google_compute_vpn_gateway.target_gateway.id
57+
}
58+
59+
resource "google_compute_forwarding_rule" "fr_udp4500" {
60+
provider = google-beta
61+
name = "{{index $.Vars "udp4500_forwarding_rule_name"}}"
62+
ip_protocol = "UDP"
63+
port_range = "4500"
64+
ip_address = google_compute_address.vpn_static_ip.address
65+
target = google_compute_vpn_gateway.target_gateway.id
66+
}
67+
68+
resource "google_compute_route" "route" {
69+
provider = google-beta
70+
name = "{{index $.Vars "route_name"}}"
71+
network = google_compute_network.network.name
72+
dest_range = "15.0.0.0/24"
73+
priority = 1000
74+
next_hop_vpn_tunnel = google_compute_vpn_tunnel.tunnel.id
75+
}
76+

0 commit comments

Comments
 (0)