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

E2E tests for ncc-spoke-ra #2424

Merged
merged 2 commits into from
Jul 13, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 53 additions & 39 deletions modules/ncc-spoke-ra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,98 +13,110 @@ module "spoke-ra" {
source = "./fabric/modules/ncc-spoke-ra"
hub = { create = true, name = "ncc-hub" }
name = "spoke-ra"
project_id = "my-project"
region = "europe-west1"
project_id = var.project_id
region = var.region
router_appliances = [
{
internal_ip = "10.0.0.3"
vm_self_link = "projects/my-project/zones/europe-west1-b/instances/router-app"
internal_ip = module.compute-vm-primary-b.internal_ip
vm_self_link = module.compute-vm-primary-b.self_link
}
]
router_config = {
asn = 65000
ip_interface0 = "10.0.0.14"
ip_interface1 = "10.0.0.15"
ip_interface0 = "10.0.16.14"
ip_interface1 = "10.0.16.15"
peer_asn = 65001
}
vpc_config = {
network_name = "my-vpc"
network_name = var.vpc.self_link
subnet_self_link = var.subnet.self_link
}
}
# tftest modules=1 resources=7
# tftest modules=5 resources=11 fixtures=fixtures/compute-vm-nva.tf e2e
```

### Two spokes

```hcl
resource "google_network_connectivity_hub" "default" {
name = "Hub"
description = "Hub"
project = var.project_id
}

module "spoke-ra-a" {
source = "./fabric/modules/ncc-spoke-ra"
hub = { id = "projects/my-project/locations/global/hubs/ncc-hub" }
hub = { id = google_network_connectivity_hub.default.id }
name = "spoke-ra-a"
project_id = "my-project"
region = "europe-west1"
project_id = var.project_id
region = var.regions.primary
router_appliances = [
{
internal_ip = "10.0.0.3"
vm_self_link = "projects/my-project/zones/europe-west1-b/instances/router-app-a"
internal_ip = module.compute-vm-primary-b.internal_ip
vm_self_link = module.compute-vm-primary-b.self_link
}
]
router_config = {
asn = 65000
ip_interface0 = "10.0.0.14"
ip_interface1 = "10.0.0.15"
ip_interface0 = "10.0.16.14"
ip_interface1 = "10.0.16.15"
peer_asn = 65001
}
vpc_config = {
network_name = "my-vpc1"
subnet_self_link = "projects/my-project/regions/europe-west1/subnetworks/subnet"
network_name = var.vpc.self_link
subnet_self_link = var.subnets.primary.self_link
}
}

module "spoke-ra-b" {
source = "./fabric/modules/ncc-spoke-ra"
hub = { id = "projects/my-project/locations/global/hubs/ncc-hub" }
hub = { id = google_network_connectivity_hub.default.id }
name = "spoke-ra-b"
project_id = "my-project"
region = "europe-west3"
project_id = var.project_id
region = var.regions.secondary
router_appliances = [
{
internal_ip = "10.1.0.5"
vm_self_link = "projects/my-project/zones/europe-west3-b/instances/router-app-b"
internal_ip = module.compute-vm-secondary-b.internal_ip
vm_self_link = module.compute-vm-secondary-b.self_link
}
]
router_config = {
asn = 65000
ip_interface0 = "10.0.0.14"
ip_interface1 = "10.0.0.15"
ip_interface0 = "10.1.16.14"
ip_interface1 = "10.1.16.15"
peer_asn = 65002
}
vpc_config = {
network_name = "my-vpc2"
subnet_self_link = "projects/my-project/regions/europe-west3/subnetworks/subnet"
network_name = var.vpc.self_link
subnet_self_link = var.subnets.secondary.self_link
}
}
# tftest modules=2 resources=12
# tftest modules=6 resources=17 fixtures=fixtures/compute-vm-nva.tf e2e
```

### Spoke with load-balanced router appliances

```hcl
resource "google_network_connectivity_hub" "default" {
name = "Hub"
description = "Hub"
project = var.project_id
}

module "spoke-ra" {
source = "./fabric/modules/ncc-spoke-ra"
hub = { id = "projects/my-project/locations/global/hubs/ncc-hub" }
hub = { id = google_network_connectivity_hub.default.id }
name = "spoke-ra"
project_id = "my-project"
region = "europe-west1"
project_id = var.project_id
region = var.region
router_appliances = [
{
internal_ip = "10.0.0.3"
vm_self_link = "projects/my-project/zones/europe-west1-b/instances/router-app-a"
internal_ip = module.compute-vm-primary-b.internal_ip
vm_self_link = module.compute-vm-primary-b.self_link
},
{
internal_ip = "10.0.0.4"
vm_self_link = "projects/my-project/zones/europe-west1-c/instances/router-app-b"
internal_ip = module.compute-vm-primary-c.internal_ip
vm_self_link = module.compute-vm-primary-c.self_link
}
]
router_config = {
Expand All @@ -115,19 +127,18 @@ module "spoke-ra" {
"10.10.0.0/24" = "peered-vpc"
}
}
ip_interface0 = "10.0.0.14"
ip_interface1 = "10.0.0.15"
ip_interface0 = "10.0.16.14"
ip_interface1 = "10.0.16.15"
peer_asn = 65001
}
vpc_config = {
network_name = "my-vpc"
network_name = var.vpc.self_link
subnet_self_link = var.subnet.self_link
}
}
# tftest modules=1 resources=8
# tftest modules=5 resources=13 fixtures=fixtures/compute-vm-nva.tf e2e
```
<!-- BEGIN TFDOC -->

## Variables

| name | description | type | required | default |
Expand All @@ -150,4 +161,7 @@ module "spoke-ra" {
| [router](outputs.tf#L27) | Cloud Router resource. | |
| [spoke-ra](outputs.tf#L32) | NCC spoke resource. | |

## Fixtures

- [compute-vm-nva.tf](../../tests/fixtures/compute-vm-nva.tf)
<!-- END TFDOC -->
17 changes: 17 additions & 0 deletions tests/examples/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@ variable "subnet" {
}
}

variable "subnets" {
default = {
primary = {
name = "primary"
region = "europe-west8"
cidr = "10.0.16.0/24"
self_link = "https://www.googleapis.com/compute/v1/projects/my-project/regions/europe-west8/subnetworks/primary"
}
secondary = {
name = "secondary"
region = "europe-west89"
cidr = "10.0.16.0/24"
self_link = "https://www.googleapis.com/compute/v1/projects/my-project/regions/europe-west9/subnetworks/secondary"
}
}
}

variable "subnet_psc_1" {
default = {
name = "subnet_name"
Expand Down
17 changes: 16 additions & 1 deletion tests/examples_e2e/setup_module/e2e_tests.tfvars.tftpl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,22 @@ subnet = {
region = "${subnet.region}"
cidr = "${subnet.ip_cidr_range}"
self_link = "${subnet.self_link}"
}
}
subnets = {
primary = {
name = "${subnet.name}"
region = "${subnet.region}"
cidr = "${subnet.ip_cidr_range}"
self_link = "${subnet.self_link}"
}
secondary = {
name = "${subnet_secondary.name}"
region = "${subnet_secondary.region}"
cidr = "${subnet_secondary.ip_cidr_range}"
self_link = "${subnet_secondary.self_link}"
}

}
subnet_psc_1 = {
name = "${subnet_psc_1.name}"
region = "${subnet_psc_1.region}"
Expand Down
85 changes: 72 additions & 13 deletions tests/examples_e2e/setup_module/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ resource "google_compute_network" "network" {
depends_on = [google_project_service.project_service]
}

resource "google_compute_subnetwork" "subnetwork" {
# Primary region networking

resource "google_compute_subnetwork" "primary" {
ip_cidr_range = "10.0.16.0/24"
name = "e2e-test-1"
name = "e2e-test-primary"
network = google_compute_network.network.name
project = google_project.project.project_id
private_ip_google_access = true
Expand All @@ -108,7 +110,7 @@ resource "google_compute_subnetwork" "subnetwork" {
}
}

resource "google_compute_subnetwork" "proxy_only_global" {
resource "google_compute_subnetwork" "primary_proxy_only_global" {
project = google_project.project.project_id
network = google_compute_network.network.name
name = "proxy-global"
Expand All @@ -118,7 +120,7 @@ resource "google_compute_subnetwork" "proxy_only_global" {
role = "ACTIVE"
}

resource "google_compute_subnetwork" "proxy_only_regional" {
resource "google_compute_subnetwork" "primary_proxy_only_regional" {
project = google_project.project.project_id
network = google_compute_network.network.name
name = "proxy-regional"
Expand All @@ -128,7 +130,7 @@ resource "google_compute_subnetwork" "proxy_only_regional" {
role = "ACTIVE"
}

resource "google_compute_subnetwork" "psc" {
resource "google_compute_subnetwork" "primary_psc" {
project = google_project.project.project_id
network = google_compute_network.network.name
name = "psc-regional"
Expand All @@ -137,6 +139,57 @@ resource "google_compute_subnetwork" "psc" {
purpose = "PRIVATE_SERVICE_CONNECT"
}



# Secondary region networking

resource "google_compute_subnetwork" "secondary" {
ip_cidr_range = "10.1.16.0/24"
name = "e2e-test-secondary"
network = google_compute_network.network.name
project = google_project.project.project_id
private_ip_google_access = true
region = var.region_secondary
secondary_ip_range {
range_name = "pods"
ip_cidr_range = "100.69.0.0/16"
}
secondary_ip_range {
range_name = "services"
ip_cidr_range = "100.72.1.0/24"
}
}

resource "google_compute_subnetwork" "secondary_proxy_only_global" {
project = google_project.project.project_id
network = google_compute_network.network.name
name = "proxy-global"
region = var.region_secondary
ip_cidr_range = "10.1.17.0/24"
purpose = "GLOBAL_MANAGED_PROXY"
role = "ACTIVE"
}

resource "google_compute_subnetwork" "secondary_proxy_only_regional" {
project = google_project.project.project_id
network = google_compute_network.network.name
name = "proxy-regional"
region = var.region_secondary
ip_cidr_range = "10.1.18.0/24"
purpose = "REGIONAL_MANAGED_PROXY"
role = "ACTIVE"
}

resource "google_compute_subnetwork" "secondary_psc" {
project = google_project.project.project_id
network = google_compute_network.network.name
name = "psc-regional"
region = var.region_secondary
ip_cidr_range = "10.1.19.0/24"
purpose = "PRIVATE_SERVICE_CONNECT"
}


### PSA ###

resource "google_compute_global_address" "psa_ranges" {
Expand Down Expand Up @@ -224,16 +277,22 @@ resource "local_file" "terraform_tfvars" {
iam_email = "serviceAccount:${google_service_account.service_account.email}"
}
subnet = {
name = google_compute_subnetwork.subnetwork.name
region = google_compute_subnetwork.subnetwork.region
ip_cidr_range = google_compute_subnetwork.subnetwork.ip_cidr_range
self_link = google_compute_subnetwork.subnetwork.self_link
name = google_compute_subnetwork.primary.name
region = google_compute_subnetwork.primary.region
ip_cidr_range = google_compute_subnetwork.primary.ip_cidr_range
self_link = google_compute_subnetwork.primary.self_link
}
subnet_secondary = {
name = google_compute_subnetwork.secondary.name
region = google_compute_subnetwork.secondary.region
ip_cidr_range = google_compute_subnetwork.secondary.ip_cidr_range
self_link = google_compute_subnetwork.secondary.self_link
}
subnet_psc_1 = {
name = google_compute_subnetwork.psc.name
region = google_compute_subnetwork.psc.region
ip_cidr_range = google_compute_subnetwork.psc.ip_cidr_range
self_link = google_compute_subnetwork.psc.self_link
name = google_compute_subnetwork.primary_psc.name
region = google_compute_subnetwork.primary_psc.region
ip_cidr_range = google_compute_subnetwork.primary_psc.ip_cidr_range
self_link = google_compute_subnetwork.primary_psc.self_link
}
vpc = {
name = google_compute_network.network.name
Expand Down
Loading