Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net-address end-to-end tests #1963

Merged
merged 5 commits into from Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 20 additions & 23 deletions modules/net-address/README.md
Expand Up @@ -12,14 +12,17 @@ module "addresses" {
project_id = var.project_id
external_addresses = {
one = { region = "europe-west1" }
two = { region = "europe-west2" }
two = {
region = "europe-west2"
tier = "STANDARD"
}
}
global_addresses = {
app-1 = {}
app-2 = {}
}
}
# tftest modules=1 resources=4 inventory=external.yaml
# tftest modules=1 resources=4 inventory=external.yaml e2e
```

### Internal addresses
Expand All @@ -35,13 +38,13 @@ module "addresses" {
subnetwork = var.subnet.self_link
}
ilb-2 = {
address = "10.0.0.2"
address = "10.0.16.2"
region = var.region
subnetwork = var.subnet.self_link
}
}
}
# tftest modules=1 resources=2 inventory=internal.yaml
# tftest modules=1 resources=2 inventory=internal.yaml e2e
```

### IPv6 addresses
Expand All @@ -55,27 +58,21 @@ module "addresses" {
external_addresses = {
nlb = {
region = var.region
subnetwork = var.subnet.self_link
subnetwork = module.vpc.subnets["${var.region}/ipv6-external"].self_link
ipv6 = {
endpoint_type = "NETLB"
}
}
}
internal_addresses = {
ilb = {
ipv6 = {}
purpose = "SHARED_LOADBALANCER_VIP"
region = var.region
subnetwork = var.subnet.self_link
}
vm = {
ipv6 = {}
region = var.region
subnetwork = var.subnet.self_link
subnetwork = module.vpc.subnets["${var.region}/ipv6-internal"].self_link
}
}
}
# tftest modules=1 resources=3 inventory=ipv6.yaml
# tftest modules=2 resources=7 fixtures=fixtures/net-vpc-ipv6.tf inventory=ipv6.yaml e2e
```

### PSA addresses
Expand All @@ -92,7 +89,7 @@ module "addresses" {
}
}
}
# tftest modules=1 resources=1 inventory=psa.yaml
# tftest modules=1 resources=1 inventory=psa.yaml e2e
```

### PSC addresses
Expand All @@ -103,16 +100,12 @@ module "addresses" {
project_id = var.project_id
psc_addresses = {
one = {
address = null
network = var.vpc.self_link
}
two = {
address = "10.0.0.32"
network = var.vpc.self_link
}
}
}
# tftest modules=1 resources=2 inventory=psc.yaml
# tftest modules=1 resources=1 inventory=psc.yaml e2e
```

# IPSec Interconnect addresses
Expand All @@ -136,17 +129,17 @@ module "addresses" {
}
}
}
# tftest modules=1 resources=2 inventory=ipsec-interconnect.yaml
# tftest modules=1 resources=2 inventory=ipsec-interconnect.yaml e2e
```
<!-- BEGIN TFDOC -->
## Variables

| name | description | type | required | default |
|---|---|:---:|:---:|:---:|
| [project_id](variables.tf#L84) | Project where the addresses will be created. | <code>string</code> | ✓ | |
| [external_addresses](variables.tf#L17) | Map of external addresses, keyed by name. | <code title="map&#40;object&#40;&#123;&#10; region &#61; string&#10; description &#61; optional&#40;string, &#34;Terraform managed.&#34;&#41;&#10; ipv6 &#61; optional&#40;object&#40;&#123;&#10; endpoint_type &#61; string&#10; &#125;&#41;&#41;&#10; labels &#61; optional&#40;map&#40;string&#41;, &#123;&#125;&#41;&#10; name &#61; optional&#40;string&#41;&#10; tier &#61; optional&#40;string&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [global_addresses](variables.tf#L39) | List of global addresses to create. | <code title="map&#40;object&#40;&#123;&#10; description &#61; optional&#40;string, &#34;Terraform managed.&#34;&#41;&#10; ipv6 &#61; optional&#40;map&#40;string&#41;&#41; &#35; To be left empty for ipv6&#10; name &#61; optional&#40;string&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [internal_addresses](variables.tf#L49) | Map of internal addresses to create, keyed by name. | <code title="map&#40;object&#40;&#123;&#10; region &#61; string&#10; subnetwork &#61; string&#10; address &#61; optional&#40;string&#41;&#10; description &#61; optional&#40;string, &#34;Terraform managed.&#34;&#41;&#10; ipv6 &#61; optional&#40;map&#40;string&#41;&#41; &#35; To be left empty for ipv6&#10; labels &#61; optional&#40;map&#40;string&#41;&#41;&#10; name &#61; optional&#40;string&#41;&#10; purpose &#61; optional&#40;string&#41;&#10; tier &#61; optional&#40;string&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [external_addresses](variables.tf#L17) | Map of external addresses, keyed by name. | <code title="map&#40;object&#40;&#123;&#10; region &#61; string&#10; description &#61; optional&#40;string, &#34;Terraform managed.&#34;&#41;&#10; ipv6 &#61; optional&#40;object&#40;&#123;&#10; endpoint_type &#61; string&#10; &#125;&#41;&#41;&#10; labels &#61; optional&#40;map&#40;string&#41;, &#123;&#125;&#41;&#10; name &#61; optional&#40;string&#41;&#10; subnetwork &#61; optional&#40;string&#41; &#35; for IPv6&#10; tier &#61; optional&#40;string&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [global_addresses](variables.tf#L40) | List of global addresses to create. | <code title="map&#40;object&#40;&#123;&#10; description &#61; optional&#40;string, &#34;Terraform managed.&#34;&#41;&#10; ipv6 &#61; optional&#40;map&#40;string&#41;&#41; &#35; To be left empty for ipv6&#10; name &#61; optional&#40;string&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [internal_addresses](variables.tf#L50) | Map of internal addresses to create, keyed by name. | <code title="map&#40;object&#40;&#123;&#10; region &#61; string&#10; subnetwork &#61; string&#10; address &#61; optional&#40;string&#41;&#10; description &#61; optional&#40;string, &#34;Terraform managed.&#34;&#41;&#10; ipv6 &#61; optional&#40;map&#40;string&#41;&#41; &#35; To be left empty for ipv6&#10; labels &#61; optional&#40;map&#40;string&#41;&#41;&#10; name &#61; optional&#40;string&#41;&#10; purpose &#61; optional&#40;string&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [ipsec_interconnect_addresses](variables.tf#L65) | Map of internal addresses used for HPA VPN over Cloud Interconnect. | <code title="map&#40;object&#40;&#123;&#10; region &#61; string&#10; address &#61; string&#10; network &#61; string&#10; description &#61; optional&#40;string, &#34;Terraform managed.&#34;&#41;&#10; name &#61; optional&#40;string&#41;&#10; prefix_length &#61; number&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [psa_addresses](variables.tf#L89) | Map of internal addresses used for Private Service Access. | <code title="map&#40;object&#40;&#123;&#10; address &#61; string&#10; network &#61; string&#10; prefix_length &#61; number&#10; description &#61; optional&#40;string, &#34;Terraform managed.&#34;&#41;&#10; name &#61; optional&#40;string&#41;&#10;&#10;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [psc_addresses](variables.tf#L102) | Map of internal addresses used for Private Service Connect. | <code title="map&#40;object&#40;&#123;&#10; address &#61; string&#10; network &#61; string&#10; description &#61; optional&#40;string, &#34;Terraform managed.&#34;&#41;&#10; name &#61; optional&#40;string&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#123;&#125;</code> |
Expand All @@ -161,4 +154,8 @@ module "addresses" {
| [ipsec_interconnect_addresses](outputs.tf#L41) | Allocated internal addresses for HA VPN over Cloud Interconnect. | |
| [psa_addresses](outputs.tf#L49) | Allocated internal addresses for PSA endpoints. | |
| [psc_addresses](outputs.tf#L57) | Allocated internal addresses for PSC endpoints. | |

## Fixtures

- [net-vpc-ipv6.tf](../../tests/fixtures/net-vpc-ipv6.tf)
<!-- END TFDOC -->
16 changes: 8 additions & 8 deletions modules/net-address/main.tf
Expand Up @@ -27,29 +27,29 @@ resource "google_compute_address" "external" {
for_each = var.external_addresses
project = var.project_id
name = coalesce(each.value.name, each.key)
description = each.value.description
address_type = "EXTERNAL"
description = each.value.description
ip_version = each.value.ipv6 != null ? "IPV6" : "IPV4"
ipv6_endpoint_type = try(each.value.ipv6.endpoint_type, null)
labels = each.value.labels
network_tier = each.value.tier
region = each.value.region
labels = each.value.labels
subnetwork = each.value.subnetwork
}

resource "google_compute_address" "internal" {
provider = google-beta
for_each = var.internal_addresses
project = var.project_id
name = coalesce(each.value.name, each.key)
description = each.value.description
address_type = "INTERNAL"
region = each.value.region
subnetwork = each.value.subnetwork
address = each.value.address
address_type = "INTERNAL"
description = each.value.description
ip_version = each.value.ipv6 != null ? "IPV6" : "IPV4"
network_tier = each.value.tier
purpose = each.value.purpose
labels = coalesce(each.value.labels, {})
purpose = each.value.purpose
region = each.value.region
subnetwork = each.value.subnetwork
}

resource "google_compute_global_address" "psc" {
Expand Down
8 changes: 4 additions & 4 deletions modules/net-address/variables.tf
Expand Up @@ -22,9 +22,10 @@ variable "external_addresses" {
ipv6 = optional(object({
endpoint_type = string
}))
labels = optional(map(string), {})
name = optional(string)
tier = optional(string)
labels = optional(map(string), {})
name = optional(string)
subnetwork = optional(string) # for IPv6
tier = optional(string)
}))
default = {}
validation {
Expand Down Expand Up @@ -57,7 +58,6 @@ variable "internal_addresses" {
labels = optional(map(string))
name = optional(string)
purpose = optional(string)
tier = optional(string)
}))
default = {}
}
Expand Down
40 changes: 40 additions & 0 deletions tests/fixtures/net-vpc-ipv6.tf
@@ -0,0 +1,40 @@
# Copyright 2024 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 "vpc" {
source = "./fabric/modules/net-vpc"
project_id = var.project_id
name = "fixture-net-vpc-external"
ipv6_config = {
enable_ula_internal = true
}
subnets = [
{
ip_cidr_range = "192.168.0.0/24"
name = "ipv6-external"
region = var.region
ipv6 = {
access_type = "EXTERNAL"
}
},
{
ip_cidr_range = "192.168.1.0/24"
name = "ipv6-internal"
region = var.region
ipv6 = {
access_type = "INTERNAL"
}
},
]
}
2 changes: 1 addition & 1 deletion tests/modules/net_address/examples/internal.yaml
Expand Up @@ -23,7 +23,7 @@ values:
region: europe-west8
subnetwork: subnet_self_link
module.addresses.google_compute_address.internal["ilb-2"]:
address: 10.0.0.2
address: 10.0.16.2
address_type: INTERNAL
labels: null
name: ilb-2
Expand Down
13 changes: 1 addition & 12 deletions tests/modules/net_address/examples/ipv6.yaml
Expand Up @@ -20,16 +20,6 @@ values:
name: nlb
project: project-id
region: europe-west8
module.addresses.google_compute_address.internal["ilb"]:
address_type: INTERNAL
ip_version: IPV6
labels: null
name: ilb
network: null
project: project-id
purpose: SHARED_LOADBALANCER_VIP
region: europe-west8
subnetwork: subnet_self_link
module.addresses.google_compute_address.internal["vm"]:
address_type: INTERNAL
ip_version: IPV6
Expand All @@ -38,7 +28,6 @@ values:
network: null
project: project-id
region: europe-west8
subnetwork: subnet_self_link

counts:
google_compute_address: 3
google_compute_address: 2
10 changes: 2 additions & 8 deletions tests/modules/net_address/examples/psc.yaml
Expand Up @@ -14,18 +14,12 @@

values:
module.addresses.google_compute_global_address.psc["one"]:
address_type: INTERNAL
name: one
network: projects/xxx/global/networks/aaa
project: project-id
purpose: PRIVATE_SERVICE_CONNECT
module.addresses.google_compute_global_address.psc["two"]:
address: 10.0.0.32
address_type: INTERNAL
name: two
name: one
network: projects/xxx/global/networks/aaa
project: project-id
purpose: PRIVATE_SERVICE_CONNECT

counts:
google_compute_global_address: 2
google_compute_global_address: 1