Skip to content

Commit 56f5c7b

Browse files
chore: Added example for creating internal IP address in shared subnet (#279)
1 parent e08ac65 commit 56f5c7b

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

examples/basic_shared_vpc/README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
# Simple Project
1+
# Simple shared VPC Project
22

3-
This example enables shared VPC on a host project and attaches a service project.
3+
This example:
44

5-
# Custom mode network
5+
* Enables shared VPC on a host project
6+
* Attaches a service project
7+
* Reserves an internal IP address in a subnet of a Shared VPC network
8+
9+
Note that the IP address configuration object is created in the service
10+
project, while its value comes from the range of available addresses in
11+
the chosen shared subnet.
612

7-
This example configures a single simple custom mode VPC network inside of a project.
813

914
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
1015
## Inputs
@@ -18,7 +23,10 @@ This example configures a single simple custom mode VPC network inside of a proj
1823

1924
| Name | Description |
2025
|------|-------------|
26+
| ip\_address | The internal IP address |
27+
| ip\_address\_name | The name of the internal IP |
2128
| project | Host project ID |
2229
| service\_project | Service project ID |
30+
| subnet | Name of the host subnet |
2331

2432
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

examples/basic_shared_vpc/main.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,20 @@ resource "google_compute_shared_vpc_service_project" "service1" {
3636
}
3737
# [END vpc_shared_vpc_service_project_attach]
3838

39+
# [START compute_shared_internal_ip_create]
40+
data "google_compute_subnetwork" "subnet" {
41+
name = "my-subnet-123"
42+
project = var.project
43+
region = "us-central1"
44+
}
45+
46+
resource "google_compute_address" "internal" {
47+
project = var.service_project
48+
region = "us-central1"
49+
name = "int-ip"
50+
address_type = "INTERNAL"
51+
address = "10.0.0.1"
52+
subnetwork = data.google_compute_subnetwork.subnet.self_link
53+
}
54+
# [END compute_shared_internal_ip_create]
55+

examples/basic_shared_vpc/outputs.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,18 @@ output "service_project" {
2323
value = google_compute_shared_vpc_service_project.service1.service_project
2424
description = "Service project ID"
2525
}
26+
27+
output "ip_address_name" {
28+
value = google_compute_address.internal.name
29+
description = "The name of the internal IP"
30+
}
31+
32+
output "subnet" {
33+
value = google_compute_address.internal.subnetwork
34+
description = "Name of the host subnet"
35+
}
36+
37+
output "ip_address" {
38+
value = google_compute_address.internal.address
39+
description = "The internal IP address"
40+
}

examples/basic_shared_vpc/variables.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ variable "project" {
2121
variable "service_project" {
2222
description = "The service project ID"
2323
}
24+

0 commit comments

Comments
 (0)