Skip to content

Commit

Permalink
fix: update based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ericyz committed Mar 13, 2023
1 parent 9dc86ba commit cdcf03f
Show file tree
Hide file tree
Showing 24 changed files with 296 additions and 373 deletions.
2 changes: 1 addition & 1 deletion .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,4 @@ suites:
driver:
name: terraform
command_timeout: 1800
root_module_directory: test/fixtures/mig/stateful
root_module_directory: test/fixtures/mig_stateful
4 changes: 2 additions & 2 deletions autogen/main.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ resource "google_compute_region_instance_group_manager" "{{ module_name }}" {
}

dynamic "stateful_internal_ip" {
for_each = var.stateful_internal_ips
for_each = [for static_ip in var.stateful_ips: static_ip if static_ip["is_external"] == false]
content {
interface_name = stateful_internal_ip.value.interface_name
delete_rule = lookup(stateful_internal_ip.value, "delete_rule", null)
}
}

dynamic "stateful_external_ip" {
for_each = var.stateful_external_ips
for_each = [for static_ip in var.stateful_ips: static_ip if static_ip["is_external"] == true]
content {
interface_name = stateful_external_ip.value.interface_name
delete_rule = lookup(stateful_external_ip.value, "delete_rule", null)
Expand Down
14 changes: 3 additions & 11 deletions autogen/variables.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,12 @@ variable "stateful_disks" {
#################
# Stateful IPs
#################
variable "stateful_internal_ips" {
description = "Internal IPs created on the instances that will be preserved on instance delete. https://cloud.google.com/compute/docs/instance-groups/configuring-stateful-ip-addresses-in-migs"
type = list(object({
interface_name = string
delete_rule = string
}))
default = []
}

variable "stateful_external_ips" {
description = "External IPs created on the instances that will be preserved on instance delete. https://cloud.google.com/compute/docs/instance-groups/configuring-stateful-ip-addresses-in-migs"
variable "stateful_ips" {
description = "Statful IPs created on the instances that will be preserved on instance delete. https://cloud.google.com/compute/docs/instance-groups/configuring-stateful-ip-addresses-in-migs"
type = list(object({
interface_name = string
delete_rule = string
is_external = bool
}))
default = []
}
Expand Down
429 changes: 213 additions & 216 deletions build/int.cloudbuild.yaml

Large diffs are not rendered by default.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ module "mig" {
target_size = var.target_size
hostname = "mig-stateful"
instance_template = module.instance_template.self_link
stateful_internal_ips = [{
stateful_ips = [{
interface_name = "nic0"
delete_rule = "ON_PERMANENT_INSTANCE_DELETION"
is_external = true
}]

update_policy = [{
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions modules/mig/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ The current version is 2.X. The following guides are available to assist with up
| region | The GCP region where the managed instance group resides. | `string` | n/a | yes |
| scaling\_schedules | Autoscaling, scaling schedule block. https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_autoscaler#scaling_schedules | <pre>list(object({<br> disabled = bool<br> duration_sec = number<br> min_required_replicas = number<br> name = string<br> schedule = string<br> time_zone = string<br> }))</pre> | `[]` | no |
| stateful\_disks | Disks created on the instances that will be preserved on instance delete. https://cloud.google.com/compute/docs/instance-groups/configuring-stateful-disks-in-migs | <pre>list(object({<br> device_name = string<br> delete_rule = string<br> }))</pre> | `[]` | no |
| stateful\_external\_ips | External IPs created on the instances that will be preserved on instance delete. https://cloud.google.com/compute/docs/instance-groups/configuring-stateful-ip-addresses-in-migs | <pre>list(object({<br> interface_name = string<br> delete_rule = string<br> }))</pre> | `[]` | no |
| stateful\_internal\_ips | Internal IPs created on the instances that will be preserved on instance delete. https://cloud.google.com/compute/docs/instance-groups/configuring-stateful-ip-addresses-in-migs | <pre>list(object({<br> interface_name = string<br> delete_rule = string<br> }))</pre> | `[]` | no |
| stateful\_ips | Statful IPs created on the instances that will be preserved on instance delete. https://cloud.google.com/compute/docs/instance-groups/configuring-stateful-ip-addresses-in-migs | <pre>list(object({<br> interface_name = string<br> delete_rule = string<br> is_external = bool<br> }))</pre> | `[]` | no |
| target\_pools | The target load balancing pools to assign this group to. | `list(string)` | `[]` | no |
| target\_size | The target number of running instances for this managed instance group. This value should always be explicitly set unless this resource is attached to an autoscaler, in which case it should never be set. | `number` | `1` | no |
| update\_policy | The rolling update policy. https://www.terraform.io/docs/providers/google/r/compute_region_instance_group_manager#rolling_update_policy | <pre>list(object({<br> max_surge_fixed = number<br> instance_redistribution_type = string<br> max_surge_percent = number<br> max_unavailable_fixed = number<br> max_unavailable_percent = number<br> min_ready_sec = number<br> replacement_method = string<br> minimal_action = string<br> type = string<br> }))</pre> | `[]` | no |
Expand Down
4 changes: 2 additions & 2 deletions modules/mig/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ resource "google_compute_region_instance_group_manager" "mig" {
}

dynamic "stateful_internal_ip" {
for_each = var.stateful_internal_ips
for_each = [for static_ip in var.stateful_ips : static_ip if static_ip["is_external"] == false]
content {
interface_name = stateful_internal_ip.value.interface_name
delete_rule = lookup(stateful_internal_ip.value, "delete_rule", null)
}
}

dynamic "stateful_external_ip" {
for_each = var.stateful_external_ips
for_each = [for static_ip in var.stateful_ips : static_ip if static_ip["is_external"] == true]
content {
interface_name = stateful_external_ip.value.interface_name
delete_rule = lookup(stateful_external_ip.value, "delete_rule", null)
Expand Down
14 changes: 3 additions & 11 deletions modules/mig/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,12 @@ variable "stateful_disks" {
#################
# Stateful IPs
#################
variable "stateful_internal_ips" {
description = "Internal IPs created on the instances that will be preserved on instance delete. https://cloud.google.com/compute/docs/instance-groups/configuring-stateful-ip-addresses-in-migs"
type = list(object({
interface_name = string
delete_rule = string
}))
default = []
}

variable "stateful_external_ips" {
description = "External IPs created on the instances that will be preserved on instance delete. https://cloud.google.com/compute/docs/instance-groups/configuring-stateful-ip-addresses-in-migs"
variable "stateful_ips" {
description = "Statful IPs created on the instances that will be preserved on instance delete. https://cloud.google.com/compute/docs/instance-groups/configuring-stateful-ip-addresses-in-migs"
type = list(object({
interface_name = string
delete_rule = string
is_external = bool
}))
default = []
}
Expand Down
3 changes: 1 addition & 2 deletions modules/mig_with_percent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ The current version is 2.X. The following guides are available to assist with up
| region | The GCP region where the managed instance group resides. | `string` | n/a | yes |
| scaling\_schedules | Autoscaling, scaling schedule block. https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_autoscaler#scaling_schedules | <pre>list(object({<br> disabled = bool<br> duration_sec = number<br> min_required_replicas = number<br> name = string<br> schedule = string<br> time_zone = string<br> }))</pre> | `[]` | no |
| stateful\_disks | Disks created on the instances that will be preserved on instance delete. https://cloud.google.com/compute/docs/instance-groups/configuring-stateful-disks-in-migs | <pre>list(object({<br> device_name = string<br> delete_rule = string<br> }))</pre> | `[]` | no |
| stateful\_external\_ips | External IPs created on the instances that will be preserved on instance delete. https://cloud.google.com/compute/docs/instance-groups/configuring-stateful-ip-addresses-in-migs | <pre>list(object({<br> interface_name = string<br> delete_rule = string<br> }))</pre> | `[]` | no |
| stateful\_internal\_ips | Internal IPs created on the instances that will be preserved on instance delete. https://cloud.google.com/compute/docs/instance-groups/configuring-stateful-ip-addresses-in-migs | <pre>list(object({<br> interface_name = string<br> delete_rule = string<br> }))</pre> | `[]` | no |
| stateful\_ips | Statful IPs created on the instances that will be preserved on instance delete. https://cloud.google.com/compute/docs/instance-groups/configuring-stateful-ip-addresses-in-migs | <pre>list(object({<br> interface_name = string<br> delete_rule = string<br> is_external = bool<br> }))</pre> | `[]` | no |
| target\_pools | The target load balancing pools to assign this group to. | `list(string)` | `[]` | no |
| target\_size | The target number of running instances for this managed instance group. This value should always be explicitly set unless this resource is attached to an autoscaler, in which case it should never be set. | `number` | `1` | no |
| update\_policy | The rolling update policy. https://www.terraform.io/docs/providers/google/r/compute_region_instance_group_manager#rolling_update_policy | <pre>list(object({<br> max_surge_fixed = number<br> instance_redistribution_type = string<br> max_surge_percent = number<br> max_unavailable_fixed = number<br> max_unavailable_percent = number<br> min_ready_sec = number<br> replacement_method = string<br> minimal_action = string<br> type = string<br> }))</pre> | `[]` | no |
Expand Down
4 changes: 2 additions & 2 deletions modules/mig_with_percent/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ resource "google_compute_region_instance_group_manager" "mig_with_percent" {
}

dynamic "stateful_internal_ip" {
for_each = var.stateful_internal_ips
for_each = [for static_ip in var.stateful_ips : static_ip if static_ip["is_external"] == false]
content {
interface_name = stateful_internal_ip.value.interface_name
delete_rule = lookup(stateful_internal_ip.value, "delete_rule", null)
}
}

dynamic "stateful_external_ip" {
for_each = var.stateful_external_ips
for_each = [for static_ip in var.stateful_ips : static_ip if static_ip["is_external"] == true]
content {
interface_name = stateful_external_ip.value.interface_name
delete_rule = lookup(stateful_external_ip.value, "delete_rule", null)
Expand Down
14 changes: 3 additions & 11 deletions modules/mig_with_percent/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,12 @@ variable "stateful_disks" {
#################
# Stateful IPs
#################
variable "stateful_internal_ips" {
description = "Internal IPs created on the instances that will be preserved on instance delete. https://cloud.google.com/compute/docs/instance-groups/configuring-stateful-ip-addresses-in-migs"
type = list(object({
interface_name = string
delete_rule = string
}))
default = []
}

variable "stateful_external_ips" {
description = "External IPs created on the instances that will be preserved on instance delete. https://cloud.google.com/compute/docs/instance-groups/configuring-stateful-ip-addresses-in-migs"
variable "stateful_ips" {
description = "Statful IPs created on the instances that will be preserved on instance delete. https://cloud.google.com/compute/docs/instance-groups/configuring-stateful-ip-addresses-in-migs"
type = list(object({
interface_name = string
delete_rule = string
is_external = bool
}))
default = []
}
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/mig/stateful/network.tf

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

module "mig_stateful" {
source = "../../../../examples/mig/stateful"
source = "../../../examples/mig_stateful"
project_id = var.project_id
subnetwork = google_compute_subnetwork.main.name
target_size = 3
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/mig_stateful/network.tf
File renamed without changes.
File renamed without changes.
File renamed without changes.
87 changes: 0 additions & 87 deletions test/integration/mig_stateful/controls/mig_stateful.rb

This file was deleted.

23 changes: 0 additions & 23 deletions test/integration/mig_stateful/inspec.yml

This file was deleted.

61 changes: 61 additions & 0 deletions test/integration/mig_stateful/mig_stateful_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2021 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.

package mig_stateful

import (
"fmt"
"testing"

"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/gcloud"
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft"
"github.com/stretchr/testify/assert"
)

func TestMigStatefulModule(t *testing.T) {

const instanceGroupNamePrefix = "mig-stateful"
zoneIns := map[string]string{
"mig-stateful-001": "us-central1-a",
"mig-stateful-002": "us-central1-b",
"mig-stateful-003": "us-central1-c",
"mig-stateful-004": "us-central1-f",
}

expected_instance_groups := 1

migStatefulT := tft.NewTFBlueprintTest(t)
migStatefulT.DefineVerify(func(assert *assert.Assertions) {
migStatefulT.DefaultVerify(assert)

instances := gcloud.Run(t, fmt.Sprintf("compute instances list --project %s --filter name~%s", migStatefulT.GetStringOutput("project_id"), instanceGroupNamePrefix))
assert.Equal(len(zoneIns), len(instances.Array()), "found 4 gce instances")

for _, instance := range instances.Array() {
instanceName := instance.Get("name").String()
assert.Contains(instance.Get("zone").String(), zoneIns[instanceName], fmt.Sprintf("%s is in the right zone", instanceName))
}

instanceGroups := gcloud.Run(t, fmt.Sprintf("compute instance-groups list --project %s --filter name~%s", migStatefulT.GetStringOutput("project_id"), instanceGroupNamePrefix))
assert.Equal(expected_instance_groups, len(instanceGroups.Array()), "found 1 gce instance group")

managedInstanceGroups := gcloud.Run(t, fmt.Sprintf("compute instance-groups managed list --project %s --filter name~%s", migStatefulT.GetStringOutput("project_id"), instanceGroupNamePrefix))
assert.Equal(expected_instance_groups, len(managedInstanceGroups.Array()), "found 1 gce managed instance group")
for _, mig := range managedInstanceGroups.Array() {
assert.Contains(true, mig.Get("status").Get("stateful").Get("hasStatefulConfig").Bool(), fmt.Sprintf("%s has stateful config", mig.Get("name").String()))
}

})
migStatefulT.Test()
}

0 comments on commit cdcf03f

Please sign in to comment.