Skip to content

Commit 3f720fa

Browse files
authored
feat: Adding vpc-serverless-connector-submodule-beta (#280)
* updated rules in readme example to resolve issue #252 * Adding vpc-serverless-connector-beta submodule with integration tests * removing comment * updateing docs via make generate_docs * Adding int tests, changing serverless submodule to list of maps, updated int tests * Adding support for ip_cidr_range & network, modifying int test fixtures * Adding serverless api for setup on integration tests * Adding itegration test iam permissions and improving ip_cidr_range example * removing accidental comment * Adding project_id as output, updating docs
1 parent fdbe6fe commit 3f720fa

File tree

21 files changed

+527
-2
lines changed

21 files changed

+527
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Session.vim
2323

2424
# Local .terraform directories
2525
**/.terraform/*
26+
.terraform.lock.hcl
2627

2728
# .tfstate files
2829
*.tfstate

.kitchen.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019 Google LLC
1+
# Copyright 2021 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -159,3 +159,23 @@ suites:
159159
backend: local
160160
controls:
161161
- gcloud
162+
- name: "submodule_vpc_serverless_connector_beta"
163+
driver:
164+
name: "terraform"
165+
command_timeout: 1800
166+
root_module_directory: test/fixtures/submodule_vpc_serverless_connector_beta/
167+
verifier:
168+
name: terraform
169+
color: true
170+
systems:
171+
- name: inspec-gcp
172+
attrs_outputs:
173+
customized_inspec_attribute: output_connector_ids
174+
backend: gcp
175+
controls:
176+
- gcp
177+
- inspec_attributes
178+
- name: local
179+
backend: local
180+
controls:
181+
- gcloud

build/int.cloudbuild.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,26 @@ steps:
161161
- verify submodule-network-peering-local
162162
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
163163
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy submodule-network-peering-local']
164+
- id: create submodule-vpc-serverless-connector-beta
165+
waitFor:
166+
- prepare
167+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
168+
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do create submodule-vpc-serverless-connector-beta']
169+
- id: converge submodule-vpc-serverless-connector-beta
170+
waitFor:
171+
- create submodule-vpc-serverless-connector-beta
172+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
173+
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do converge submodule-vpc-serverless-connector-beta']
174+
- id: verify submodule-vpc-serverless-connector-beta
175+
waitFor:
176+
- converge submodule-vpc-serverless-connector-beta
177+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
178+
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do verify submodule-vpc-serverless-connector-beta']
179+
- id: destroy submodule-vpc-serverless-connector-beta
180+
waitFor:
181+
- verify submodule-vpc-serverless-connector-beta
182+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
183+
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy submodule-vpc-serverless-connector-beta']
164184
tags:
165185
- 'ci'
166186
- 'integration'
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# VPC Serverless Connector Beta
2+
3+
This example deploys a single vpc serverless connector in the us-central1 region.
4+
5+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
6+
## Inputs
7+
8+
| Name | Description | Type | Default | Required |
9+
|------|-------------|------|---------|:--------:|
10+
| project\_id | Project in which the vpc connector will be deployed. | `string` | n/a | yes |
11+
12+
## Outputs
13+
14+
| Name | Description |
15+
|------|-------------|
16+
| connector\_ids | ID of the vpc serverless connector that was deployed. |
17+
| project\_id | The ID of the project being used |
18+
19+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
provider "google" {
18+
version = "~> 3.62"
19+
}
20+
21+
provider "google-beta" {
22+
version = "~> 3.62"
23+
}
24+
25+
module "test-vpc-module" {
26+
source = "terraform-google-modules/network/google"
27+
version = "~> 3.2.0"
28+
project_id = var.project_id # Replace this with your project ID in quotes
29+
network_name = "my-serverless-network"
30+
mtu = 1460
31+
32+
subnets = [
33+
{
34+
subnet_name = "serverless-subnet"
35+
subnet_ip = "10.10.10.0/28"
36+
subnet_region = "us-central1"
37+
}
38+
]
39+
}
40+
41+
module "serverless-connector" {
42+
source = "../../modules/vpc-serverless-connector-beta"
43+
project_id = var.project_id
44+
vpc_connectors = [{
45+
name = "central-serverless"
46+
region = "us-central1"
47+
subnet_name = module.test-vpc-module.subnets["us-central1/serverless-subnet"].name
48+
# host_project_id = var.host_project_id # Leverage host_project_id if using a shared VPC
49+
machine_type = "e2-standard-4"
50+
min_instances = 2
51+
max_instances = 7
52+
}
53+
# Uncomment below to leverage ip_cidr_range
54+
# , {
55+
# name = "central-serverless2"
56+
# region = "us-central1"
57+
# network = module.test-vpc-module.network_name
58+
# ip_cidr_range = "10.10.11.0/28"
59+
# subnet_name = null
60+
# machine_type = "e2-standard-4"
61+
# min_instances = 2
62+
# max_instances = 7 }
63+
]
64+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
output "connector_ids" {
18+
value = module.serverless-connector.connector_ids
19+
description = "ID of the vpc serverless connector that was deployed."
20+
}
21+
22+
output "project_id" {
23+
value = var.project_id
24+
description = "The ID of the project being used"
25+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
variable "project_id" {
18+
type = string
19+
description = "Project in which the vpc connector will be deployed."
20+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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 = ">=0.13.0"
19+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Terraform VPC Serverless Connector Beta
2+
3+
This submodule is part of the the `terraform-google-network` module. It creates the vpc serverless connector using the beta components available.
4+
5+
It supports creating:
6+
7+
- serverless connector
8+
- serverless vpc access connector
9+
10+
## Usage
11+
12+
Basic usage of this submodule is as follows:
13+
14+
```hcl
15+
module "serverless-connector" {
16+
source = "terraform-google-modules/network/google//modules/vpc-serverless-connector-beta"
17+
project_id = <PROJECT ID>
18+
vpc_connectors = [{
19+
name = "central-serverless"
20+
region = "us-central1"
21+
subnet_name = "<SUBNET NAME>"
22+
host_project_id = "<HOST PROJECT ID>"
23+
machine_type = "e2-standard-4"
24+
min_instances = 2
25+
max_instances = 3
26+
}]
27+
}
28+
```
29+
30+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
31+
## Inputs
32+
33+
| Name | Description | Type | Default | Required |
34+
|------|-------------|------|---------|:--------:|
35+
| project\_id | Project in which the vpc connector will be deployed. | `string` | n/a | yes |
36+
| vpc\_connectors | List of VPC serverless connectors. | `list(map(string))` | `[]` | no |
37+
38+
## Outputs
39+
40+
| Name | Description |
41+
|------|-------------|
42+
| connector\_ids | VPC serverless connector ID. |
43+
44+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
# Pending new google-cloud-beta provider release Estimated Release 03/22
18+
# https://github.com/hashicorp/terraform-provider-google/issues/8475
19+
resource "google_vpc_access_connector" "connector_beta" {
20+
for_each = { for connector in var.vpc_connectors : connector.name => connector }
21+
provider = google-beta
22+
name = each.value.name
23+
project = var.project_id
24+
region = each.value.region
25+
ip_cidr_range = lookup(each.value, "ip_cidr_range", null)
26+
network = lookup(each.value, "network", null)
27+
dynamic "subnet" {
28+
for_each = each.value.subnet_name == null ? [] : [each.value]
29+
content {
30+
name = each.value.subnet_name
31+
project_id = lookup(each.value, "host_project_id", null)
32+
}
33+
}
34+
machine_type = lookup(each.value, "machine_type", null)
35+
min_instances = lookup(each.value, "min_instances", null)
36+
max_instances = lookup(each.value, "max_instances", null)
37+
}

0 commit comments

Comments
 (0)