Merge branch 'master' into sa-upload-crt
This commit is contained in:
@@ -19,12 +19,14 @@ variable "billing_account" {
|
||||
|
||||
variable "cai_config" {
|
||||
type = object({
|
||||
bq_dataset = string
|
||||
bq_table = string
|
||||
bq_dataset = string
|
||||
bq_table = string
|
||||
target_node = string
|
||||
})
|
||||
default = {
|
||||
bq_dataset = "my-dataset"
|
||||
bq_table = "my_table"
|
||||
bq_dataset = "my-dataset"
|
||||
bq_table = "my_table"
|
||||
target_node = "organization/1234567890"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ def _plan_runner():
|
||||
"Runs Terraform plan and returns parsed output."
|
||||
tf = tftest.TerraformTest(fixture_path, BASEDIR,
|
||||
os.environ.get('TERRAFORM', 'terraform'))
|
||||
tf.setup()
|
||||
tf.setup(upgrade=True)
|
||||
return tf.plan(output=True, refresh=refresh, tf_vars=tf_vars, targets=targets)
|
||||
|
||||
return run_plan
|
||||
@@ -94,7 +94,7 @@ def apply_runner():
|
||||
"Runs Terraform apply and returns parsed output"
|
||||
tf = tftest.TerraformTest(fixture_path, BASEDIR,
|
||||
os.environ.get('TERRAFORM', 'terraform'))
|
||||
tf.setup()
|
||||
tf.setup(upgrade=True)
|
||||
apply = tf.apply(tf_vars=tf_vars)
|
||||
output = tf.output(json_format=True)
|
||||
return apply, output
|
||||
|
||||
@@ -14,6 +14,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
# Used in stateful disk test
|
||||
resource "google_compute_disk" "default" {
|
||||
name = "test-disk"
|
||||
type = "pd-ssd"
|
||||
zone = "europe-west1-c"
|
||||
image = "debian-9-stretch-v20200805"
|
||||
physical_block_size_bytes = 4096
|
||||
}
|
||||
|
||||
module "test" {
|
||||
source = "../../../../modules/compute-mig"
|
||||
project_id = "my-project"
|
||||
@@ -28,6 +37,8 @@ module "test" {
|
||||
health_check_config = var.health_check_config
|
||||
named_ports = var.named_ports
|
||||
regional = var.regional
|
||||
update_policy = var.update_policy
|
||||
versions = var.versions
|
||||
stateful_config = var.stateful_config
|
||||
|
||||
update_policy = var.update_policy
|
||||
versions = var.versions
|
||||
}
|
||||
|
||||
@@ -60,6 +60,37 @@ variable "regional" {
|
||||
default = false
|
||||
}
|
||||
|
||||
variable "stateful_config" {
|
||||
description = "Stateful configuration can be done by individual instances or for all instances in the MIG. They key in per_instance_config is the name of the specific instance. The key of the stateful_disks is the 'device_name' field of the resource. Please note that device_name is defined at the OS mount level, unlike the disk name."
|
||||
type = object({
|
||||
per_instance_config = map(object({
|
||||
#name is the key
|
||||
#name = string
|
||||
stateful_disks = map(object({
|
||||
#device_name is the key
|
||||
source = string
|
||||
mode = string # READ_WRITE | READ_ONLY
|
||||
delete_rule = string # NEVER | ON_PERMANENT_INSTANCE_DELETION
|
||||
}))
|
||||
metadata = map(string)
|
||||
update_config = object({
|
||||
minimal_action = string # NONE | REPLACE | RESTART | REFRESH
|
||||
most_disruptive_allowed_action = string # REPLACE | RESTART | REFRESH | NONE
|
||||
remove_instance_state_on_destroy = bool
|
||||
})
|
||||
}))
|
||||
|
||||
mig_config = object({
|
||||
stateful_disks = map(object({
|
||||
#device_name is the key
|
||||
delete_rule = string # NEVER | ON_PERMANENT_INSTANCE_DELETION
|
||||
}))
|
||||
})
|
||||
|
||||
})
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "update_policy" {
|
||||
type = object({
|
||||
type = string # OPPORTUNISTIC | PROACTIVE
|
||||
|
||||
@@ -24,6 +24,7 @@ def test_defaults(plan_runner):
|
||||
"Test variable defaults."
|
||||
_, resources = plan_runner(FIXTURES_DIR)
|
||||
assert len(resources) == 1
|
||||
print(resources[0]['type'])
|
||||
mig = resources[0]
|
||||
assert mig['type'] == 'google_compute_instance_group_manager'
|
||||
assert mig['values']['target_size'] == 2
|
||||
@@ -35,7 +36,6 @@ def test_defaults(plan_runner):
|
||||
assert mig['values']['target_size'] == 2
|
||||
assert mig['values']['region']
|
||||
|
||||
|
||||
def test_health_check(plan_runner):
|
||||
"Test health check resource."
|
||||
health_check_config = '{type="tcp", check={port=80}, config=null, logging=false}'
|
||||
@@ -75,3 +75,81 @@ def test_autoscaler(plan_runner):
|
||||
assert len(resources) == 2
|
||||
autoscaler = resources[0]
|
||||
assert autoscaler['type'] == 'google_compute_region_autoscaler'
|
||||
|
||||
def test_stateful_mig(plan_runner):
|
||||
"Test stateful instances - mig."
|
||||
|
||||
stateful_config = (
|
||||
'{'
|
||||
'per_instance_config = {},'
|
||||
'mig_config = {'
|
||||
'stateful_disks = {'
|
||||
'persistent-disk-1 = {delete_rule="NEVER"}'
|
||||
'}'
|
||||
'}'
|
||||
'}'
|
||||
)
|
||||
_, resources = plan_runner(
|
||||
FIXTURES_DIR, stateful_config=stateful_config)
|
||||
assert len(resources) == 1
|
||||
statefuldisk = resources[0]
|
||||
assert statefuldisk['type'] == 'google_compute_instance_group_manager'
|
||||
assert statefuldisk['values']['stateful_disk'] == [{
|
||||
'device_name': 'persistent-disk-1',
|
||||
'delete_rule': 'NEVER',
|
||||
}]
|
||||
|
||||
def test_stateful_instance(plan_runner):
|
||||
"Test stateful instances - instance."
|
||||
stateful_config = (
|
||||
'{'
|
||||
'per_instance_config = {'
|
||||
'instance-1 = {'
|
||||
'stateful_disks = {'
|
||||
'persistent-disk-1 = {'
|
||||
'source = "test-disk",'
|
||||
'mode = "READ_ONLY",'
|
||||
'delete_rule= "NEVER",'
|
||||
'},'
|
||||
'},'
|
||||
'metadata = {'
|
||||
'foo = "bar"'
|
||||
'},'
|
||||
'update_config = {'
|
||||
'minimal_action = "NONE",'
|
||||
'most_disruptive_allowed_action = "REPLACE",'
|
||||
'remove_instance_state_on_destroy = false,'
|
||||
|
||||
'},'
|
||||
'},'
|
||||
'},'
|
||||
'mig_config = {'
|
||||
'stateful_disks = {'
|
||||
'persistent-disk-1 = {delete_rule="NEVER"}'
|
||||
'}'
|
||||
'}'
|
||||
'}'
|
||||
)
|
||||
_, resources = plan_runner(
|
||||
FIXTURES_DIR, stateful_config=stateful_config)
|
||||
assert len(resources) == 2
|
||||
instanceconfig = resources[0]
|
||||
assert instanceconfig['type'] == 'google_compute_instance_group_manager'
|
||||
instanceconfig = resources[1]
|
||||
assert instanceconfig['type'] == 'google_compute_per_instance_config'
|
||||
|
||||
assert instanceconfig['values']['preserved_state'] == [{
|
||||
'disk': [{
|
||||
'device_name': 'persistent-disk-1',
|
||||
'delete_rule': 'NEVER',
|
||||
'source': 'test-disk',
|
||||
'mode': 'READ_ONLY',
|
||||
}],
|
||||
'metadata': {
|
||||
'foo': 'bar'
|
||||
}
|
||||
}]
|
||||
|
||||
assert instanceconfig['values']['minimal_action'] == 'NONE'
|
||||
assert instanceconfig['values']['most_disruptive_allowed_action'] == 'REPLACE'
|
||||
assert instanceconfig['values']['remove_instance_state_on_destroy'] == False
|
||||
@@ -1,4 +1,4 @@
|
||||
pytest>=4.6.0
|
||||
PyYAML>=5.3
|
||||
tftest>=1.5.2
|
||||
tftest>=1.6.1
|
||||
marko>=0.9.1
|
||||
|
||||
Reference in New Issue
Block a user