Skip to content

Commit

Permalink
resource/aws_cloudtrail: Replace GetOk with GetOkExists (#2817)
Browse files Browse the repository at this point in the history
* Replace GetOk with GetOkExists

* update
  • Loading branch information
atsushi-ishibashi authored and radeksimko committed Feb 12, 2018
1 parent b64bcdb commit caf0d81
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion aws/resource_aws_cloudtrail.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func resourceAwsCloudTrailCreate(d *schema.ResourceData, meta interface{}) error
if v, ok := d.GetOk("cloud_watch_logs_role_arn"); ok {
input.CloudWatchLogsRoleArn = aws.String(v.(string))
}
if v, ok := d.GetOk("include_global_service_events"); ok {
if v, ok := d.GetOkExists("include_global_service_events"); ok {
input.IncludeGlobalServiceEvents = aws.Bool(v.(bool))
}
if v, ok := d.GetOk("is_multi_region_trail"); ok {
Expand Down
61 changes: 61 additions & 0 deletions aws/resource_aws_cloudtrail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,26 @@ func testAccAWSCloudTrail_tags(t *testing.T) {
})
}

func TestAccAWSCloudTrail_include_global_service_events(t *testing.T) {
var trail cloudtrail.Trail
cloudTrailRandInt := acctest.RandInt()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSCloudTrailDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSCloudTrailConfig_include_global_service_events(cloudTrailRandInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudTrailExists("aws_cloudtrail.foobar", &trail),
resource.TestCheckResourceAttr("aws_cloudtrail.foobar", "include_global_service_events", "false"),
),
},
},
})
}

func testAccCheckCloudTrailExists(n string, trail *cloudtrail.Trail) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -937,6 +957,47 @@ POLICY
}
`

func testAccAWSCloudTrailConfig_include_global_service_events(cloudTrailRandInt int) string {
return fmt.Sprintf(`
resource "aws_cloudtrail" "foobar" {
name = "tf-trail-foobar-%d"
s3_bucket_name = "${aws_s3_bucket.foo.id}"
include_global_service_events = false
}
resource "aws_s3_bucket" "foo" {
bucket = "tf-test-trail-%d"
force_destroy = true
policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AWSCloudTrailAclCheck",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetBucketAcl",
"Resource": "arn:aws:s3:::tf-test-trail-%d"
},
{
"Sid": "AWSCloudTrailWrite",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::tf-test-trail-%d/*",
"Condition": {
"StringEquals": {
"s3:x-amz-acl": "bucket-owner-full-control"
}
}
}
]
}
POLICY
}
`, cloudTrailRandInt, cloudTrailRandInt, cloudTrailRandInt, cloudTrailRandInt)
}

func testAccAWSCloudTrailConfig_tags(cloudTrailRandInt int) string {
tagsString := `tags {
Foo = "moo"
Expand Down

0 comments on commit caf0d81

Please sign in to comment.