Skip to content

Commit

Permalink
Adds tests for init and init-from-module command hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
lorengordon committed Aug 15, 2018
1 parent 3d6a6df commit b15ffe3
Show file tree
Hide file tree
Showing 9 changed files with 295 additions and 51 deletions.
3 changes: 3 additions & 0 deletions test/fixture-hooks/init-once/backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
terraform {
backend "s3" {}
}
7 changes: 7 additions & 0 deletions test/fixture-hooks/init-once/base-module/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
data "template_file" "example" {
template = "hello, world"
}

output "example" {
value = "${data.template_file.example.rendered}"
}
7 changes: 7 additions & 0 deletions test/fixture-hooks/init-once/no-source-no-backend/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
data "template_file" "example" {
template = "hello, world"
}

output "example" {
value = "${data.template_file.example.rendered}"
}
17 changes: 17 additions & 0 deletions test/fixture-hooks/init-once/no-source-no-backend/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
terragrunt = {
terraform {
# Should NOT execute. With no source, init-from-module should never execute.
# If AFTER_INIT_FROM_MODULE_ONLY_ONCE is present in output, the test failed
after_hook "after_init_from_module" {
commands = ["init-from-module"]
execute = ["echo","AFTER_INIT_FROM_MODULE_ONLY_ONCE"]
}

# SHOULD execute
# If AFTER_INIT_ONLY_ONCE is not present exactly once in output, the test failed
after_hook "after_init" {
commands = ["init"]
execute = ["echo","AFTER_INIT_ONLY_ONCE"]
}
}
}
11 changes: 11 additions & 0 deletions test/fixture-hooks/init-once/no-source-with-backend/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
terraform {
backend "s3" {}
}

data "template_file" "example" {
template = "hello, world"
}

output "example" {
value = "${data.template_file.example.rendered}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
terragrunt = {
remote_state {
backend = "s3"
config {
encrypt = true
bucket = "__FILL_IN_BUCKET_NAME__"
key = "terraform.tfstate"
region = "__FILL_IN_REGION__"
}
}

terraform {
# Should NOT execute. With no source, init-from-module should never execute.
# If AFTER_INIT_FROM_MODULE_ONLY_ONCE is present in output, the test failed
after_hook "after_init_from_module" {
commands = ["init-from-module"]
execute = ["echo","AFTER_INIT_FROM_MODULE_ONLY_ONCE"]
}

# SHOULD execute.
# If AFTER_INIT_ONLY_ONCE is not echoed exactly once, the test failed
after_hook "after_init" {
commands = ["init"]
execute = ["echo","AFTER_INIT_ONLY_ONCE"]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
terragrunt = {
terraform {
source = "../base-module"

# SHOULD execute.
# If AFTER_INIT_FROM_MODULE_ONLY_ONCE is not echoed exactly once, the test failed
after_hook "after_init_from_module" {
commands = ["init-from-module"]
execute = ["echo","AFTER_INIT_FROM_MODULE_ONLY_ONCE"]
}

# SHOULD execute.
# If AFTER_INIT_ONLY_ONCE is not echoed exactly once, the test failed
after_hook "after_init" {
commands = ["init"]
execute = ["echo","AFTER_INIT_ONLY_ONCE"]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
terragrunt = {
remote_state {
backend = "s3"
config {
encrypt = true
bucket = "__FILL_IN_BUCKET_NAME__"
key = "terraform.tfstate"
region = "__FILL_IN_REGION__"
}
}

terraform {
source = "../base-module"

after_hook "backend" {
commands = ["init-from-module"]
execute = ["cp", "${get_tfvars_dir()}/../backend.tf", "."]
}

# SHOULD execute.
# If AFTER_INIT_FROM_MODULE_ONLY_ONCE is not echoed exactly once, the test failed
after_hook "after_init_from_module" {
commands = ["init-from-module"]
execute = ["echo","AFTER_INIT_FROM_MODULE_ONLY_ONCE"]
}

# SHOULD execute.
# If AFTER_INIT_ONLY_ONCE is not echoed exactly once, the test failed
after_hook "after_init" {
commands = ["init"]
execute = ["echo","AFTER_INIT_ONLY_ONCE"]
}
}
}
221 changes: 170 additions & 51 deletions test/integration_test.go

Large diffs are not rendered by default.

0 comments on commit b15ffe3

Please sign in to comment.