Skip to content

Commit fdbe6fe

Browse files
chore: Added example for private service connect for google APIs (#294)
* Added example for private service connect for google APIs * fixed region tag * Removed unused provider info and blank lines
1 parent 95daff5 commit fdbe6fe

File tree

5 files changed

+182
-0
lines changed

5 files changed

+182
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Simple shared VPC Project
2+
3+
This example:
4+
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+
* Creates a VM instance
9+
10+
The IP address configuration object is created in the service
11+
project. Its value can come from the range of available addresses in
12+
the chosen shared subnet, or you can specify an address.
13+
14+
15+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
16+
## Inputs
17+
18+
| Name | Description | Type | Default | Required |
19+
|------|-------------|------|---------|:--------:|
20+
| project | The Google Cloud project ID | `any` | n/a | yes |
21+
22+
## Outputs
23+
24+
| Name | Description |
25+
|------|-------------|
26+
| forwarding\_rule | Name of the forwarding rule |
27+
| ip\_address | The internal IP address |
28+
| ip\_address\_name | The name of the internal IP address |
29+
| network | Name of the VPC network |
30+
| project | Google Cloud project ID |
31+
| subnet\_ip\_range | Subnet IP range |
32+
| subnetwork | Name of the subnetwork |
33+
34+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
# [START vpc_subnet_private_access]
19+
resource "google_compute_network" "network" {
20+
provider = google-beta
21+
project = var.project # Replace this with your project ID in quotes
22+
name = "tf-test"
23+
auto_create_subnetworks = false
24+
}
25+
26+
resource "google_compute_subnetwork" "vpc_subnetwork" {
27+
provider = google-beta
28+
project = google_compute_network.network.project
29+
name = "test-subnetwork"
30+
ip_cidr_range = "10.2.0.0/16"
31+
region = "us-central1"
32+
network = google_compute_network.network.id
33+
private_ip_google_access = true
34+
}
35+
# [END vpc_subnet_private_access]
36+
37+
# [START compute_internal_ip_private_access]
38+
resource "google_compute_global_address" "default" {
39+
provider = google-beta
40+
project = google_compute_network.network.project
41+
name = "global-psconnect-ip"
42+
address_type = "INTERNAL"
43+
purpose = "PRIVATE_SERVICE_CONNECT"
44+
network = google_compute_network.network.id
45+
address = "10.3.0.5"
46+
}
47+
# [END compute_internal_ip_private_access]
48+
49+
# [START compute_forwarding_rule_private_access]
50+
resource "google_compute_global_forwarding_rule" "default" {
51+
provider = google-beta
52+
project = google_compute_network.network.project
53+
name = "globalrule"
54+
target = "all-apis"
55+
network = google_compute_network.network.id
56+
ip_address = google_compute_global_address.default.id
57+
load_balancing_scheme = ""
58+
}
59+
# [START compute_forwarding_rule_private_access]
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
output "project" {
19+
value = google_compute_network.network.project
20+
description = "Google Cloud project ID"
21+
}
22+
23+
output "network" {
24+
value = google_compute_network.network.name
25+
description = "Name of the VPC network"
26+
}
27+
28+
output "subnetwork" {
29+
value = google_compute_subnetwork.vpc_subnetwork.name
30+
description = "Name of the subnetwork"
31+
}
32+
33+
output "subnet_ip_range" {
34+
value = google_compute_subnetwork.vpc_subnetwork.ip_cidr_range
35+
description = "Subnet IP range"
36+
}
37+
38+
output "ip_address_name" {
39+
value = google_compute_global_address.default.name
40+
description = "The name of the internal IP address"
41+
}
42+
43+
output "ip_address" {
44+
value = google_compute_global_address.default.address
45+
description = "The internal IP address"
46+
}
47+
48+
output "forwarding_rule" {
49+
value = google_compute_global_forwarding_rule.default.name
50+
description = "Name of the forwarding rule"
51+
}
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" {
18+
description = "The Google Cloud project ID"
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)