Skip to content

Commit

Permalink
add test for SNS topic
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Kania committed Jun 5, 2020
1 parent 7ad2ba4 commit 721517c
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
36 changes: 36 additions & 0 deletions examples/sns-topic/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#
# AWS Config Logs Bucket
#

module "config_logs" {
source = "trussworks/logs/aws"
version = "~> 5"

s3_bucket_name = var.config_logs_bucket
region = var.region
allow_config = true
config_logs_prefix = "config"
force_destroy = true
}

#
# SNS Topic
#

resource "aws_sns_topic" "config" {
name = var.config_name
}

module "config" {
source = "../../"

config_name = var.config_name
config_logs_bucket = module.config_logs.aws_logs_bucket
config_logs_prefix = "config"
config_sns_topic_arn = aws_sns_topic.config.arn

tags = {
"Automation" = "Terraform"
"Name" = var.config_name
}
}
12 changes: 12 additions & 0 deletions examples/sns-topic/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
variable "config_name" {
type = string
}

variable "config_logs_bucket" {
type = string
}

variable "region" {
type = string
}

29 changes: 29 additions & 0 deletions test/terraform_aws_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,32 @@ func TestRequiredTags(t *testing.T) {
assert.NotEmpty(t, requiredTagsRuleARN)

}

func TestSnsTopic(t *testing.T) {
t.Parallel()

tempTestFolder := test_structure.CopyTerraformFolderToTemp(t, "../", "examples/sns-topic")

configName := fmt.Sprintf("aws-config-%s", strings.ToLower(random.UniqueId()))
expectedConfigLogsBucket := fmt.Sprintf("terratest-%s", configName)

// AWS only supports one configuration recorder per region.
// Each test will need to specify a different region.
awsRegion := "eu-west-2"

terraformOptions := &terraform.Options{
TerraformDir: tempTestFolder,
Vars: map[string]interface{}{
"region": awsRegion,
"config_logs_bucket": expectedConfigLogsBucket,
"config_name": configName,
},
EnvVars: map[string]string{
"AWS_DEFAULT_REGION": awsRegion,
},
}

defer terraform.Destroy(t, terraformOptions)

terraform.InitAndApply(t, terraformOptions)
}

0 comments on commit 721517c

Please sign in to comment.