Skip to content

Commit

Permalink
update test cases (#65)
Browse files Browse the repository at this point in the history
* update test cases

* update go mdo

* update go mod / sum

* go get github.com/gruntwork-io/terratest/modules/[email protected]

* update tests

* update other tests, add enabled: false test

* add context

* Pass context to submodules

* enabled false in new fixtures

* update hcl

* Revert "enabled false in new fixtures"

This reverts commit 10f2353.

* Update main.tf

* Revert "Update main.tf"

This reverts commit dabb77a.

* remove enabled

* Update main.tf

* remove enabled from fixtures

* Revert "Update main.tf"

This reverts commit 090e468.

---------

Co-authored-by: Igor Rodionov <[email protected]>
  • Loading branch information
Benbentwo and goruha authored Jul 22, 2024
1 parent ed685ab commit cf9d57e
Show file tree
Hide file tree
Showing 37 changed files with 2,677 additions and 50 deletions.
2 changes: 2 additions & 0 deletions examples/advanced_features/api_integration.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ module "api_integration" {
type = "AmazonSns"
owner_team_id = module.team.team_id
}

context = module.this.context
}
2 changes: 2 additions & 0 deletions examples/advanced_features/integration_action.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ module "integration_action" {
}
]
}

context = module.this.context
}
2 changes: 2 additions & 0 deletions examples/advanced_features/team.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ module "team" {
description = "${module.this.id} Security Team"
ignore_members = false
}

context = module.this.context
}
4 changes: 4 additions & 0 deletions examples/alert_policy/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ module "alert_policy" {
]
}
}

context = module.this.context
}

module "team" {
Expand All @@ -44,4 +46,6 @@ module "team" {
name = module.this.id
description = "team-description"
}

context = module.this.context
}
1 change: 0 additions & 1 deletion examples/api_integration/fixtures.tfvars
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
enabled = true
namespace = "eg"
name = "api-integration"
stage = "test"
4 changes: 4 additions & 0 deletions examples/api_integration/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module "team" {
team = {
name = module.this.id
}

context = module.this.context
}

module "api_integration" {
Expand All @@ -18,4 +20,6 @@ module "api_integration" {
type = "AmazonSns"
owner_team_id = module.team.team_id
}

context = module.this.context
}
1 change: 1 addition & 0 deletions examples/complete/api_integration.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ module "api_integration" {
type = "AmazonSns"
owner_team_id = module.team.team_id
}
context = module.this.context
}
2 changes: 2 additions & 0 deletions examples/complete/escalation.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ module "escalation" {
}]
}
}

context = module.this.context
}
1 change: 0 additions & 1 deletion examples/complete/fixtures.tfvars
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
enabled = true
namespace = "eg"
name = "incident-management-workflow"
stage = "test"
2 changes: 2 additions & 0 deletions examples/complete/service.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ module "service" {
description = "Frontend service"
team_id = module.team.team_id
}

context = module.this.context
}
2 changes: 2 additions & 0 deletions examples/complete/service_incident_rule.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ module "service_incident_rule" {
}
}
}

context = module.this.context
}
2 changes: 2 additions & 0 deletions examples/complete/team.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module "team" {
description = "team-description"
ignore_members = false
}
context = module.this.context
}

module "sub_team" {
Expand All @@ -15,4 +16,5 @@ module "sub_team" {
name = "${module.this.id}.team"
description = "sub-team-description"
}
context = module.this.context
}
2 changes: 2 additions & 0 deletions examples/complete/team_routing_rule.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ module "team_routing_rule" {
id = module.escalation.escalation_id
}]
}

context = module.this.context
}
2 changes: 2 additions & 0 deletions examples/complete/user.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ module "user" {
locale = "en_US"
timezone = "America/New_York"
}

context = module.this.context
}
2 changes: 2 additions & 0 deletions examples/config/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ module "opsgenie_config" {
source = "../../modules/config"

opsgenie_resources = local.opsgenie_resources

context = module.this.context
}
6 changes: 6 additions & 0 deletions examples/escalation/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ module "owner_team" {
name = "owner-team"
description = "owner-team-description"
}

context = module.this.context
}

module "escalation_team" {
Expand All @@ -18,6 +20,8 @@ module "escalation_team" {
name = "escalation-team"
description = "owner-team-description"
}

context = module.this.context
}

module "escalation" {
Expand All @@ -34,4 +38,6 @@ module "escalation" {
}]
}
}

context = module.this.contexts
}
6 changes: 6 additions & 0 deletions examples/integration_action/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module "team" {
team = {
name = module.this.id
}

context = module.this.context
}

module "api_integration" {
Expand All @@ -18,6 +20,8 @@ module "api_integration" {
type = "AmazonSns"
owner_team_id = module.team.team_id
}

context = module.this.context
}

module "integration_action" {
Expand Down Expand Up @@ -45,4 +49,6 @@ module "integration_action" {
}
]
}

context = module.this.context
}
4 changes: 4 additions & 0 deletions examples/notification_policy/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ module "team" {
name = "owner-team"
description = "owner-team-description"
}

context = module.this.context
}

module "notification_policy" {
Expand All @@ -32,4 +34,6 @@ module "notification_policy" {
time_amount = 5
}
}

context = module.this.context
}
6 changes: 6 additions & 0 deletions examples/schedule/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ module "owner_team" {
name = "owner-team"
description = "owner-team-description"
}

context = module.this.context
}

module "team_schedule" {
Expand All @@ -20,6 +22,8 @@ module "team_schedule" {
description = "team-schedule-description"
owner_team_id = module.owner_team.team_id
}

context = module.this.context
}

module "schedule" {
Expand All @@ -30,4 +34,6 @@ module "schedule" {
name = module.this.id
description = "schedule-description"
}

context = module.this.context
}
2 changes: 2 additions & 0 deletions examples/team/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ module "team" {
name = module.this.id
description = "team-description"
}

context = module.this.context
}
8 changes: 8 additions & 0 deletions examples/team_routing_rule/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ module "escalation_team" {
name = "escalation-team"
description = "owner-team-description"
}

context = module.this.context
}

module "escalation" {
Expand All @@ -25,6 +27,8 @@ module "escalation" {
}]
}
}

context = module.this.context
}

module "owner_team" {
Expand All @@ -34,6 +38,8 @@ module "owner_team" {
name = "owner-team"
description = "owner-team-description"
}

context = module.this.context
}

module "team_routing_rule" {
Expand All @@ -60,4 +66,6 @@ module "team_routing_rule" {
}
}
}

context = module.this.context
}
2 changes: 2 additions & 0 deletions examples/user/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ module "user" {
locale = "en_US"
timezone = "America/New_York"
}

context = module.this.context
}
14 changes: 12 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,68 @@ module "alert_policy" {
source = "./modules/alert_policy"

alert_policy = var.alert_policy
context = module.this.context
}

module "api_integration" {
source = "./modules/api_integration"

api_integration = var.api_integration
context = module.this.context
}

module "escalation" {
source = "./modules/escalation"

escalation = var.escalation
context = module.this.context
}

module "integration_action" {
source = "./modules/integration_action"

integration_action = var.integration_action
context = module.this.context
}

module "notification_policy" {
source = "./modules/notification_policy"

notification_policy = var.notification_policy
context = module.this.context
}

module "team" {
source = "./modules/team"

team = var.team
team = var.team
context = module.this.context
}

module "team_routing_rule" {
source = "./modules/team_routing_rule"

team_routing_rule = var.team_routing_rule
context = module.this.context
}

module "user" {
source = "./modules/user"

user = var.user
user = var.user
context = module.this.context
}

module "service" {
source = "./modules/service"

service = var.service
context = module.this.context
}

module "service_incident_rule" {
source = "./modules/service_incident_rule"

service_incident_rule = var.service_incident_rule
context = module.this.context
}
23 changes: 19 additions & 4 deletions test/src/examples_advanced_features.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
package test

import (
"github.com/gruntwork-io/terratest/modules/random"
"github.com/gruntwork-io/terratest/modules/terraform"
testStructure "github.com/gruntwork-io/terratest/modules/test-structure"
"strings"
"testing"
)


// Test the Terraform module in examples/advanced_features using Terratest.
func TestExamplesAdvancedFeatures(t *testing.T) {
t.Parallel()
randID := strings.ToLower(random.UniqueId())
attributes := []string{randID}

rootFolder := "../../"
terraformFolderRelativeToRoot := "examples/advanced_features"
varFiles := []string{"fixtures.tfvars"}

tempTestFolder := testStructure.CopyTerraformFolderToTemp(t, rootFolder, terraformFolderRelativeToRoot)

terraformOptions := &terraform.Options{
// The path to where our Terraform code is located
TerraformDir: "../../examples/advanced_features",
TerraformDir: tempTestFolder,
Upgrade: true,
// Variables to pass to our Terraform code using -var-file options
VarFiles: []string{"fixtures.tfvars"},
VarFiles: varFiles,
Vars: map[string]interface{}{
"attributes": attributes,
},
}

// At the end of the test, run `terraform destroy` to clean up any resources that were created
defer terraform.Destroy(t, terraformOptions)
defer cleanup(t, terraformOptions, tempTestFolder)

// This will run `terraform init` and `terraform apply` and fail the test if there are any errors
terraform.InitAndApply(t, terraformOptions)
Expand Down
Loading

0 comments on commit cf9d57e

Please sign in to comment.