|
| 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