Skip to content

Commit

Permalink
provider/aws: Update TestAccAWSCloudWatchEventTarget_ssmDocument / Te…
Browse files Browse the repository at this point in the history
…stAccAWSCloudWatchEventTarget_full tests to avoid name collisions
  • Loading branch information
catsby committed May 8, 2017
1 parent 1e7a791 commit 7f3307e
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions resource_aws_cloudwatch_event_target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

events "github.com/aws/aws-sdk-go/service/cloudwatchevents"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
Expand Down Expand Up @@ -65,20 +66,21 @@ func TestAccAWSCloudWatchEventTarget_missingTargetId(t *testing.T) {

func TestAccAWSCloudWatchEventTarget_full(t *testing.T) {
var target events.Target
rName := acctest.RandomWithPrefix("tf_ssm_Document")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSCloudWatchEventTargetDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSCloudWatchEventTargetConfig_full,
Config: testAccAWSCloudWatchEventTargetConfig_full(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudWatchEventTargetExists("aws_cloudwatch_event_target.foobar", &target),
resource.TestCheckResourceAttr("aws_cloudwatch_event_target.foobar", "rule", "tf-acc-cw-event-rule-full"),
resource.TestCheckResourceAttr("aws_cloudwatch_event_target.foobar", "target_id", "tf-acc-cw-target-full"),
resource.TestMatchResourceAttr("aws_cloudwatch_event_target.foobar", "arn",
regexp.MustCompile("^arn:aws:kinesis:.*:stream/terraform-kinesis-test$")),
regexp.MustCompile("^arn:aws:kinesis:.*:stream/tf_ssm_Document")),
resource.TestCheckResourceAttr("aws_cloudwatch_event_target.foobar", "input", "{ \"source\": [\"aws.cloudtrail\"] }\n"),
resource.TestCheckResourceAttr("aws_cloudwatch_event_target.foobar", "input_path", ""),
),
Expand All @@ -89,14 +91,15 @@ func TestAccAWSCloudWatchEventTarget_full(t *testing.T) {

func TestAccAWSCloudWatchEventTarget_ssmDocument(t *testing.T) {
var target events.Target
rName := acctest.RandomWithPrefix("tf_ssm_Document")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSCloudWatchEventTargetDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSCloudWatchEventTargetConfigSsmDocument,
Config: testAccAWSCloudWatchEventTargetConfigSsmDocument(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudWatchEventTargetExists("aws_cloudwatch_event_target.test", &target),
),
Expand Down Expand Up @@ -194,15 +197,16 @@ resource "aws_sns_topic" "sun" {
}
`

var testAccAWSCloudWatchEventTargetConfig_full = `
func testAccAWSCloudWatchEventTargetConfig_full(rName string) string {
return fmt.Sprintf(`
resource "aws_cloudwatch_event_rule" "foo" {
name = "tf-acc-cw-event-rule-full"
schedule_expression = "rate(1 hour)"
role_arn = "${aws_iam_role.role.arn}"
}
resource "aws_iam_role" "role" {
name = "test_role"
name = "%s"
assume_role_policy = <<POLICY
{
"Version": "2012-10-17",
Expand All @@ -221,7 +225,7 @@ POLICY
}
resource "aws_iam_role_policy" "test_policy" {
name = "test_policy"
name = "%s_policy"
role = "${aws_iam_role.role.id}"
policy = <<EOF
{
Expand Down Expand Up @@ -252,14 +256,15 @@ INPUT
}
resource "aws_kinesis_stream" "test_stream" {
name = "terraform-kinesis-test"
name = "%s_kinesis_test"
shard_count = 1
}`, rName, rName, rName)
}
`

var testAccAWSCloudWatchEventTargetConfigSsmDocument = `
func testAccAWSCloudWatchEventTargetConfigSsmDocument(rName string) string {
return fmt.Sprintf(`
resource "aws_ssm_document" "foo" {
name = "test_document-100"
name = "%s"
document_type = "Command"
content = <<DOC
Expand All @@ -284,7 +289,7 @@ DOC
}
resource "aws_cloudwatch_event_rule" "console" {
name = "another_test"
name = "%s"
description = "another_test"
event_pattern = <<PATTERN
Expand All @@ -309,7 +314,7 @@ resource "aws_cloudwatch_event_target" "test" {
}
resource "aws_iam_role" "test_role" {
name = "test_role"
name = "%s"
assume_role_policy = <<EOF
{
Expand All @@ -329,7 +334,7 @@ EOF
}
resource "aws_iam_role_policy" "test_policy" {
name = "test_policy"
name = "%s"
role = "${aws_iam_role.test_role.id}"
policy = <<EOF
Expand All @@ -346,5 +351,5 @@ resource "aws_iam_role_policy" "test_policy" {
]
}
EOF
}`, rName, rName, rName, rName)
}
`

0 comments on commit 7f3307e

Please sign in to comment.