Skip to content

Commit 4e3d3cc

Browse files
committed
Apigee southbound PSC
1 parent 8c6d256 commit 4e3d3cc

File tree

22 files changed

+498
-15
lines changed

22 files changed

+498
-15
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ Currently the following modules are a available and can be used either as part o
1212
* [Apigee X mTLS MIG](modules/apigee-x-mtls-mig) Configures a managed instance group of Envoy proxies that can be used to terminate mutual TLS and forward traffic to the internal Apigee X endpoint.
1313
* [L7 external LB for MIG](modules/mig-l7xlb) Configures an external HTTPS Cloud Load Balancer that fronts a managed instance groups.
1414
* [Routing Appliance](modules/routing-appliance) Configures a routing appliance and custom routes to overcome transitive peering problems.
15-
* [HTTPbin Development Backend](modules/httpbin-development-backend) Configures an example HTTP backend based on a locally hosted httpbin.org service and an internal load balancer.
15+
* [Southbound PSC Backend](modules/sb-psc-attachment) Private Service Connect (PSC) service attachment and Apigee endpoint attachment.
16+
* [Development Backend](modules/development-backend) Configures an example HTTP backend and an internal load balancer.
1617
* [NIP.io Development Hostname](modules/nip-development-hostname) Configures an external IP address and hostname based on the IP and the nip.io mechanism as well as a Google-managed SSL certificate.
1718

1819
## Deploying End-To-End Samples
@@ -27,6 +28,7 @@ Select one of the available sample deployments:
2728

2829
* [X Basic](samples/x-basic) for a basic Apigee X setup with the raw instance endpoints exposed as internal IP addresses.
2930
* [X with external L7 LB](samples/x-l7xlb) for an Apigee X setup that is exposed via a global external L7 load balancer.
31+
* [X with southbound PSC (Preview)](samples/x-sb-psc) for an Apigee X setup that uses Private Service Connect (PSC) to connect to a backend service in another VPC.
3032
* [X with internal L4 LB and mTLS](samples/x-ilb-mtls) for a basic Apigee X setup plus exposure via regional L4 load balancer and envoy proxy to terminate mTLS.
3133
* [X with network appliance for transitive peering](samples/x-transitive-peering) for an Apigee X organization that is peered to a network is transitively peered to another VPC that contains the backend.
3234
To deploy the sample, first create a copy of the example variables and edit according to your requirements.

modules/apigee-x-core/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,8 @@ output "instance_endpoints" {
2020
for name, instance in module.apigee-x-instance : name => instance.endpoint
2121
})
2222
}
23+
24+
output "org_id" {
25+
description = "Apigee Organization ID"
26+
value = module.apigee.org_id
27+
}

modules/httpbin-development-backend/main.tf renamed to modules/development-backend/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ module "demo-backend-template" {
2424
network_interfaces = [{
2525
network = var.network,
2626
subnetwork = var.subnet
27-
nat = true
27+
nat = false
2828
addresses = null
2929
alias_ips = null
3030
}]
3131
boot_disk = {
32-
image = "projects/cos-cloud/global/images/family/cos-stable"
32+
image = "projects/debian-cloud/global/images/family/debian-10"
3333
type = "pd-standard"
3434
size = 10
3535
}
3636
create_template = true
3737
metadata = {
38-
startup-script = "docker run -p 80:80 kennethreitz/httpbin"
38+
startup-script = "sudo mkdir -p /var/www && cd /var/www && echo 'hello from demo' > index.html && python3 -m http.server 80"
3939
}
4040
service_account_create = true
4141
service_account_scopes = ["cloud-platform"]

modules/httpbin-development-backend/outputs.tf renamed to modules/development-backend/outputs.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ output "instance_group" {
1919
value = module.demo-backend-mig.group_manager.instance_group
2020
}
2121

22-
output "ilb_ip" {
22+
output "ilb_forwarding_rule_address" {
2323
description = "ILB forwarding rule IP address."
2424
value = module.ilb-backend.forwarding_rule_address
2525
}
26+
27+
output "ilb_forwarding_rule_self_link" {
28+
description = "ILB forwarding rule self link."
29+
value = module.ilb-backend.forwarding_rule_self_link
30+
}

modules/sb-psc-attachment/main.tf

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Copyright 2022 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+
resource "google_compute_service_attachment" "psc_service_attachment" {
18+
name = var.name
19+
region = var.region
20+
project = var.project_id
21+
description = "A service attachment to be used by Apigee"
22+
23+
enable_proxy_protocol = true
24+
connection_preference = "ACCEPT_AUTOMATIC"
25+
nat_subnets = var.nat_subnets
26+
target_service = var.target_service
27+
}
28+
29+
resource "google_apigee_endpoint_attachment" "endpoint_attachment" {
30+
org_id = var.apigee_organization
31+
endpoint_attachment_id = var.name
32+
location = var.region
33+
service_attachment = google_compute_service_attachment.psc_service_attachment.id
34+
}

modules/sb-psc-attachment/outputs.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Copyright 2022 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 "endpoint_attachment_host" {
18+
description = "Host for the endpoint attachment to be used in Apigee."
19+
value = google_apigee_endpoint_attachment.endpoint_attachment.host
20+
}
21+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Copyright 2022 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 = "Project id."
19+
type = string
20+
}
21+
22+
variable "region" {
23+
description = "GCP region where the service attachment should be created."
24+
type = string
25+
}
26+
27+
variable "name" {
28+
description = "Name for the service attachment."
29+
type = string
30+
}
31+
32+
variable "nat_subnets" {
33+
description = "One or more NAT subnets to be used for PSC."
34+
type = list(string)
35+
}
36+
37+
variable "target_service" {
38+
description = "Target Service for the service attachment e.g. a forwarding rule."
39+
type = string
40+
}
41+
42+
variable "apigee_organization" {
43+
description = "Apigee organization where the Endpoint Attachment should be added to."
44+
type = string
45+
}

modules/sb-psc-attachment/versions.tf

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Copyright 2021 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 = ">= 1.0.0"
19+
required_providers {
20+
google = {
21+
source = "hashicorp/google"
22+
version = ">= 4.0.0"
23+
}
24+
google-beta = {
25+
source = "hashicorp/google-beta"
26+
version = ">= 4.0.0"
27+
}
28+
}
29+
}

samples/x-dns-peering/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ with the Apigee X service network.
77
The private DNS Zone for the `internal.` domain contains the following
88
A records:
99

10-
* **httpbin.internal** pointing at the ILB of the demo backend
10+
* **demo.internal** pointing at the ILB of the demo backend
1111
* **${ENV_GROUP_NAME}-api.internal** pointing at all Apigee instance endpoints
1212

1313
## Setup Instructions
@@ -27,7 +27,7 @@ for detailed instructions.
2727
| Name | Source | Version |
2828
|------|--------|---------|
2929
| <a name="module_apigee-x-core"></a> [apigee-x-core](#module\_apigee-x-core) | ../../modules/apigee-x-core | n/a |
30-
| <a name="module_backend-example"></a> [backend-example](#module\_backend-example) | ../../modules/httpbin-development-backend | n/a |
30+
| <a name="module_backend-example"></a> [backend-example](#module\_backend-example) | ../../modules/development-backend | n/a |
3131
| <a name="module_private-dns"></a> [private-dns](#module\_private-dns) | github.com/terraform-google-modules/cloud-foundation-fabric//modules/dns | v14.0.0 |
3232
| <a name="module_project"></a> [project](#module\_project) | github.com/terraform-google-modules/cloud-foundation-fabric//modules/project | v14.0.0 |
3333
| <a name="module_vpc"></a> [vpc](#module\_vpc) | github.com/terraform-google-modules/cloud-foundation-fabric//modules/net-vpc | v14.0.0 |

samples/x-dns-peering/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ module "apigee-x-core" {
6767
}
6868

6969
module "backend-example" {
70-
source = "../../modules/httpbin-development-backend"
70+
source = "../../modules/development-backend"
7171
project_id = module.project.project_id
7272
name = var.backend.name
7373
network = module.vpc.self_link
@@ -83,7 +83,7 @@ module "private-dns" {
8383
domain = var.dns.domain
8484
client_networks = [module.vpc.self_link]
8585
recordsets = merge(
86-
{ "A ${var.backend.name}" = { type = "A", ttl = 300, records = [module.backend-example.ilb_ip] } },
86+
{ "A ${var.backend.name}" = { type = "A", ttl = 300, records = [module.backend-example.ilb_forwarding_rule_address] } },
8787
{ for eg_name in keys(var.apigee_envgroups) : "A ${eg_name}-api" => { type = "A", ttl = 300, records = values(module.apigee-x-core.instance_endpoints) } }
8888
)
8989
}

samples/x-dns-peering/x-demo.tfvars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ apigee_instances = {
3434
}
3535

3636
backend = {
37-
name = "httpbin"
37+
name = "demo"
3838
region = "europe-west1"
3939
subnet = "demo-backend"
4040
subnet_cidr = "10.100.0.0/24"

samples/x-sb-psc/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Basic Apigee X Setup wih internal backend reached through PSC
2+
3+
## Setup Instructions
4+
5+
Please see the main [README](https://github.com/apigee/terraform-modules#deploying-end-to-end-samples)
6+
for detailed instructions.
7+
8+
A successful run will print the endpoint attachment's host that you can then
9+
use for your target server in Apigee:
10+
11+
```txt
12+
Outputs:
13+
14+
psc_endpoint_attachment_host = "7.0.5.2"
15+
```
16+
17+
<!-- BEGIN_TF_DOCS -->
18+
## Providers
19+
20+
No providers.
21+
22+
## Modules
23+
24+
| Name | Source | Version |
25+
|------|--------|---------|
26+
| <a name="module_apigee-x-core"></a> [apigee-x-core](#module\_apigee-x-core) | ../../modules/apigee-x-core | n/a |
27+
| <a name="module_project"></a> [project](#module\_project) | github.com/terraform-google-modules/cloud-foundation-fabric//modules/project | v14.0.0 |
28+
| <a name="module_vpc"></a> [vpc](#module\_vpc) | github.com/terraform-google-modules/cloud-foundation-fabric//modules/net-vpc | v14.0.0 |
29+
30+
## Resources
31+
32+
No resources.
33+
34+
## Inputs
35+
36+
| Name | Description | Type | Default | Required |
37+
|------|-------------|------|---------|:--------:|
38+
| <a name="input_apigee_envgroups"></a> [apigee\_envgroups](#input\_apigee\_envgroups) | Apigee Environment Groups. | <pre>map(object({<br> environments = list(string)<br> hostnames = list(string)<br> }))</pre> | `{}` | no |
39+
| <a name="input_apigee_environments"></a> [apigee\_environments](#input\_apigee\_environments) | List of Apigee Environment Names. | `list(string)` | `[]` | no |
40+
| <a name="input_apigee_instances"></a> [apigee\_instances](#input\_apigee\_instances) | Apigee Instances (only one instance for EVAL orgs). | <pre>map(object({<br> region = string<br> ip_range = string<br> environments = list(string)<br> }))</pre> | `{}` | no |
41+
| <a name="input_ax_region"></a> [ax\_region](#input\_ax\_region) | GCP region for storing Apigee analytics data (see https://cloud.google.com/apigee/docs/api-platform/get-started/install-cli). | `string` | n/a | yes |
42+
| <a name="input_billing_account"></a> [billing\_account](#input\_billing\_account) | Billing account id. | `string` | `null` | no |
43+
| <a name="input_network"></a> [network](#input\_network) | Name of the VPC network to peer with the Apigee tennant project. | `string` | n/a | yes |
44+
| <a name="input_peering_range"></a> [peering\_range](#input\_peering\_range) | Service Peering CIDR range. | `string` | n/a | yes |
45+
| <a name="input_project_create"></a> [project\_create](#input\_project\_create) | Create project. When set to false, uses a data source to reference existing project. | `bool` | `false` | no |
46+
| <a name="input_project_id"></a> [project\_id](#input\_project\_id) | Project id (also used for the Apigee Organization). | `string` | n/a | yes |
47+
| <a name="input_project_parent"></a> [project\_parent](#input\_project\_parent) | Parent folder or organization in 'folders/folder\_id' or 'organizations/org\_id' format. | `string` | `null` | no |
48+
| <a name="input_support_range"></a> [support\_range](#input\_support\_range) | Support CIDR range of length /28 (required by Apigee for troubleshooting purposes). | `string` | n/a | yes |
49+
50+
## Outputs
51+
52+
No outputs.
53+
<!-- END_TF_DOCS -->

samples/x-sb-psc/main.tf

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/**
2+
* Copyright 2022 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+
module "project" {
18+
source = "github.com/terraform-google-modules/cloud-foundation-fabric//modules/project?ref=v14.0.0"
19+
name = var.project_id
20+
parent = var.project_parent
21+
billing_account = var.billing_account
22+
project_create = var.project_create
23+
services = [
24+
"apigee.googleapis.com",
25+
"cloudkms.googleapis.com",
26+
"compute.googleapis.com",
27+
"servicenetworking.googleapis.com"
28+
]
29+
}
30+
31+
module "vpc" {
32+
source = "github.com/terraform-google-modules/cloud-foundation-fabric//modules/net-vpc?ref=v14.0.0"
33+
project_id = module.project.project_id
34+
name = var.network
35+
subnets = []
36+
psa_ranges = {
37+
apigee-range = var.peering_range
38+
apigee-support-range = var.support_range
39+
}
40+
}
41+
42+
module "apigee-x-core" {
43+
source = "../../modules/apigee-x-core"
44+
project_id = module.project.project_id
45+
apigee_environments = var.apigee_environments
46+
ax_region = var.ax_region
47+
apigee_envgroups = var.apigee_envgroups
48+
network = module.vpc.network.id
49+
apigee_instances = var.apigee_instances
50+
}
51+
52+
module "backend-vpc" {
53+
source = "github.com/terraform-google-modules/cloud-foundation-fabric//modules/net-vpc?ref=v14.0.0"
54+
project_id = module.project.project_id
55+
name = var.backend_network
56+
subnets = [
57+
var.backend_subnet,
58+
]
59+
}
60+
61+
module "backend-example" {
62+
source = "../../modules/development-backend"
63+
project_id = module.project.project_id
64+
name = var.backend_name
65+
network = module.backend-vpc.network.id
66+
subnet = module.backend-vpc.subnet_self_links["${var.backend_subnet.region}/${var.backend_subnet.name}"]
67+
region = var.backend_region
68+
}
69+
70+
resource "google_compute_subnetwork" "psc_nat_subnet" {
71+
name = var.backend_psc_nat_subnet.name
72+
project = module.project.project_id
73+
region = var.backend_region
74+
network = module.backend-vpc.network.id
75+
ip_cidr_range = var.backend_psc_nat_subnet.ip_cidr_range
76+
purpose = "PRIVATE_SERVICE_CONNECT"
77+
}
78+
79+
80+
module "southbound-psc" {
81+
source = "../../modules/sb-psc-attachment"
82+
project_id = module.project.project_id
83+
name = var.psc_name
84+
region = var.backend_region
85+
apigee_organization = module.apigee-x-core.org_id
86+
nat_subnets = [google_compute_subnetwork.psc_nat_subnet.id]
87+
target_service = module.backend-example.ilb_forwarding_rule_self_link
88+
}

0 commit comments

Comments
 (0)