feat: add e2e test for compute-mig module (#2132)

add e2e test for compute-mig module
This commit is contained in:
andybubu 2024-03-06 21:30:20 +01:00 committed by GitHub
parent dcd54246cc
commit 105a19b9de
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 276 additions and 47 deletions

View File

@ -17,6 +17,7 @@ Stateful disks can be created directly, as shown in the last example below.
- [Stateful MIGs - Instance Config](#stateful-migs-instance-config)
- [Variables](#variables)
- [Outputs](#outputs)
- [Fixtures](#fixtures)
<!-- END TOC -->
## Examples
@ -34,7 +35,7 @@ module "nginx-template" {
source = "./fabric/modules/compute-vm"
project_id = var.project_id
name = "nginx-template"
zone = "europe-west1-b"
zone = "${var.region}-b"
tags = ["http-server", "ssh"]
network_interfaces = [{
network = var.vpc.self_link
@ -55,13 +56,13 @@ module "nginx-template" {
module "nginx-mig" {
source = "./fabric/modules/compute-mig"
project_id = "my-project"
location = "europe-west1-b"
project_id = var.project_id
location = "${var.region}-b"
name = "mig-test"
target_size = 2
instance_template = module.nginx-template.template.self_link
}
# tftest modules=2 resources=2 inventory=simple.yaml
# tftest modules=2 resources=2 inventory=simple.yaml e2e
```
### Multiple Versions
@ -77,7 +78,7 @@ module "nginx-template" {
source = "./fabric/modules/compute-vm"
project_id = var.project_id
name = "nginx-template"
zone = "europe-west1-b"
zone = "${var.region}-b"
tags = ["http-server", "ssh"]
network_interfaces = [{
network = var.vpc.self_link
@ -98,8 +99,8 @@ module "nginx-template" {
module "nginx-mig" {
source = "./fabric/modules/compute-mig"
project_id = "my-project"
location = "europe-west1-b"
project_id = var.project_id
location = "${var.region}-b"
name = "mig-test"
target_size = 3
instance_template = module.nginx-template.template.self_link
@ -112,7 +113,7 @@ module "nginx-mig" {
}
}
}
# tftest modules=2 resources=2
# tftest modules=2 resources=2 inventory=multiple.yaml e2e
```
### Health Check and Autohealing Policies
@ -128,7 +129,7 @@ module "nginx-template" {
source = "./fabric/modules/compute-vm"
project_id = var.project_id
name = "nginx-template"
zone = "europe-west1-b"
zone = "${var.region}-b"
tags = ["http-server", "ssh"]
network_interfaces = [{
network = var.vpc.self_link,
@ -149,8 +150,8 @@ module "nginx-template" {
module "nginx-mig" {
source = "./fabric/modules/compute-mig"
project_id = "my-project"
location = "europe-west1-b"
project_id = var.project_id
location = "${var.region}-b"
name = "mig-test"
target_size = 3
instance_template = module.nginx-template.template.self_link
@ -164,7 +165,7 @@ module "nginx-mig" {
}
}
}
# tftest modules=2 resources=3 inventory=health-check.yaml
# tftest modules=2 resources=3 inventory=health-check.yaml e2e
```
### Autoscaling
@ -180,7 +181,7 @@ module "nginx-template" {
source = "./fabric/modules/compute-vm"
project_id = var.project_id
name = "nginx-template"
zone = "europe-west1-b"
zone = "${var.region}-b"
tags = ["http-server", "ssh"]
network_interfaces = [{
network = var.vpc.self_link
@ -201,8 +202,8 @@ module "nginx-template" {
module "nginx-mig" {
source = "./fabric/modules/compute-mig"
project_id = "my-project"
location = "europe-west1-b"
project_id = var.project_id
location = "${var.region}-b"
name = "mig-test"
target_size = 3
instance_template = module.nginx-template.template.self_link
@ -217,7 +218,7 @@ module "nginx-mig" {
}
}
}
# tftest modules=2 resources=3 inventory=autoscaling.yaml
# tftest modules=2 resources=3 inventory=autoscaling.yaml e2e
```
### Update Policy
@ -231,7 +232,7 @@ module "nginx-template" {
source = "./fabric/modules/compute-vm"
project_id = var.project_id
name = "nginx-template"
zone = "europe-west1-b"
zone = "${var.region}-b"
tags = ["http-server", "ssh"]
network_interfaces = [{
network = var.vpc.self_link
@ -252,8 +253,8 @@ module "nginx-template" {
module "nginx-mig" {
source = "./fabric/modules/compute-mig"
project_id = "my-project"
location = "europe-west1-b"
project_id = var.project_id
location = "${var.region}-b"
name = "mig-test"
target_size = 3
instance_template = module.nginx-template.template.self_link
@ -266,7 +267,7 @@ module "nginx-mig" {
}
}
}
# tftest modules=2 resources=2
# tftest modules=2 resources=2 inventory=policy.yaml e2e
```
### Stateful MIGs - MIG Config
@ -286,9 +287,9 @@ module "cos-nginx" {
module "nginx-template" {
source = "./fabric/modules/compute-vm"
project_id = "my-prj"
project_id = var.project_id
name = "nginx-template"
zone = "europe-west8-b"
zone = "${var.region}-b"
tags = ["http-server", "ssh"]
instance_type = "e2-small"
network_interfaces = [{
@ -304,7 +305,7 @@ module "nginx-template" {
source_type = "attach"
name = "data-1"
size = 10
source = "test-data-1"
source = google_compute_disk.test-disk.name
}]
create_template = true
metadata = {
@ -314,8 +315,8 @@ module "nginx-template" {
module "nginx-mig" {
source = "./fabric/modules/compute-mig"
project_id = "my-prj"
location = "europe-west8-b"
project_id = var.project_id
location = "${var.region}-b"
name = "mig-test-2"
target_size = 1
instance_template = module.nginx-template.template.self_link
@ -323,7 +324,7 @@ module "nginx-mig" {
data-1 = false
}
}
# tftest modules=2 resources=2
# tftest modules=2 resources=3 fixtures=fixtures/attached-disks.tf inventory=mig-config.yaml e2e
```
### Stateful MIGs - Instance Config
@ -337,9 +338,9 @@ module "cos-nginx" {
module "nginx-template" {
source = "./fabric/modules/compute-vm"
project_id = "my-prj"
project_id = var.project_id
name = "nginx-template"
zone = "europe-west8-b"
zone = "${var.region}-b"
tags = ["http-server", "ssh"]
instance_type = "e2-small"
network_interfaces = [{
@ -355,7 +356,7 @@ module "nginx-template" {
source_type = "attach"
name = "data-1"
size = 10
source = "test-data-1"
source = google_compute_disk.test-disk.name
}]
create_template = true
metadata = {
@ -365,8 +366,8 @@ module "nginx-template" {
module "nginx-mig" {
source = "./fabric/modules/compute-mig"
project_id = "my-prj"
location = "europe-west8-b"
project_id = var.project_id
location = "${var.region}-b"
name = "mig-test"
instance_template = module.nginx-template.template.self_link
stateful_config = {
@ -376,7 +377,7 @@ module "nginx-mig" {
preserved_state = {
disks = {
data-1 = {
source = "projects/my-prj/zones/europe-west8-b/disks/test-data-1"
source = google_compute_disk.test-disk.id
}
}
metadata = {
@ -386,7 +387,7 @@ module "nginx-mig" {
}
}
}
# tftest modules=2 resources=3 inventory=stateful.yaml
# tftest modules=2 resources=4 fixtures=fixtures/attached-disks.tf inventory=stateful.yaml e2e
```
<!-- BEGIN TFDOC -->
## Variables
@ -421,4 +422,8 @@ module "nginx-mig" {
| [group_manager](outputs.tf#L26) | Instance group resource. | |
| [health_check](outputs.tf#L35) | Auto-created health-check resource. | |
| [id](outputs.tf#L44) | Fully qualified group manager id. | |
## Fixtures
- [attached-disks.tf](../../tests/fixtures/attached-disks.tf)
<!-- END TFDOC -->

24
tests/fixtures/attached-disks.tf vendored Normal file
View File

@ -0,0 +1,24 @@
/**
* 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.
*/
resource "google_compute_disk" "test-disk" {
project = var.project_id
name = "test-data-1"
type = "pd-balanced"
zone = "${var.region}-b"
physical_block_size_bytes = 4096
size = 10
}

View File

@ -1,4 +1,4 @@
# Copyright 2023 Google LLC
# 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.
@ -26,12 +26,37 @@ values:
mode: 'ON'
scale_in_control: []
scaling_schedules: []
description: Terraform managed.
name: mig-test
project: my-project
project: project-id
timeouts: null
zone: europe-west1-b
zone: europe-west8-b
module.nginx-mig.google_compute_instance_group_manager.default[0]:
all_instances_config: []
auto_healing_policies: []
base_instance_name: mig-test
description: Terraform managed.
list_managed_instances_results: PAGELESS
name: mig-test
named_port: []
project: project-id
stateful_disk: []
stateful_external_ip: []
stateful_internal_ip: []
target_pools: null
target_size: 3
timeouts: null
version:
- name: default
target_size: []
wait_for_instances: false
wait_for_instances_status: STABLE
zone: europe-west8-b
counts:
google_compute_autoscaler: 1
google_compute_instance_group_manager: 1
google_compute_instance_template: 1
modules: 2
resources: 3

View File

@ -1,4 +1,4 @@
# Copyright 2023 Google LLC
# 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.
@ -15,6 +15,7 @@
values:
module.nginx-mig.google_compute_health_check.default[0]:
check_interval_sec: 5
description: Terraform managed.
grpc_health_check: []
healthy_threshold: 2
http2_health_check: []
@ -30,14 +31,39 @@ values:
log_config:
- enable: true
name: mig-test
project: my-project
project: project-id
ssl_health_check: []
tcp_health_check: []
timeout_sec: 5
timeouts: null
unhealthy_threshold: 2
module.nginx-mig.google_compute_instance_group_manager.default[0]:
all_instances_config: []
auto_healing_policies:
- initial_delay_sec: 30
base_instance_name: mig-test
description: Terraform managed.
list_managed_instances_results: PAGELESS
name: mig-test
named_port: []
project: project-id
stateful_disk: []
stateful_external_ip: []
stateful_internal_ip: []
target_pools: null
target_size: 3
timeouts: null
version:
- name: default
target_size: []
wait_for_instances: false
wait_for_instances_status: STABLE
zone: europe-west8-b
counts:
google_compute_health_check: 1
google_compute_instance_group_manager: 1
google_compute_instance_template: 1
modules: 2
resources: 3

View File

@ -0,0 +1,47 @@
# 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.
values:
module.nginx-mig.google_compute_instance_group_manager.default[0]:
all_instances_config: []
auto_healing_policies: []
base_instance_name: mig-test-2
description: Terraform managed.
list_managed_instances_results: PAGELESS
name: mig-test-2
named_port: []
project: project-id
stateful_disk:
- delete_rule: NEVER
device_name: data-1
stateful_external_ip: []
stateful_internal_ip: []
target_pools: null
target_size: 1
timeouts: null
version:
- name: default
target_size: []
wait_for_instances: false
wait_for_instances_status: STABLE
zone: europe-west8-b
counts:
google_compute_disk: 1
google_compute_instance_group_manager: 1
google_compute_instance_template: 1
modules: 2
resources: 3

View File

@ -0,0 +1,47 @@
# 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.
values:
module.nginx-mig.google_compute_instance_group_manager.default[0]:
all_instances_config: []
auto_healing_policies: []
base_instance_name: mig-test
description: Terraform managed.
list_managed_instances_results: PAGELESS
name: mig-test
named_port: []
project: project-id
stateful_disk: []
stateful_external_ip: []
stateful_internal_ip: []
target_pools: null
target_size: 3
timeouts: null
version:
- name: default
target_size: []
- name: canary
target_size:
- fixed: 1
percent: null
wait_for_instances: false
wait_for_instances_status: STABLE
zone: europe-west8-b
counts:
google_compute_instance_group_manager: 1
google_compute_instance_template: 1
modules: 2
resources: 2

View File

@ -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.
values:
module.nginx-mig.google_compute_instance_group_manager.default[0]:
all_instances_config: []
auto_healing_policies: []
base_instance_name: mig-test
description: Terraform managed.
list_managed_instances_results: PAGELESS
name: mig-test
named_port: []
project: project-id
stateful_disk: []
stateful_external_ip: []
stateful_internal_ip: []
target_pools: null
target_size: 3
timeouts: null
update_policy:
- max_surge_fixed: 1
max_surge_percent: null
max_unavailable_percent: null
min_ready_sec: 30
minimal_action: REPLACE
most_disruptive_allowed_action: null
replacement_method: null
type: PROACTIVE
version:
- name: default
target_size: []
wait_for_instances: false
wait_for_instances_status: STABLE
zone: europe-west8-b
counts:
google_compute_instance_group_manager: 1
google_compute_instance_template: 1
modules: 2
resources: 2

View File

@ -1,4 +1,4 @@
# Copyright 2023 Google LLC
# 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.
@ -16,9 +16,9 @@ values:
module.nginx-mig.google_compute_instance_group_manager.default[0]:
base_instance_name: mig-test
name: mig-test
project: my-project
project: project-id
target_size: 2
zone: europe-west1-b
zone: europe-west8-b
counts:
google_compute_instance_group_manager: 1

View File

@ -1,4 +1,4 @@
# Copyright 2023 Google LLC
# 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.
@ -21,7 +21,7 @@ values:
list_managed_instances_results: PAGELESS
name: mig-test
named_port: []
project: my-prj
project: project-id
stateful_disk: []
stateful_external_ip: []
stateful_internal_ip: []
@ -43,19 +43,22 @@ values:
- delete_rule: NEVER
device_name: data-1
mode: READ_WRITE
source: projects/my-prj/zones/europe-west8-b/disks/test-data-1
external_ip: []
internal_ip: []
metadata:
foo: bar
project: my-prj
project: project-id
remove_instance_on_destroy: false
remove_instance_state_on_destroy: false
timeouts: null
zone: europe-west8-b
counts:
google_compute_disk: 1
google_compute_instance_group_manager: 1
google_compute_instance_template: 1
google_compute_per_instance_config: 1
modules: 2
resources: 3
resources: 4
outputs: {}