Skip to content

Commit 0a9fb3d

Browse files
Promote VPC Flow Logs Terraform API to GA (#12579) (#872)
[upstream:5e6616b9bfa37e9c5b1e2937215a7f2db3a2c0da] Signed-off-by: Modular Magician <[email protected]>
1 parent 7aa664a commit 0a9fb3d

File tree

16 files changed

+602
-0
lines changed

16 files changed

+602
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This file has some scaffolding to make sure that names are unique and that
2+
# a region and zone are selected when you try to create your Terraform resources.
3+
4+
locals {
5+
name_suffix = "${random_pet.suffix.id}"
6+
}
7+
8+
resource "random_pet" "suffix" {
9+
length = 2
10+
}
11+
12+
provider "google" {
13+
region = "us-central1"
14+
zone = "us-central1-c"
15+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
data "google_project" "project" {
2+
}
3+
4+
resource "google_network_management_vpc_flow_logs_config" "interconnect-test" {
5+
vpc_flow_logs_config_id = "basic-interconnect-test-id-${local.name_suffix}"
6+
location = "global"
7+
interconnect_attachment = "projects/${data.google_project.project.number}/regions/us-east4/interconnectAttachments/${google_compute_interconnect_attachment.attachment.name}"
8+
}
9+
10+
resource "google_compute_network" "network" {
11+
name = "basic-interconnect-test-network-${local.name_suffix}"
12+
}
13+
14+
resource "google_compute_router" "router" {
15+
name = "basic-interconnect-test-router-${local.name_suffix}"
16+
network = google_compute_network.network.name
17+
bgp {
18+
asn = 16550
19+
}
20+
}
21+
22+
resource "google_compute_interconnect_attachment" "attachment" {
23+
name = "basic-interconnect-test-id-${local.name_suffix}"
24+
edge_availability_domain = "AVAILABILITY_DOMAIN_1"
25+
type = "PARTNER"
26+
router = google_compute_router.router.id
27+
mtu = 1500
28+
}
29+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
===
2+
3+
These examples use real resources that will be billed to the
4+
Google Cloud Platform project you use - so make sure that you
5+
run "terraform destroy" before quitting!
6+
7+
===
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Network Management Vpc Flow Logs Config Interconnect Basic - Terraform
2+
3+
## Setup
4+
5+
<walkthrough-author name="[email protected]" analyticsId="UA-125550242-1" tutorialName="network_management_vpc_flow_logs_config_interconnect_basic" repositoryUrl="https://github.com/terraform-google-modules/docs-examples"></walkthrough-author>
6+
7+
Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform.
8+
9+
<walkthrough-project-billing-setup></walkthrough-project-billing-setup>
10+
11+
Terraform provisions real GCP resources, so anything you create in this session will be billed against this project.
12+
13+
## Terraforming!
14+
15+
Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command
16+
to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up
17+
the project name from the environment variable.
18+
19+
```bash
20+
export GOOGLE_CLOUD_PROJECT={{project-id}}
21+
```
22+
23+
After that, let's get Terraform started. Run the following to pull in the providers.
24+
25+
```bash
26+
terraform init
27+
```
28+
29+
With the providers downloaded and a project set, you're ready to use Terraform. Go ahead!
30+
31+
```bash
32+
terraform apply
33+
```
34+
35+
Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan.
36+
37+
```bash
38+
yes
39+
```
40+
41+
42+
## Post-Apply
43+
44+
### Editing your config
45+
46+
Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed.
47+
48+
```bash
49+
terraform plan
50+
```
51+
52+
So let's make a change! Try editing a number, or appending a value to the name in the editor. Then,
53+
run a 'plan' again.
54+
55+
```bash
56+
terraform plan
57+
```
58+
59+
Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes
60+
at the 'yes' prompt.
61+
62+
```bash
63+
terraform apply
64+
```
65+
66+
```bash
67+
yes
68+
```
69+
70+
## Cleanup
71+
72+
Run the following to remove the resources Terraform provisioned:
73+
74+
```bash
75+
terraform destroy
76+
```
77+
```bash
78+
yes
79+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This file has some scaffolding to make sure that names are unique and that
2+
# a region and zone are selected when you try to create your Terraform resources.
3+
4+
locals {
5+
name_suffix = "${random_pet.suffix.id}"
6+
}
7+
8+
resource "random_pet" "suffix" {
9+
length = 2
10+
}
11+
12+
provider "google" {
13+
region = "us-central1"
14+
zone = "us-central1-c"
15+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
data "google_project" "project" {
2+
}
3+
4+
resource "google_network_management_vpc_flow_logs_config" "interconnect-test" {
5+
vpc_flow_logs_config_id = "full-interconnect-test-id-${local.name_suffix}"
6+
location = "global"
7+
interconnect_attachment = "projects/${data.google_project.project.number}/regions/us-east4/interconnectAttachments/${google_compute_interconnect_attachment.attachment.name}"
8+
state = "ENABLED"
9+
aggregation_interval = "INTERVAL_5_SEC"
10+
description = "VPC Flow Logs over a VPN Gateway."
11+
flow_sampling = 0.5
12+
metadata = "INCLUDE_ALL_METADATA"
13+
}
14+
15+
resource "google_compute_network" "network" {
16+
name = "full-interconnect-test-network-${local.name_suffix}"
17+
}
18+
19+
resource "google_compute_router" "router" {
20+
name = "full-interconnect-test-router-${local.name_suffix}"
21+
network = google_compute_network.network.name
22+
bgp {
23+
asn = 16550
24+
}
25+
}
26+
27+
resource "google_compute_interconnect_attachment" "attachment" {
28+
name = "full-interconnect-test-id-${local.name_suffix}"
29+
edge_availability_domain = "AVAILABILITY_DOMAIN_1"
30+
type = "PARTNER"
31+
router = google_compute_router.router.id
32+
mtu = 1500
33+
}
34+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
===
2+
3+
These examples use real resources that will be billed to the
4+
Google Cloud Platform project you use - so make sure that you
5+
run "terraform destroy" before quitting!
6+
7+
===
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Network Management Vpc Flow Logs Config Interconnect Full - Terraform
2+
3+
## Setup
4+
5+
<walkthrough-author name="[email protected]" analyticsId="UA-125550242-1" tutorialName="network_management_vpc_flow_logs_config_interconnect_full" repositoryUrl="https://github.com/terraform-google-modules/docs-examples"></walkthrough-author>
6+
7+
Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform.
8+
9+
<walkthrough-project-billing-setup></walkthrough-project-billing-setup>
10+
11+
Terraform provisions real GCP resources, so anything you create in this session will be billed against this project.
12+
13+
## Terraforming!
14+
15+
Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command
16+
to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up
17+
the project name from the environment variable.
18+
19+
```bash
20+
export GOOGLE_CLOUD_PROJECT={{project-id}}
21+
```
22+
23+
After that, let's get Terraform started. Run the following to pull in the providers.
24+
25+
```bash
26+
terraform init
27+
```
28+
29+
With the providers downloaded and a project set, you're ready to use Terraform. Go ahead!
30+
31+
```bash
32+
terraform apply
33+
```
34+
35+
Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan.
36+
37+
```bash
38+
yes
39+
```
40+
41+
42+
## Post-Apply
43+
44+
### Editing your config
45+
46+
Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed.
47+
48+
```bash
49+
terraform plan
50+
```
51+
52+
So let's make a change! Try editing a number, or appending a value to the name in the editor. Then,
53+
run a 'plan' again.
54+
55+
```bash
56+
terraform plan
57+
```
58+
59+
Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes
60+
at the 'yes' prompt.
61+
62+
```bash
63+
terraform apply
64+
```
65+
66+
```bash
67+
yes
68+
```
69+
70+
## Cleanup
71+
72+
Run the following to remove the resources Terraform provisioned:
73+
74+
```bash
75+
terraform destroy
76+
```
77+
```bash
78+
yes
79+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This file has some scaffolding to make sure that names are unique and that
2+
# a region and zone are selected when you try to create your Terraform resources.
3+
4+
locals {
5+
name_suffix = "${random_pet.suffix.id}"
6+
}
7+
8+
resource "random_pet" "suffix" {
9+
length = 2
10+
}
11+
12+
provider "google" {
13+
region = "us-central1"
14+
zone = "us-central1-c"
15+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
data "google_project" "project" {
2+
}
3+
4+
resource "google_network_management_vpc_flow_logs_config" "vpn-test" {
5+
vpc_flow_logs_config_id = "basic-test-id-${local.name_suffix}"
6+
location = "global"
7+
vpn_tunnel = "projects/${data.google_project.project.number}/regions/us-central1/vpnTunnels/${google_compute_vpn_tunnel.tunnel.name}"
8+
}
9+
10+
resource "google_compute_vpn_tunnel" "tunnel" {
11+
name = "basic-test-tunnel-${local.name_suffix}"
12+
peer_ip = "15.0.0.120"
13+
shared_secret = "a secret message"
14+
target_vpn_gateway = google_compute_vpn_gateway.target_gateway.id
15+
16+
depends_on = [
17+
google_compute_forwarding_rule.fr_esp,
18+
google_compute_forwarding_rule.fr_udp500,
19+
google_compute_forwarding_rule.fr_udp4500,
20+
]
21+
}
22+
23+
resource "google_compute_vpn_gateway" "target_gateway" {
24+
name = "basic-test-gateway-${local.name_suffix}"
25+
network = google_compute_network.network.id
26+
}
27+
28+
resource "google_compute_network" "network" {
29+
name = "basic-test-network-${local.name_suffix}"
30+
}
31+
32+
resource "google_compute_address" "vpn_static_ip" {
33+
name = "basic-test-address-${local.name_suffix}"
34+
}
35+
36+
resource "google_compute_forwarding_rule" "fr_esp" {
37+
name = "basic-test-fresp-${local.name_suffix}"
38+
ip_protocol = "ESP"
39+
ip_address = google_compute_address.vpn_static_ip.address
40+
target = google_compute_vpn_gateway.target_gateway.id
41+
}
42+
43+
resource "google_compute_forwarding_rule" "fr_udp500" {
44+
name = "basic-test-fr500-${local.name_suffix}"
45+
ip_protocol = "UDP"
46+
port_range = "500"
47+
ip_address = google_compute_address.vpn_static_ip.address
48+
target = google_compute_vpn_gateway.target_gateway.id
49+
}
50+
51+
resource "google_compute_forwarding_rule" "fr_udp4500" {
52+
name = "basic-test-fr4500-${local.name_suffix}"
53+
ip_protocol = "UDP"
54+
port_range = "4500"
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_route" "route" {
60+
name = "basic-test-route-${local.name_suffix}"
61+
network = google_compute_network.network.name
62+
dest_range = "15.0.0.0/24"
63+
priority = 1000
64+
next_hop_vpn_tunnel = google_compute_vpn_tunnel.tunnel.id
65+
}

0 commit comments

Comments
 (0)