Skip to content

Commit d12aacc

Browse files
alkobi-googleglasnt
authored andcommitted
feat(VPC Flow Logs): Prepare VPC Flow Logs for inclusion in C.G.C. documentation (terraform-google-modules#764)
* Prepare VPC Flow Logs for inclusion in C.G.C. documentation * Prepare VPC Flow Logs for inclusion in C.G.C. documentation * Prepare VPC Flow Logs for inclusion in C.G.C. documentation * Prepare VPC Flow Logs for inclusion in C.G.C. documentation * Fix description * Fix code review comments: Changed the directory name Simplified the region tag Removed unnecessary comments. * Fix all of the demo files to create every resource needed for the vpc flow logs. * Fix lint errors * Fix lint error. * Change region tags to differentiate between the setup and the VPC Flow Logs Config. * Fix lint errors --------- Co-authored-by: Katie McLaughlin <[email protected]>
1 parent dec3024 commit d12aacc

File tree

4 files changed

+284
-0
lines changed
  • network_management/vpcflowlogs

4 files changed

+284
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
# [START vpcflowlogs_interconnect_attachment_basic_parent_tag]
18+
# [START vpcflowlogs_interconnect_attachment_basic_vpcflow]
19+
resource "google_network_management_vpc_flow_logs_config" "vpc_flow_logs_config" {
20+
provider = google-beta
21+
22+
vpc_flow_logs_config_id = "vpcflowlogs-config"
23+
location = "global"
24+
interconnect_attachment = google_compute_interconnect_attachment.attachment.id
25+
}
26+
# [END vpcflowlogs_interconnect_attachment_basic_vpcflow]
27+
28+
# [START vpcflowlogs_interconnect_attachment_basic_network]
29+
resource "google_compute_network" "network" {
30+
name = "vpcflowlogs-network"
31+
}
32+
33+
resource "google_compute_router" "router" {
34+
name = "vpcflowlogs-router"
35+
region = "us-central1"
36+
network = google_compute_network.network.name
37+
bgp {
38+
asn = 16550
39+
}
40+
}
41+
42+
resource "google_compute_interconnect_attachment" "attachment" {
43+
name = "vpcflowlogs-attachment"
44+
region = "us-central1"
45+
router = google_compute_router.router.id
46+
edge_availability_domain = "AVAILABILITY_DOMAIN_1"
47+
type = "PARTNER"
48+
mtu = 1500
49+
}
50+
# [END vpcflowlogs_interconnect_attachment_basic_network]
51+
# [END vpcflowlogs_interconnect_attachment_basic_parent_tag]
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
# [START vpcflowlogs_interconnect_attachment_full_parent_tag]
18+
# [START vpcflowlogs_interconnect_attachment_full_vpcflow]
19+
resource "google_network_management_vpc_flow_logs_config" "vpc_flow_logs_config" {
20+
provider = google-beta
21+
22+
vpc_flow_logs_config_id = "vpcflowlogs-config"
23+
location = "global"
24+
interconnect_attachment = google_compute_interconnect_attachment.attachment.id
25+
aggregation_interval = "INTERVAL_10_MIN"
26+
description = "VPC Flow Logs over an Interconnect Attachment."
27+
flow_sampling = 0.7
28+
metadata = "INCLUDE_ALL_METADATA"
29+
state = "ENABLED"
30+
}
31+
# [END vpcflowlogs_interconnect_attachment_full_vpcflow]
32+
33+
# [START vpcflowlogs_interconnect_attachment_full_network]
34+
resource "google_compute_network" "network" {
35+
name = "vpcflowlogs-network"
36+
}
37+
38+
resource "google_compute_router" "router" {
39+
name = "vpcflowlogs-router"
40+
region = "us-central1"
41+
network = google_compute_network.network.name
42+
bgp {
43+
asn = 16550
44+
}
45+
}
46+
47+
resource "google_compute_interconnect_attachment" "attachment" {
48+
name = "vpcflowlogs-attachment"
49+
region = "us-central1"
50+
router = google_compute_router.router.id
51+
edge_availability_domain = "AVAILABILITY_DOMAIN_1"
52+
type = "PARTNER"
53+
mtu = 1500
54+
}
55+
# [END vpcflowlogs_interconnect_attachment_full_network]
56+
# [END vpcflowlogs_interconnect_attachment_full_parent_tag]
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
# [START vpcflowlogs_vpn_tunnel_basic_parent_tag]
18+
# [START vpcflowlogs_vpn_tunnel_basic_vpcflow]
19+
resource "google_network_management_vpc_flow_logs_config" "vpc_flow_logs_config" {
20+
provider = google-beta
21+
22+
vpc_flow_logs_config_id = "vpcflowlogs-config"
23+
location = "global"
24+
vpn_tunnel = google_compute_vpn_tunnel.tunnel.id
25+
}
26+
# [END vpcflowlogs_vpn_tunnel_basic_vpcflow]
27+
28+
# [START vpcflowlogs_vpn_tunnel_basic_network]
29+
resource "google_compute_vpn_tunnel" "tunnel" {
30+
name = "vpcflowlogs-tunnel"
31+
peer_ip = "15.0.0.120"
32+
shared_secret = "a secret message"
33+
target_vpn_gateway = google_compute_vpn_gateway.gatway.id
34+
35+
depends_on = [
36+
google_compute_forwarding_rule.fr_esp,
37+
google_compute_forwarding_rule.fr_udp500,
38+
google_compute_forwarding_rule.fr_udp4500,
39+
]
40+
}
41+
42+
resource "google_compute_vpn_gateway" "gatway" {
43+
name = "vpcflowlogs-gateway"
44+
network = google_compute_network.network.id
45+
}
46+
47+
resource "google_compute_network" "network" {
48+
name = "vpcflowlogs-network"
49+
}
50+
51+
resource "google_compute_address" "vpn_static_ip" {
52+
name = "vpcflowlogs-vpn-static-ip"
53+
}
54+
55+
resource "google_compute_forwarding_rule" "fr_esp" {
56+
name = "vpcflowlogs-fr-esp"
57+
ip_protocol = "ESP"
58+
ip_address = google_compute_address.vpn_static_ip.address
59+
target = google_compute_vpn_gateway.gatway.id
60+
}
61+
62+
resource "google_compute_forwarding_rule" "fr_udp500" {
63+
name = "vpcflowlogs-fr-udp500"
64+
ip_protocol = "UDP"
65+
port_range = "500"
66+
ip_address = google_compute_address.vpn_static_ip.address
67+
target = google_compute_vpn_gateway.gatway.id
68+
}
69+
70+
resource "google_compute_forwarding_rule" "fr_udp4500" {
71+
name = "vpcflowlogs-fr-udp4500"
72+
ip_protocol = "UDP"
73+
port_range = "4500"
74+
ip_address = google_compute_address.vpn_static_ip.address
75+
target = google_compute_vpn_gateway.gatway.id
76+
}
77+
78+
resource "google_compute_route" "route" {
79+
name = "vpcflowlogs-route"
80+
network = google_compute_network.network.name
81+
dest_range = "15.0.0.0/24"
82+
priority = 1000
83+
next_hop_vpn_tunnel = google_compute_vpn_tunnel.tunnel.id
84+
}
85+
# [END vpcflowlogs_vpn_tunnel_basic_network]
86+
# [END vpcflowlogs_vpn_tunnel_basic_parent_tag]
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/**
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
# [START vpcflowlogs_vpn_tunnel_full_parent_tag]
18+
# [START vpcflowlogs_vpn_tunnel_full_vpcflow]
19+
resource "google_network_management_vpc_flow_logs_config" "vpc_flow_logs_config" {
20+
provider = google-beta
21+
22+
vpc_flow_logs_config_id = "vpcflowlogs-config"
23+
location = "global"
24+
vpn_tunnel = google_compute_vpn_tunnel.tunnel.id
25+
aggregation_interval = "INTERVAL_10_MIN"
26+
description = "VPC Flow Logs over a VPN Gateway."
27+
flow_sampling = 0.7
28+
metadata = "INCLUDE_ALL_METADATA"
29+
state = "ENABLED"
30+
}
31+
# [END vpcflowlogs_vpn_tunnel_full_vpcflow]
32+
33+
# [START vpcflowlogs_vpn_tunnel_full_network]
34+
resource "google_compute_vpn_tunnel" "tunnel" {
35+
name = "vpcflowlogs-tunnel"
36+
peer_ip = "15.0.0.120"
37+
shared_secret = "a secret message"
38+
target_vpn_gateway = google_compute_vpn_gateway.gatway.id
39+
40+
depends_on = [
41+
google_compute_forwarding_rule.fr_esp,
42+
google_compute_forwarding_rule.fr_udp500,
43+
google_compute_forwarding_rule.fr_udp4500,
44+
]
45+
}
46+
47+
resource "google_compute_vpn_gateway" "gatway" {
48+
name = "vpcflowlogs-gateway"
49+
network = google_compute_network.network.id
50+
}
51+
52+
resource "google_compute_network" "network" {
53+
name = "vpcflowlogs-network"
54+
}
55+
56+
resource "google_compute_address" "vpn_static_ip" {
57+
name = "vpcflowlogs-vpn-static-ip"
58+
}
59+
60+
resource "google_compute_forwarding_rule" "fr_esp" {
61+
name = "vpcflowlogs-fr-esp"
62+
ip_protocol = "ESP"
63+
ip_address = google_compute_address.vpn_static_ip.address
64+
target = google_compute_vpn_gateway.gatway.id
65+
}
66+
67+
resource "google_compute_forwarding_rule" "fr_udp500" {
68+
name = "vpcflowlogs-fr-udp500"
69+
ip_protocol = "UDP"
70+
port_range = "500"
71+
ip_address = google_compute_address.vpn_static_ip.address
72+
target = google_compute_vpn_gateway.gatway.id
73+
}
74+
75+
resource "google_compute_forwarding_rule" "fr_udp4500" {
76+
name = "vpcflowlogs-fr-udp4500"
77+
ip_protocol = "UDP"
78+
port_range = "4500"
79+
ip_address = google_compute_address.vpn_static_ip.address
80+
target = google_compute_vpn_gateway.gatway.id
81+
}
82+
83+
resource "google_compute_route" "route" {
84+
name = "vpcflowlogs-route"
85+
network = google_compute_network.network.name
86+
dest_range = "15.0.0.0/24"
87+
priority = 1000
88+
next_hop_vpn_tunnel = google_compute_vpn_tunnel.tunnel.id
89+
}
90+
# [END vpcflowlogs_vpn_tunnel_full_network]
91+
# [END vpcflowlogs_vpn_tunnel_full_parent_tag]

0 commit comments

Comments
 (0)