Skip to content

Commit f5b753b

Browse files
chore: Added new example for a subnet with a secondary range (#292)
* Added new example for a subnet with a secondary range * Fixed project ID reference in output
1 parent 29fe0a3 commit f5b753b

File tree

5 files changed

+147
-0
lines changed

5 files changed

+147
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Subnet with secondary range
2+
3+
This example configures a VPC network and a subnet with a secondary range.
4+
5+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
6+
## Inputs
7+
8+
| Name | Description | Type | Default | Required |
9+
|------|-------------|------|---------|:--------:|
10+
| project\_id | The project ID to host the network in | `any` | n/a | yes |
11+
12+
## Outputs
13+
14+
| Name | Description |
15+
|------|-------------|
16+
| primary\_cidr | Primary CIDR range |
17+
| project\_id | Google Cloud project ID |
18+
| region | Google Cloud region |
19+
| secondary\_cidr | Secondary CIDR range |
20+
| secondary\_cidr\_name | Name of the secondary CIDR range |
21+
| subnetwork\_name | The name of the subnetwork |
22+
23+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Copyright 2019 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+
18+
terraform {
19+
required_providers {
20+
google = {
21+
version = ">= 3.45.0"
22+
}
23+
null = {
24+
version = ">= 2.1.0"
25+
}
26+
}
27+
}
28+
29+
# [START vpc_secondary_range_create]
30+
resource "google_compute_subnetwork" "network-with-private-secondary-ip-ranges" {
31+
project = var.project_id # Replace this with your project ID in quotes
32+
name = "test-subnetwork"
33+
ip_cidr_range = "10.2.0.0/16"
34+
region = "us-central1"
35+
network = "test-vpc-network"
36+
secondary_ip_range {
37+
range_name = "tf-test-secondary-range-update1"
38+
ip_cidr_range = "192.168.10.0/24"
39+
}
40+
}
41+
# [END vpc_secondary_range_create]
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Copyright 2019 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+
output "project_id" {
18+
value = google_compute_subnetwork.network-with-private-secondary-ip-ranges.project
19+
description = "Google Cloud project ID"
20+
}
21+
22+
output "region" {
23+
value = google_compute_subnetwork.network-with-private-secondary-ip-ranges.region
24+
description = "Google Cloud region"
25+
}
26+
27+
output "subnetwork_name" {
28+
value = google_compute_subnetwork.network-with-private-secondary-ip-ranges.name
29+
description = "The name of the subnetwork"
30+
}
31+
32+
output "primary_cidr" {
33+
value = google_compute_subnetwork.network-with-private-secondary-ip-ranges.ip_cidr_range
34+
description = "Primary CIDR range"
35+
}
36+
37+
output "secondary_cidr_name" {
38+
value = google_compute_subnetwork.network-with-private-secondary-ip-ranges.secondary_ip_range[0].range_name
39+
description = "Name of the secondary CIDR range"
40+
}
41+
42+
output "secondary_cidr" {
43+
value = google_compute_subnetwork.network-with-private-secondary-ip-ranges.secondary_ip_range[0].ip_cidr_range
44+
description = "Secondary CIDR range"
45+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright 2019 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+
variable "project_id" {
18+
description = "The project ID to host the network in"
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright 2019 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+
terraform {
18+
required_version = ">=0.12.6"
19+
}

0 commit comments

Comments
 (0)