-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
95daff5
commit fdbe6fe
Showing
5 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Simple shared VPC Project | ||
|
||
This example: | ||
|
||
* Enables shared VPC on a host project | ||
* Attaches a service project | ||
* Reserves an internal IP address in a subnet of a Shared VPC network | ||
* Creates a VM instance | ||
|
||
The IP address configuration object is created in the service | ||
project. Its value can come from the range of available addresses in | ||
the chosen shared subnet, or you can specify an address. | ||
|
||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| project | The Google Cloud project ID | `any` | n/a | yes | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| forwarding\_rule | Name of the forwarding rule | | ||
| ip\_address | The internal IP address | | ||
| ip\_address\_name | The name of the internal IP address | | ||
| network | Name of the VPC network | | ||
| project | Google Cloud project ID | | ||
| subnet\_ip\_range | Subnet IP range | | ||
| subnetwork | Name of the subnetwork | | ||
|
||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* Copyright 2019 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
|
||
# [START vpc_subnet_private_access] | ||
resource "google_compute_network" "network" { | ||
provider = google-beta | ||
project = var.project # Replace this with your project ID in quotes | ||
name = "tf-test" | ||
auto_create_subnetworks = false | ||
} | ||
|
||
resource "google_compute_subnetwork" "vpc_subnetwork" { | ||
provider = google-beta | ||
project = google_compute_network.network.project | ||
name = "test-subnetwork" | ||
ip_cidr_range = "10.2.0.0/16" | ||
region = "us-central1" | ||
network = google_compute_network.network.id | ||
private_ip_google_access = true | ||
} | ||
# [END vpc_subnet_private_access] | ||
|
||
# [START compute_internal_ip_private_access] | ||
resource "google_compute_global_address" "default" { | ||
provider = google-beta | ||
project = google_compute_network.network.project | ||
name = "global-psconnect-ip" | ||
address_type = "INTERNAL" | ||
purpose = "PRIVATE_SERVICE_CONNECT" | ||
network = google_compute_network.network.id | ||
address = "10.3.0.5" | ||
} | ||
# [END compute_internal_ip_private_access] | ||
|
||
# [START compute_forwarding_rule_private_access] | ||
resource "google_compute_global_forwarding_rule" "default" { | ||
provider = google-beta | ||
project = google_compute_network.network.project | ||
name = "globalrule" | ||
target = "all-apis" | ||
network = google_compute_network.network.id | ||
ip_address = google_compute_global_address.default.id | ||
load_balancing_scheme = "" | ||
} | ||
# [START compute_forwarding_rule_private_access] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Copyright 2019 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
|
||
output "project" { | ||
value = google_compute_network.network.project | ||
description = "Google Cloud project ID" | ||
} | ||
|
||
output "network" { | ||
value = google_compute_network.network.name | ||
description = "Name of the VPC network" | ||
} | ||
|
||
output "subnetwork" { | ||
value = google_compute_subnetwork.vpc_subnetwork.name | ||
description = "Name of the subnetwork" | ||
} | ||
|
||
output "subnet_ip_range" { | ||
value = google_compute_subnetwork.vpc_subnetwork.ip_cidr_range | ||
description = "Subnet IP range" | ||
} | ||
|
||
output "ip_address_name" { | ||
value = google_compute_global_address.default.name | ||
description = "The name of the internal IP address" | ||
} | ||
|
||
output "ip_address" { | ||
value = google_compute_global_address.default.address | ||
description = "The internal IP address" | ||
} | ||
|
||
output "forwarding_rule" { | ||
value = google_compute_global_forwarding_rule.default.name | ||
description = "Name of the forwarding rule" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Copyright 2019 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
variable "project" { | ||
description = "The Google Cloud project ID" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Copyright 2019 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
terraform { | ||
required_version = ">=0.12.6" | ||
} |