FAST plugin system (#1266)
* plugin folder, gitignore, serverless connector example * add support to fast plugin variables and outputs to tfdoc * rename folder, READMEs * add variable description * show diffs * check documentation, use multiple files * debug check doc * try a different glob * debug tfdoc names * more debug * and even more debug * fix gitignore * fix links * support extra files in tests * fix fixture, switch stage 2 peering to new tests * tfdoc * Allow globs in extra files --------- Co-authored-by: Julio Castillo <jccb@google.com>
This commit is contained in:
parent
176c5e05cd
commit
3d41d01efc
|
@ -56,7 +56,7 @@ jobs:
|
||||||
- name: Check documentation
|
- name: Check documentation
|
||||||
id: documentation-fabric
|
id: documentation-fabric
|
||||||
run: |
|
run: |
|
||||||
python3 tools/check_documentation.py modules fast blueprints
|
python3 tools/check_documentation.py --show-diffs modules fast blueprints
|
||||||
|
|
||||||
- name: Check documentation links
|
- name: Check documentation links
|
||||||
id: documentation-links-fabric
|
id: documentation-links-fabric
|
||||||
|
|
|
@ -23,7 +23,6 @@ Clone this repository or [open it in cloud shell](https://ssh.cloud.google.com/c
|
||||||
|
|
||||||
Once done testing, you can clean up resources by running `terraform destroy`.
|
Once done testing, you can clean up resources by running `terraform destroy`.
|
||||||
|
|
||||||
|
|
||||||
<!-- BEGIN TFDOC -->
|
<!-- BEGIN TFDOC -->
|
||||||
|
|
||||||
## Variables
|
## Variables
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
stages/[0-9]*/local-*.tf
|
||||||
|
stages-multitenant/[0-9]*/local-*.tf
|
|
@ -0,0 +1,40 @@
|
||||||
|
# VPC Serverless Connector
|
||||||
|
|
||||||
|
This FAST plugin adds centralized [Serverless VPC Access Connectors](https://cloud.google.com/vpc/docs/serverless-vpc-access) to network stages.
|
||||||
|
|
||||||
|
This plugin does not manage
|
||||||
|
|
||||||
|
- IAM bindings for the connectors, which should be added via the stage project-level variables
|
||||||
|
- firewall rules for the connectors, which should be added via the stage factory
|
||||||
|
|
||||||
|
The plugin only requires a specific configuration if the defaults it uses need to be changed:
|
||||||
|
|
||||||
|
- the connector-specific subnets default to the `10.255.255.0` range
|
||||||
|
- the machine type, number of instances and thoughput use the API defaults
|
||||||
|
|
||||||
|
To enable the plugin, simply copy or link its files in the networking stage.
|
||||||
|
|
||||||
|
<!-- TFDOC OPTS files:1 show_extra:1 -->
|
||||||
|
<!-- BEGIN TFDOC -->
|
||||||
|
|
||||||
|
## Files
|
||||||
|
|
||||||
|
| name | description | modules | resources |
|
||||||
|
|---|---|---|---|
|
||||||
|
| [local-serverless-connector-outputs.tf](./local-serverless-connector-outputs.tf) | Serverless Connector outputs. | | <code>google_storage_bucket_object</code> · <code>local_file</code> |
|
||||||
|
| [local-serverless-connector-variables.tf](./local-serverless-connector-variables.tf) | Serverless Connector variables. | | |
|
||||||
|
| [local-serverless-connector.tf](./local-serverless-connector.tf) | Serverless Connector resources. | <code>net-vpc</code> | <code>google_vpc_access_connector</code> |
|
||||||
|
|
||||||
|
## Variables
|
||||||
|
|
||||||
|
| name | description | type | required | default | producer |
|
||||||
|
|---|---|:---:|:---:|:---:|:---:|
|
||||||
|
| [serverless_connector_config](local-serverless-connector-variables.tf#L19) | VPC Access Serverless Connectors configuration. | <code title="object({ dev-primary = object({ ip_cidr_range = optional(string, "10.255.255.128/28") machine_type = optional(string) instances = optional(object({ max = optional(number) min = optional(number) }), {}) throughput = optional(object({ max = optional(number) min = optional(number) }), {}) }) prod-primary = object({ ip_cidr_range = optional(string, "10.255.255.0/28") machine_type = optional(string) instances = optional(object({ max = optional(number) min = optional(number) }), {}) throughput = optional(object({ max = optional(number) min = optional(number) }), {}) }) })">object({…})</code> | | <code title="{ dev-primary = {} prod-primary = {} }">{…}</code> | |
|
||||||
|
|
||||||
|
## Outputs
|
||||||
|
|
||||||
|
| name | description | sensitive | consumers |
|
||||||
|
|---|---|:---:|---|
|
||||||
|
| [plugin_sc_connectors](local-serverless-connector-outputs.tf#L43) | VPC Access Connectors. | | |
|
||||||
|
|
||||||
|
<!-- END TFDOC -->
|
|
@ -0,0 +1,46 @@
|
||||||
|
/**
|
||||||
|
* Copyright 2023 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
# tfdoc:file:description Serverless Connector outputs.
|
||||||
|
|
||||||
|
locals {
|
||||||
|
plugin_sc_tfvars = {
|
||||||
|
dev = google_vpc_access_connector.dev-primary.0.id
|
||||||
|
prod = google_vpc_access_connector.prod-primary.0.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# generate tfvars file for subsequent stages
|
||||||
|
|
||||||
|
resource "local_file" "plugin_sc_tfvars" {
|
||||||
|
for_each = var.outputs_location == null ? {} : { 1 = 1 }
|
||||||
|
file_permission = "0644"
|
||||||
|
filename = "${try(pathexpand(var.outputs_location), "")}/tfvars/2-networking-serverless-connnector.auto.tfvars.json"
|
||||||
|
content = jsonencode(local.plugin_sc_tfvars)
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "google_storage_bucket_object" "plugin_sc_tfvars" {
|
||||||
|
bucket = var.automation.outputs_bucket
|
||||||
|
name = "tfvars/2-networking-serverless-connnector.auto.tfvars.json"
|
||||||
|
content = jsonencode(local.plugin_sc_tfvars)
|
||||||
|
}
|
||||||
|
|
||||||
|
# outputs
|
||||||
|
|
||||||
|
output "plugin_sc_connectors" {
|
||||||
|
description = "VPC Access Connectors."
|
||||||
|
value = local.plugin_sc_tfvars
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
/**
|
||||||
|
* Copyright 2023 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
# tfdoc:file:description Serverless Connector variables.
|
||||||
|
|
||||||
|
variable "serverless_connector_config" {
|
||||||
|
description = "VPC Access Serverless Connectors configuration."
|
||||||
|
type = object({
|
||||||
|
dev-primary = object({
|
||||||
|
ip_cidr_range = optional(string, "10.255.255.128/28")
|
||||||
|
machine_type = optional(string)
|
||||||
|
instances = optional(object({
|
||||||
|
max = optional(number)
|
||||||
|
min = optional(number)
|
||||||
|
}), {})
|
||||||
|
throughput = optional(object({
|
||||||
|
max = optional(number)
|
||||||
|
min = optional(number)
|
||||||
|
}), {})
|
||||||
|
})
|
||||||
|
prod-primary = object({
|
||||||
|
ip_cidr_range = optional(string, "10.255.255.0/28")
|
||||||
|
machine_type = optional(string)
|
||||||
|
instances = optional(object({
|
||||||
|
max = optional(number)
|
||||||
|
min = optional(number)
|
||||||
|
}), {})
|
||||||
|
throughput = optional(object({
|
||||||
|
max = optional(number)
|
||||||
|
min = optional(number)
|
||||||
|
}), {})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
default = {
|
||||||
|
dev-primary = {}
|
||||||
|
prod-primary = {}
|
||||||
|
}
|
||||||
|
nullable = false
|
||||||
|
}
|
|
@ -0,0 +1,84 @@
|
||||||
|
/**
|
||||||
|
* Copyright 2023 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
# tfdoc:file:description Serverless Connector resources.
|
||||||
|
|
||||||
|
locals {
|
||||||
|
plugin_sc_subnets = {
|
||||||
|
dev = {
|
||||||
|
for k, v in module.dev-spoke-vpc-serverless.subnets : k => v.name
|
||||||
|
}
|
||||||
|
prod = {
|
||||||
|
for k, v in module.prod-spoke-vpc-serverless.subnets : k => v.name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module "dev-spoke-vpc-serverless" {
|
||||||
|
source = "../../../modules/net-vpc"
|
||||||
|
project_id = module.dev-spoke-project.project_id
|
||||||
|
name = module.dev-spoke-vpc.name
|
||||||
|
vpc_create = false
|
||||||
|
subnets = [{
|
||||||
|
name = "access-connector"
|
||||||
|
description = "VPC Serverless Connector for the primary region."
|
||||||
|
ip_cidr_range = var.serverless_connector_config.dev-primary.ip_cidr_range
|
||||||
|
region = var.regions.primary
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
|
||||||
|
module "prod-spoke-vpc-serverless" {
|
||||||
|
source = "../../../modules/net-vpc"
|
||||||
|
project_id = module.prod-spoke-project.project_id
|
||||||
|
name = module.prod-spoke-vpc.name
|
||||||
|
vpc_create = false
|
||||||
|
subnets = [{
|
||||||
|
name = "access-connector"
|
||||||
|
description = "VPC Serverless Connector for the primary region."
|
||||||
|
ip_cidr_range = var.serverless_connector_config.prod-primary.ip_cidr_range
|
||||||
|
region = var.regions.primary
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "google_vpc_access_connector" "dev-primary" {
|
||||||
|
count = var.serverless_connector_config.dev-primary == null ? 0 : 1
|
||||||
|
project = module.dev-spoke-project.project_id
|
||||||
|
region = var.regions.primary
|
||||||
|
name = "access-connector-${local.region_shortnames[var.regions.primary]}"
|
||||||
|
subnet {
|
||||||
|
name = local.plugin_sc_subnets.dev["${var.regions.primary}/access-connector"]
|
||||||
|
}
|
||||||
|
machine_type = var.serverless_connector_config.dev-primary.machine_type
|
||||||
|
max_instances = var.serverless_connector_config.dev-primary.instances.max
|
||||||
|
max_throughput = var.serverless_connector_config.dev-primary.throughput.max
|
||||||
|
min_instances = var.serverless_connector_config.dev-primary.instances.min
|
||||||
|
min_throughput = var.serverless_connector_config.dev-primary.throughput.min
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "google_vpc_access_connector" "prod-primary" {
|
||||||
|
count = var.serverless_connector_config.prod-primary == null ? 0 : 1
|
||||||
|
project = module.prod-spoke-project.project_id
|
||||||
|
region = var.regions.primary
|
||||||
|
name = "access-connector-${local.region_shortnames[var.regions.primary]}"
|
||||||
|
subnet {
|
||||||
|
name = local.plugin_sc_subnets.prod["${var.regions.primary}/access-connector"]
|
||||||
|
}
|
||||||
|
machine_type = var.serverless_connector_config.prod-primary.machine_type
|
||||||
|
max_instances = var.serverless_connector_config.prod-primary.instances.max
|
||||||
|
max_throughput = var.serverless_connector_config.prod-primary.throughput.max
|
||||||
|
min_instances = var.serverless_connector_config.prod-primary.instances.min
|
||||||
|
min_throughput = var.serverless_connector_config.prod-primary.throughput.min
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
# FAST plugin system
|
||||||
|
|
||||||
|
This folders details a simple mechanism that can be used to add extra functionality to FAST stages, and a few examples that implement simple plugins that can be used as-is.
|
||||||
|
|
||||||
|
## Available plugins
|
||||||
|
|
||||||
|
### Networking
|
||||||
|
|
||||||
|
- [Serverless VPC Access Connector](./2-networking-serverless-connector/)
|
||||||
|
|
||||||
|
## Anatomy of a plugin
|
||||||
|
|
||||||
|
FAST plugins are much simpler and easier to code than full-blown stages: each plugin is meant to add a single feature using a small set of resources, and interacting directly with stage modules and variables.
|
||||||
|
|
||||||
|
A simple plugin might be composed of a single file with one resource, and grow up to the canonical set of one "main" (resources), one variables, and outputs file.
|
||||||
|
|
||||||
|
Plugin file names start with the `local-` prefix which is purposefully excluded in FAST stages via Git ignore, so that plugins are not accidentally committed to stages during development and staying aligned with our master branch is possible.
|
||||||
|
|
||||||
|
Plugins are structured here as individual folders, organized in top-level folders according to the FAST stage they are designed to work with.
|
||||||
|
|
||||||
|
As an example, the [`2-networking/serverless-connector` plugin](./2-networking-serverless-connector/) implements centralized [Serverless VPC Access Connectors](https://cloud.google.com/vpc/docs/serverless-vpc-access) for our networking stages, and is composed of three files:
|
||||||
|
|
||||||
|
- [`local-serverless-connector.tf`](./2-networking-serverless-connector/local-serverless-connector.tf) managing resources including the subnets needed in each VPC and the connectors themselves
|
||||||
|
- [`local-serverless-connector-outputs.tf`](./2-networking-serverless-connector/local-serverless-connector-outputs.tf) defining a single `serverless_connectors` output for the plugin, and optional output files
|
||||||
|
- [`local-serverless-connector-variables.tf`](./2-networking-serverless-connector/local-serverless-connector-variables.tf) defining a single `serverless_connector_config` variable used to configure the plugin
|
|
@ -30,6 +30,7 @@ module "dev-spoke-project" {
|
||||||
"networkmanagement.googleapis.com",
|
"networkmanagement.googleapis.com",
|
||||||
"servicenetworking.googleapis.com",
|
"servicenetworking.googleapis.com",
|
||||||
"stackdriver.googleapis.com",
|
"stackdriver.googleapis.com",
|
||||||
|
"vpcaccess.googleapis.com"
|
||||||
]
|
]
|
||||||
shared_vpc_host_config = {
|
shared_vpc_host_config = {
|
||||||
enabled = true
|
enabled = true
|
||||||
|
|
|
@ -30,6 +30,7 @@ module "prod-spoke-project" {
|
||||||
"networkmanagement.googleapis.com",
|
"networkmanagement.googleapis.com",
|
||||||
"servicenetworking.googleapis.com",
|
"servicenetworking.googleapis.com",
|
||||||
"stackdriver.googleapis.com",
|
"stackdriver.googleapis.com",
|
||||||
|
"vpcaccess.googleapis.com"
|
||||||
]
|
]
|
||||||
shared_vpc_host_config = {
|
shared_vpc_host_config = {
|
||||||
enabled = true
|
enabled = true
|
||||||
|
|
|
@ -30,6 +30,7 @@ module "dev-spoke-project" {
|
||||||
"networkmanagement.googleapis.com",
|
"networkmanagement.googleapis.com",
|
||||||
"servicenetworking.googleapis.com",
|
"servicenetworking.googleapis.com",
|
||||||
"stackdriver.googleapis.com",
|
"stackdriver.googleapis.com",
|
||||||
|
"vpcaccess.googleapis.com"
|
||||||
]
|
]
|
||||||
shared_vpc_host_config = {
|
shared_vpc_host_config = {
|
||||||
enabled = true
|
enabled = true
|
||||||
|
|
|
@ -30,6 +30,7 @@ module "prod-spoke-project" {
|
||||||
"networkmanagement.googleapis.com",
|
"networkmanagement.googleapis.com",
|
||||||
"servicenetworking.googleapis.com",
|
"servicenetworking.googleapis.com",
|
||||||
"stackdriver.googleapis.com",
|
"stackdriver.googleapis.com",
|
||||||
|
"vpcaccess.googleapis.com"
|
||||||
]
|
]
|
||||||
shared_vpc_host_config = {
|
shared_vpc_host_config = {
|
||||||
enabled = true
|
enabled = true
|
||||||
|
|
|
@ -29,6 +29,7 @@ module "dev-spoke-project" {
|
||||||
"networkmanagement.googleapis.com",
|
"networkmanagement.googleapis.com",
|
||||||
"servicenetworking.googleapis.com",
|
"servicenetworking.googleapis.com",
|
||||||
"stackdriver.googleapis.com",
|
"stackdriver.googleapis.com",
|
||||||
|
"vpcaccess.googleapis.com"
|
||||||
]
|
]
|
||||||
shared_vpc_host_config = {
|
shared_vpc_host_config = {
|
||||||
enabled = true
|
enabled = true
|
||||||
|
|
|
@ -29,6 +29,7 @@ module "prod-spoke-project" {
|
||||||
"networkmanagement.googleapis.com",
|
"networkmanagement.googleapis.com",
|
||||||
"servicenetworking.googleapis.com",
|
"servicenetworking.googleapis.com",
|
||||||
"stackdriver.googleapis.com",
|
"stackdriver.googleapis.com",
|
||||||
|
"vpcaccess.googleapis.com"
|
||||||
]
|
]
|
||||||
shared_vpc_host_config = {
|
shared_vpc_host_config = {
|
||||||
enabled = true
|
enabled = true
|
||||||
|
|
|
@ -30,6 +30,7 @@ module "dev-spoke-project" {
|
||||||
"networkmanagement.googleapis.com",
|
"networkmanagement.googleapis.com",
|
||||||
"servicenetworking.googleapis.com",
|
"servicenetworking.googleapis.com",
|
||||||
"stackdriver.googleapis.com",
|
"stackdriver.googleapis.com",
|
||||||
|
"vpcaccess.googleapis.com"
|
||||||
]
|
]
|
||||||
shared_vpc_host_config = {
|
shared_vpc_host_config = {
|
||||||
enabled = true
|
enabled = true
|
||||||
|
|
|
@ -30,6 +30,7 @@ module "prod-spoke-project" {
|
||||||
"networkmanagement.googleapis.com",
|
"networkmanagement.googleapis.com",
|
||||||
"servicenetworking.googleapis.com",
|
"servicenetworking.googleapis.com",
|
||||||
"stackdriver.googleapis.com",
|
"stackdriver.googleapis.com",
|
||||||
|
"vpcaccess.googleapis.com"
|
||||||
]
|
]
|
||||||
shared_vpc_host_config = {
|
shared_vpc_host_config = {
|
||||||
enabled = true
|
enabled = true
|
||||||
|
|
|
@ -37,6 +37,9 @@ class FabricTestFile(pytest.File):
|
||||||
have the following structure:
|
have the following structure:
|
||||||
|
|
||||||
test-name:
|
test-name:
|
||||||
|
extra_files:
|
||||||
|
- bar.tf
|
||||||
|
- foo.tf
|
||||||
tfvars:
|
tfvars:
|
||||||
- tfvars1.tfvars
|
- tfvars1.tfvars
|
||||||
- tfvars2.tfvars
|
- tfvars2.tfvars
|
||||||
|
@ -60,27 +63,32 @@ class FabricTestFile(pytest.File):
|
||||||
common = raw.pop('common_tfvars', [])
|
common = raw.pop('common_tfvars', [])
|
||||||
for test_name, spec in raw.get('tests', {}).items():
|
for test_name, spec in raw.get('tests', {}).items():
|
||||||
spec = {} if spec is None else spec
|
spec = {} if spec is None else spec
|
||||||
|
extra_files = spec.get('extra_files')
|
||||||
inventories = spec.get('inventory', [f'{test_name}.yaml'])
|
inventories = spec.get('inventory', [f'{test_name}.yaml'])
|
||||||
tfvars = common + [f'{test_name}.tfvars'] + spec.get('tfvars', [])
|
tf_var_files = common + [f'{test_name}.tfvars'] + spec.get('tfvars', [])
|
||||||
for i in inventories:
|
for i in inventories:
|
||||||
name = test_name
|
name = test_name
|
||||||
if isinstance(inventories, list) and len(inventories) > 1:
|
if isinstance(inventories, list) and len(inventories) > 1:
|
||||||
name = f'{test_name}[{i}]'
|
name = f'{test_name}[{i}]'
|
||||||
yield FabricTestItem.from_parent(self, name=name, module=module,
|
yield FabricTestItem.from_parent(self, name=name, module=module,
|
||||||
inventory=[i], tfvars=tfvars)
|
inventory=[i],
|
||||||
|
tf_var_files=tf_var_files,
|
||||||
|
extra_files=extra_files)
|
||||||
|
|
||||||
|
|
||||||
class FabricTestItem(pytest.Item):
|
class FabricTestItem(pytest.Item):
|
||||||
|
|
||||||
def __init__(self, name, parent, module, inventory, tfvars):
|
def __init__(self, name, parent, module, inventory, tf_var_files,
|
||||||
|
extra_files=None):
|
||||||
super().__init__(name, parent)
|
super().__init__(name, parent)
|
||||||
self.module = module
|
self.module = module
|
||||||
self.inventory = inventory
|
self.inventory = inventory
|
||||||
self.tfvars = tfvars
|
self.tf_var_files = tf_var_files
|
||||||
|
self.extra_files = extra_files
|
||||||
|
|
||||||
def runtest(self):
|
def runtest(self):
|
||||||
s = plan_validator(self.module, self.inventory, self.parent.path.parent,
|
s = plan_validator(self.module, self.inventory, self.parent.path.parent,
|
||||||
self.tfvars)
|
self.tf_var_files, self.extra_files)
|
||||||
|
|
||||||
def reportinfo(self):
|
def reportinfo(self):
|
||||||
return self.path, None, self.name
|
return self.path, None, self.name
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
data_dir = "../../../fast/stages/2-networking-a-peering/data/"
|
|
||||||
automation = {
|
automation = {
|
||||||
outputs_bucket = "test"
|
outputs_bucket = "test"
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,3 +11,7 @@
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
counts:
|
||||||
|
modules: 31
|
||||||
|
resources: 122
|
|
@ -14,27 +14,14 @@
|
||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from deepdiff import DeepDiff
|
from deepdiff import DeepDiff
|
||||||
|
from pathlib import Path
|
||||||
BASEDIR = Path(__file__).parent
|
|
||||||
FIXTURE_PEERING = BASEDIR / 'fixture'
|
|
||||||
FIXTURE_VPN = BASEDIR.parent / 's2_networking_b_vpn/fixture'
|
|
||||||
|
|
||||||
STAGES = Path(__file__).parents[4] / 'fast/stages'
|
STAGES = Path(__file__).parents[4] / 'fast/stages'
|
||||||
STAGE_PEERING = STAGES / '2-networking-a-peering'
|
STAGE_PEERING = STAGES / '2-networking-a-peering'
|
||||||
STAGE_VPN = STAGES / '2-networking-b-vpn'
|
STAGE_VPN = STAGES / '2-networking-b-vpn'
|
||||||
|
|
||||||
|
|
||||||
def test_counts(plan_summary):
|
|
||||||
"Test stage."
|
|
||||||
summary = plan_summary("fast/stages/2-networking-a-peering",
|
|
||||||
tf_var_files=["common.tfvars"])
|
|
||||||
assert summary.counts["modules"] > 0
|
|
||||||
assert summary.counts["resources"] > 0
|
|
||||||
|
|
||||||
|
|
||||||
def test_vpn_peering_parity(plan_summary):
|
def test_vpn_peering_parity(plan_summary):
|
||||||
'''Ensure VPN- and peering-based networking stages are identical except
|
'''Ensure VPN- and peering-based networking stages are identical except
|
||||||
for VPN and VPC peering resources'''
|
for VPN and VPC peering resources'''
|
||||||
|
@ -65,7 +52,7 @@ def compute_md5(filename):
|
||||||
return md5hash.hexdigest()
|
return md5hash.hexdigest()
|
||||||
|
|
||||||
|
|
||||||
def test_vpn_peering_checksums(e2e_plan_runner):
|
def test_vpn_peering_checksums():
|
||||||
'''Compare MD5 sums of common files in the vpn and peering
|
'''Compare MD5 sums of common files in the vpn and peering
|
||||||
networking stages'''
|
networking stages'''
|
||||||
peering_files = {
|
peering_files = {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Copyright 2022 Google LLC
|
# Copyright 2023 Google LLC
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
|
@ -12,10 +12,11 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
module: fast/stages/2-networking-a-peering
|
||||||
|
common_tfvars:
|
||||||
|
- common.tfvars
|
||||||
|
|
||||||
def test_counts(plan_summary):
|
tests:
|
||||||
"Test stage."
|
stage:
|
||||||
summary = plan_summary("fast/stages/2-networking-b-vpn",
|
extra_files:
|
||||||
tf_var_files=["common.tfvars"])
|
- ../../plugins/2-networking-serverless-connector/*.tf
|
||||||
assert summary.counts["modules"] > 0
|
|
||||||
assert summary.counts["resources"] > 0
|
|
|
@ -1,4 +1,3 @@
|
||||||
data_dir = "../../../../../fast/stages/2-networking-b-vpn/data/"
|
|
||||||
automation = {
|
automation = {
|
||||||
outputs_bucket = "test"
|
outputs_bucket = "test"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,54 +0,0 @@
|
||||||
/**
|
|
||||||
* Copyright 2022 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module "stage" {
|
|
||||||
source = "../../../../../fast/stages/02-networking-vpn"
|
|
||||||
data_dir = "../../../../../fast/stages/02-networking-vpn/data/"
|
|
||||||
automation = {
|
|
||||||
outputs_bucket = "test"
|
|
||||||
}
|
|
||||||
billing_account = {
|
|
||||||
id = "000000-111111-222222"
|
|
||||||
organization_id = 123456789012
|
|
||||||
}
|
|
||||||
custom_roles = {
|
|
||||||
service_project_network_admin = "organizations/123456789012/roles/foo"
|
|
||||||
}
|
|
||||||
folder_ids = {
|
|
||||||
networking = null
|
|
||||||
networking-dev = null
|
|
||||||
networking-prod = null
|
|
||||||
}
|
|
||||||
region_trigram = {
|
|
||||||
europe-west1 = "ew1"
|
|
||||||
europe-west3 = "ew3"
|
|
||||||
europe-west8 = "ew8"
|
|
||||||
}
|
|
||||||
service_accounts = {
|
|
||||||
data-platform-dev = "string"
|
|
||||||
data-platform-prod = "string"
|
|
||||||
gke-dev = "string"
|
|
||||||
gke-prod = "string"
|
|
||||||
project-factory-dev = "string"
|
|
||||||
project-factory-prod = "string"
|
|
||||||
}
|
|
||||||
organization = {
|
|
||||||
domain = "fast.example.com"
|
|
||||||
id = 123456789012
|
|
||||||
customer_id = "C00000000"
|
|
||||||
}
|
|
||||||
prefix = "fast2"
|
|
||||||
}
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Copyright 2022 Google LLC
|
# Copyright 2023 Google LLC
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
|
@ -11,3 +11,7 @@
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
counts:
|
||||||
|
modules: 33
|
||||||
|
resources: 159
|
|
@ -0,0 +1,22 @@
|
||||||
|
# Copyright 2023 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.
|
||||||
|
|
||||||
|
module: fast/stages/2-networking-b-vpn
|
||||||
|
common_tfvars:
|
||||||
|
- common.tfvars
|
||||||
|
|
||||||
|
tests:
|
||||||
|
stage:
|
||||||
|
extra_files:
|
||||||
|
- ../../plugins/2-networking-serverless-connector/*.tf
|
|
@ -1,4 +1,3 @@
|
||||||
data_dir = "../../../fast/stages/2-networking-c-nva/data/"
|
|
||||||
automation = {
|
automation = {
|
||||||
outputs_bucket = "test"
|
outputs_bucket = "test"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Copyright 2022 Google LLC
|
# Copyright 2023 Google LLC
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
|
@ -11,3 +11,7 @@
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
counts:
|
||||||
|
modules: 45
|
||||||
|
resources: 168
|
|
@ -1,21 +0,0 @@
|
||||||
# Copyright 2022 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.
|
|
||||||
|
|
||||||
|
|
||||||
def test_counts(plan_summary):
|
|
||||||
"Test stage."
|
|
||||||
summary = plan_summary("fast/stages/2-networking-c-nva",
|
|
||||||
tf_var_files=["common.tfvars"])
|
|
||||||
assert summary.counts["modules"] > 0
|
|
||||||
assert summary.counts["resources"] > 0
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
# Copyright 2023 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.
|
||||||
|
|
||||||
|
module: fast/stages/2-networking-c-nva
|
||||||
|
common_tfvars:
|
||||||
|
- common.tfvars
|
||||||
|
|
||||||
|
tests:
|
||||||
|
stage:
|
||||||
|
extra_files:
|
||||||
|
- ../../plugins/2-networking-serverless-connector/*.tf
|
|
@ -1,4 +1,3 @@
|
||||||
data_dir = "../../../../../fast/stages/2-networking-d-separate-envs/data/"
|
|
||||||
automation = {
|
automation = {
|
||||||
outputs_bucket = "test"
|
outputs_bucket = "test"
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
# Copyright 2023 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.
|
||||||
|
|
||||||
|
counts:
|
||||||
|
modules: 28
|
||||||
|
resources: 122
|
|
@ -1,21 +0,0 @@
|
||||||
# Copyright 2022 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.
|
|
||||||
|
|
||||||
|
|
||||||
def test_counts(plan_summary):
|
|
||||||
"Test stage."
|
|
||||||
summary = plan_summary("fast/stages/2-networking-d-separate-envs",
|
|
||||||
tf_var_files=["common.tfvars"])
|
|
||||||
assert summary.counts["modules"] > 0
|
|
||||||
assert summary.counts["resources"] > 0
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
# Copyright 2023 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.
|
||||||
|
|
||||||
|
module: fast/stages/2-networking-d-separate-envs
|
||||||
|
common_tfvars:
|
||||||
|
- common.tfvars
|
||||||
|
|
||||||
|
tests:
|
||||||
|
stage:
|
||||||
|
extra_files:
|
||||||
|
- ../../plugins/2-networking-serverless-connector/*.tf
|
|
@ -1,4 +1,4 @@
|
||||||
# Copyright 2022 Google LLC
|
# Copyright 2023 Google LLC
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
import contextlib
|
import contextlib
|
||||||
import itertools
|
import glob
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
|
@ -34,7 +34,7 @@ def _prepare_root_module(path):
|
||||||
|
|
||||||
If the TFTEST_COPY environment variable is set, `path` is copied to
|
If the TFTEST_COPY environment variable is set, `path` is copied to
|
||||||
a temporary directory and a few terraform files (e.g.
|
a temporary directory and a few terraform files (e.g.
|
||||||
terraform.tfvars) are delete to ensure a clean test environment.
|
terraform.tfvars) are deleted to ensure a clean test environment.
|
||||||
Otherwise, `path` is simply returned untouched.
|
Otherwise, `path` is simply returned untouched.
|
||||||
"""
|
"""
|
||||||
if os.environ.get('TFTEST_COPY'):
|
if os.environ.get('TFTEST_COPY'):
|
||||||
|
@ -62,7 +62,8 @@ def _prepare_root_module(path):
|
||||||
yield path
|
yield path
|
||||||
|
|
||||||
|
|
||||||
def plan_summary(module_path, basedir, tf_var_files=None, **tf_vars):
|
def plan_summary(module_path, basedir, tf_var_files=None, extra_files=None,
|
||||||
|
**tf_vars):
|
||||||
"""
|
"""
|
||||||
Run a Terraform plan on the module located at `module_path`.
|
Run a Terraform plan on the module located at `module_path`.
|
||||||
|
|
||||||
|
@ -97,7 +98,10 @@ def plan_summary(module_path, basedir, tf_var_files=None, **tf_vars):
|
||||||
with _prepare_root_module(module_path) as test_path:
|
with _prepare_root_module(module_path) as test_path:
|
||||||
binary = os.environ.get('TERRAFORM', 'terraform')
|
binary = os.environ.get('TERRAFORM', 'terraform')
|
||||||
tf = tftest.TerraformTest(test_path, binary=binary)
|
tf = tftest.TerraformTest(test_path, binary=binary)
|
||||||
tf.setup(upgrade=True)
|
extra_files = [(module_path / filename).resolve()
|
||||||
|
for x in extra_files or []
|
||||||
|
for filename in glob.glob(x, root_dir=module_path)]
|
||||||
|
tf.setup(extra_files=extra_files, upgrade=True)
|
||||||
tf_var_files = [(basedir / x).resolve() for x in tf_var_files or []]
|
tf_var_files = [(basedir / x).resolve() for x in tf_var_files or []]
|
||||||
plan = tf.plan(output=True, tf_var_file=tf_var_files, tf_vars=tf_vars)
|
plan = tf.plan(output=True, tf_var_file=tf_var_files, tf_vars=tf_vars)
|
||||||
|
|
||||||
|
@ -135,19 +139,21 @@ def plan_summary_fixture(request):
|
||||||
to the directory of the calling test
|
to the directory of the calling test
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def inner(module_path, basedir=None, tf_var_files=None, **tf_vars):
|
def inner(module_path, basedir=None, tf_var_files=None, extra_files=None,
|
||||||
|
**tf_vars):
|
||||||
if basedir is None:
|
if basedir is None:
|
||||||
basedir = Path(request.fspath).parent
|
basedir = Path(request.fspath).parent
|
||||||
return plan_summary(module_path=module_path, basedir=basedir,
|
return plan_summary(module_path=module_path, basedir=basedir,
|
||||||
tf_var_files=tf_var_files, **tf_vars)
|
tf_var_files=tf_var_files, extra_files=extra_files,
|
||||||
|
**tf_vars)
|
||||||
|
|
||||||
return inner
|
return inner
|
||||||
|
|
||||||
|
|
||||||
def plan_validator(module_path, inventory_paths, basedir, tf_var_files=None,
|
def plan_validator(module_path, inventory_paths, basedir, tf_var_files=None,
|
||||||
**tf_vars):
|
extra_files=None, **tf_vars):
|
||||||
summary = plan_summary(module_path=module_path, tf_var_files=tf_var_files,
|
summary = plan_summary(module_path=module_path, tf_var_files=tf_var_files,
|
||||||
basedir=basedir, **tf_vars)
|
extra_files=extra_files, basedir=basedir, **tf_vars)
|
||||||
|
|
||||||
# allow single single string for inventory_paths
|
# allow single single string for inventory_paths
|
||||||
if not isinstance(inventory_paths, list):
|
if not isinstance(inventory_paths, list):
|
||||||
|
|
|
@ -78,11 +78,10 @@ def _check_dir(dir_name, exclude_files=None, files=False, show_extra=False):
|
||||||
try:
|
try:
|
||||||
new_doc = tfdoc.create_doc(readme_path.parent, files, show_extra,
|
new_doc = tfdoc.create_doc(readme_path.parent, files, show_extra,
|
||||||
exclude_files, readme)
|
exclude_files, readme)
|
||||||
# TODO: support variables in multiple files
|
|
||||||
newvars = new_doc.variables
|
newvars = new_doc.variables
|
||||||
newouts = new_doc.outputs
|
newouts = new_doc.outputs
|
||||||
variables = [v.name for v in newvars if v.file == "variables.tf"]
|
variables = [v.name for v in newvars if v.file.endswith('variables.tf')]
|
||||||
outputs = [o.name for o in newouts if o.file == "outputs.tf"]
|
outputs = [o.name for o in newouts if o.file.endswith('outputs.tf')]
|
||||||
except SystemExit:
|
except SystemExit:
|
||||||
state = state.SKIP
|
state = state.SKIP
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -175,7 +175,9 @@ def parse_files(basepath, exclude_files=None):
|
||||||
def parse_outputs(basepath, exclude_files=None):
|
def parse_outputs(basepath, exclude_files=None):
|
||||||
'Return a list of Output named tuples for root module outputs*.tf.'
|
'Return a list of Output named tuples for root module outputs*.tf.'
|
||||||
exclude_files = exclude_files or []
|
exclude_files = exclude_files or []
|
||||||
for name in glob.glob(os.path.join(basepath, 'outputs*tf')):
|
names = glob.glob(os.path.join(basepath, 'outputs*tf'))
|
||||||
|
names += glob.glob(os.path.join(basepath, 'local-*outputs*tf'))
|
||||||
|
for name in names:
|
||||||
shortname = os.path.basename(name)
|
shortname = os.path.basename(name)
|
||||||
if shortname in exclude_files:
|
if shortname in exclude_files:
|
||||||
continue
|
continue
|
||||||
|
@ -196,7 +198,9 @@ def parse_outputs(basepath, exclude_files=None):
|
||||||
def parse_variables(basepath, exclude_files=None):
|
def parse_variables(basepath, exclude_files=None):
|
||||||
'Return a list of Variable named tuples for root module variables*.tf.'
|
'Return a list of Variable named tuples for root module variables*.tf.'
|
||||||
exclude_files = exclude_files or []
|
exclude_files = exclude_files or []
|
||||||
for name in glob.glob(os.path.join(basepath, 'variables*tf')):
|
names = glob.glob(os.path.join(basepath, 'variables*tf'))
|
||||||
|
names += glob.glob(os.path.join(basepath, 'local-*variables*tf'))
|
||||||
|
for name in names:
|
||||||
shortname = os.path.basename(name)
|
shortname = os.path.basename(name)
|
||||||
if shortname in exclude_files:
|
if shortname in exclude_files:
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in New Issue