Standardise reuse variable from project module and implement for net-vpc (#3205)
* exposing the network_id from the net-vpc module for use with tag bindings * convert vpc_create to vpc_reuse * Changed the reuse vars to standardised attributes * fixed readme tests and schemas * modified apigee blueprint to use vpc_reuse with network_id passthrough --------- Co-authored-by: Ludovico Magnocavallo <ludomagno@google.com>
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -63,7 +63,19 @@ module "shared_vpc" {
|
||||
source = "../../../modules/net-vpc"
|
||||
project_id = var.project_config.shared_vpc_service_config.host_project
|
||||
name = var.network_config.shared_vpc.name
|
||||
vpc_create = false
|
||||
vpc_reuse = (
|
||||
var.network_config.shared_vpc.network_id == null
|
||||
? {
|
||||
use_data_source = true
|
||||
attributes = null
|
||||
}
|
||||
: {
|
||||
use_data_source = false
|
||||
attributes = {
|
||||
network_id = var.network_config.shared_vpc.network_id
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
module "apigee_vpc" {
|
||||
@@ -71,7 +83,7 @@ module "apigee_vpc" {
|
||||
source = "../../../modules/net-vpc"
|
||||
project_id = module.project.project_id
|
||||
name = coalesce(var.network_config.apigee_vpc.name, "apigee-vpc")
|
||||
vpc_create = var.network_config.apigee_vpc.auto_create
|
||||
vpc_reuse = var.network_config.apigee_vpc.vpc_reuse
|
||||
psa_configs = [{
|
||||
ranges = merge(flatten([for k, v in var.apigee_config.instances : merge(
|
||||
v.runtime_ip_cidr_range == null ? {} : { "apigee-22-${k}" = v.runtime_ip_cidr_range },
|
||||
|
||||
@@ -29,15 +29,15 @@ locals {
|
||||
}
|
||||
network = try(module.shared_vpc[0].id, module.apigee_vpc[0].id)
|
||||
neg_subnets = (var.network_config.shared_vpc == null ?
|
||||
(try(var.network_config.apigee_vpc.auto_create, false) ?
|
||||
(try(var.network_config.apigee_vpc.vpc_reuse, null) == null ?
|
||||
{ for k, v in module.apigee_vpc[0].subnets_psc : v.region => v.id } :
|
||||
{ for k, v in var.network_config.apigee_vpc.subnets_psc : v => v.id }) :
|
||||
{ for k, v in var.network_config.apigee_vpc.subnets_psc : k => v.id }) :
|
||||
var.network_config.shared_vpc.subnets_psc
|
||||
)
|
||||
ilb_subnets = (var.network_config.shared_vpc == null ?
|
||||
(try(var.network_config.apigee_vpc.auto_create, false) ?
|
||||
(try(var.network_config.apigee_vpc.vpc_reuse, null) == null ?
|
||||
{ for k, v in module.apigee_vpc[0].subnets : v.region => v.id } :
|
||||
{ for k, v in var.network_config.apigee_vpc.subnets : v => v.id }) :
|
||||
{ for k, v in var.network_config.apigee_vpc.subnets : k => v.id }) :
|
||||
var.network_config.shared_vpc.subnets
|
||||
)
|
||||
ext_instances = var.ext_lb_config == null ? {} : { for k, v in local.neg_subnets : k => module.apigee.instances[k] }
|
||||
|
||||
@@ -292,12 +292,17 @@ variable "network_config" {
|
||||
type = object({
|
||||
shared_vpc = optional(object({
|
||||
name = string
|
||||
network_id = optional(number)
|
||||
subnets = map(string)
|
||||
subnets_psc = map(string)
|
||||
}))
|
||||
apigee_vpc = optional(object({
|
||||
name = optional(string)
|
||||
auto_create = optional(bool, true)
|
||||
name = optional(string)
|
||||
vpc_reuse = optional(object({
|
||||
use_data_source = optional(bool, true)
|
||||
attributes = optional(object({
|
||||
network_id = number
|
||||
})) }))
|
||||
subnets = optional(map(object({
|
||||
id = optional(string)
|
||||
name = optional(string)
|
||||
|
||||
@@ -66,7 +66,7 @@ Do the following to verify that everything works as expected.
|
||||
| [organization](variables.tf#L59) | Apigee organization. | <code title="object({ display_name = optional(string, "Apigee organization created by tf module") description = optional(string, "Apigee organization created by tf module") authorized_network = optional(string, "vpc") runtime_type = optional(string, "CLOUD") billing_type = optional(string) database_encryption_key = optional(string) analytics_region = optional(string, "europe-west1") })">object({…})</code> | | <code title="{ }">{…}</code> |
|
||||
| [path](variables.tf#L75) | Bucket path. | <code>string</code> | | <code>"/analytics"</code> |
|
||||
| [project_create](variables.tf#L82) | Parameters for the creation of the new project. | <code title="object({ billing_account_id = string parent = string })">object({…})</code> | | <code>null</code> |
|
||||
| [vpc_create](variables.tf#L103) | Boolean flag indicating whether the VPC should be created or not. | <code>bool</code> | | <code>true</code> |
|
||||
| [vpc_reuse](variables.tf#L103) | Reuse existing VPC if not null. If the network_id number is not passed in, a data source is used. | <code title="object({ use_data_source = optional(bool, true) attributes = optional(object({ network_id = number })) })">object({…})</code> | | <code>null</code> |
|
||||
|
||||
## Outputs
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ module "vpc" {
|
||||
source = "../../../modules/net-vpc"
|
||||
project_id = module.project.project_id
|
||||
name = var.organization.authorized_network
|
||||
vpc_create = var.vpc_create
|
||||
vpc_reuse = var.vpc_reuse
|
||||
subnets_psc = [for k, v in var.psc_config : {
|
||||
ip_cidr_range = v
|
||||
name = "subnet-psc-${k}"
|
||||
|
||||
@@ -100,8 +100,20 @@ variable "psc_config" {
|
||||
nullable = false
|
||||
}
|
||||
|
||||
variable "vpc_create" {
|
||||
description = "Boolean flag indicating whether the VPC should be created or not."
|
||||
type = bool
|
||||
default = true
|
||||
variable "vpc_reuse" {
|
||||
description = "Reuse existing VPC if not null. If the network_id number is not passed in, a data source is used."
|
||||
type = object({
|
||||
use_data_source = optional(bool, true)
|
||||
attributes = optional(object({
|
||||
network_id = number
|
||||
}))
|
||||
})
|
||||
default = null
|
||||
validation {
|
||||
condition = (
|
||||
try(var.vpc_reuse.use_data_source, null) != false ||
|
||||
try(var.vpc_reuse.attributes, null) != null
|
||||
)
|
||||
error_message = "Reuse datasource can be disabled only if attributes are set."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,12 @@ module "vpc" {
|
||||
region = var.region
|
||||
}
|
||||
] : []
|
||||
vpc_create = var.project_create != null ? true : false
|
||||
vpc_reuse = (
|
||||
var.project_create == null
|
||||
? {
|
||||
use_data_source = true
|
||||
} : null
|
||||
)
|
||||
}
|
||||
|
||||
module "firewall" {
|
||||
|
||||
@@ -69,8 +69,8 @@ Alternatively you can also check all the above using the dashboards available in
|
||||
| [mgmt_subnet_cidr_block](variables.tf#L60) | Management subnet IP CIDR range. | <code>string</code> | | <code>"10.0.2.0/24"</code> |
|
||||
| [project_create](variables.tf#L66) | Parameters for the creation of the new project. | <code title="object({ billing_account_id = string parent = string })">object({…})</code> | | <code>null</code> |
|
||||
| [region](variables.tf#L80) | Region. | <code>string</code> | | <code>"europe-west1"</code> |
|
||||
| [vpc_create](variables.tf#L86) | Flag indicating whether the VPC should be created or not. | <code>bool</code> | | <code>true</code> |
|
||||
| [vpc_name](variables.tf#L92) | VPC name. | <code>string</code> | | <code>"vpc"</code> |
|
||||
| [vpc_name](variables.tf#L86) | VPC name. | <code>string</code> | | <code>"vpc"</code> |
|
||||
| [vpc_reuse](variables.tf#L93) | Reuse existing VPC if not null. If the network_id number is not passed in, a data source is used. | <code title="object({ use_data_source = optional(bool, true) attributes = optional(object({ network_id = number })) })">object({…})</code> | | <code>null</code> |
|
||||
|
||||
## Outputs
|
||||
|
||||
|
||||
@@ -83,15 +83,27 @@ variable "region" {
|
||||
default = "europe-west1"
|
||||
}
|
||||
|
||||
variable "vpc_create" {
|
||||
description = "Flag indicating whether the VPC should be created or not."
|
||||
type = bool
|
||||
default = true
|
||||
}
|
||||
|
||||
variable "vpc_name" {
|
||||
description = "VPC name."
|
||||
type = string
|
||||
nullable = false
|
||||
default = "vpc"
|
||||
}
|
||||
|
||||
variable "vpc_reuse" {
|
||||
description = "Reuse existing VPC if not null. If the network_id number is not passed in, a data source is used."
|
||||
type = object({
|
||||
use_data_source = optional(bool, true)
|
||||
attributes = optional(object({
|
||||
network_id = number
|
||||
}))
|
||||
})
|
||||
default = null
|
||||
validation {
|
||||
condition = (
|
||||
try(var.vpc_reuse.use_data_source, null) != false ||
|
||||
try(var.vpc_reuse.attributes, null) != null
|
||||
)
|
||||
error_message = "Reuse datasource can be disabled only if attributes are set."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ module "vpc" {
|
||||
source = "../../../modules/net-vpc"
|
||||
project_id = module.project.project_id
|
||||
name = var.vpc_name
|
||||
vpc_create = var.vpc_create
|
||||
vpc_reuse = var.vpc_reuse
|
||||
subnets = [
|
||||
{
|
||||
ip_cidr_range = var.mgmt_subnet_cidr_block
|
||||
|
||||
@@ -56,7 +56,12 @@ module "project" {
|
||||
parent = try(var.project_create.parent, null)
|
||||
billing_account = try(var.project_create.billing_account, null)
|
||||
name = var.project_id
|
||||
project_create = var.project_create != null
|
||||
project_reuse = (
|
||||
var.project_create == null
|
||||
? {
|
||||
use_data_source = true
|
||||
} : null
|
||||
)
|
||||
services = compact([
|
||||
"anthos.googleapis.com",
|
||||
var.registry_create ? "artifactregistry.googleapis.com" : null,
|
||||
|
||||
Reference in New Issue
Block a user