@ -82,9 +82,56 @@ func TestAccAWSELB_fullCharacterRange(t *testing.T) {
} )
}
func TestAccAWSELB_AccessLogs ( t * testing . T ) {
func TestAccAWSELB_AccessLogs _enabled ( t * testing . T ) {
var conf elb . LoadBalancerDescription
rName := fmt . Sprintf ( "terraform-access-logs-bucket-%d" , acctest . RandInt ( ) )
resource . Test ( t , resource . TestCase {
PreCheck : func ( ) { testAccPreCheck ( t ) } ,
IDRefreshName : "aws_elb.foo" ,
Providers : testAccProviders ,
CheckDestroy : testAccCheckAWSELBDestroy ,
Steps : [ ] resource . TestStep {
resource . TestStep {
Config : testAccAWSELBAccessLogs ,
Check : resource . ComposeTestCheckFunc (
testAccCheckAWSELBExists ( "aws_elb.foo" , & conf ) ,
) ,
} ,
resource . TestStep {
Config : testAccAWSELBAccessLogsOn ( rName ) ,
Check : resource . ComposeTestCheckFunc (
testAccCheckAWSELBExists ( "aws_elb.foo" , & conf ) ,
resource . TestCheckResourceAttr (
"aws_elb.foo" , "access_logs.#" , "1" ) ,
resource . TestCheckResourceAttr (
"aws_elb.foo" , "access_logs.0.bucket" , rName ) ,
resource . TestCheckResourceAttr (
"aws_elb.foo" , "access_logs.0.interval" , "5" ) ,
resource . TestCheckResourceAttr (
"aws_elb.foo" , "access_logs.0.enabled" , "true" ) ,
) ,
} ,
resource . TestStep {
Config : testAccAWSELBAccessLogs ,
Check : resource . ComposeTestCheckFunc (
testAccCheckAWSELBExists ( "aws_elb.foo" , & conf ) ,
resource . TestCheckResourceAttr (
"aws_elb.foo" , "access_logs.#" , "0" ) ,
) ,
} ,
} ,
} )
}
func TestAccAWSELB_AccessLogs_disabled ( t * testing . T ) {
var conf elb . LoadBalancerDescription
rName := fmt . Sprintf ( "terraform-access-logs-bucket-%d" , acctest . RandInt ( ) )
resource . Test ( t , resource . TestCase {
PreCheck : func ( ) { testAccPreCheck ( t ) } ,
IDRefreshName : "aws_elb.foo" ,
@ -99,15 +146,17 @@ func TestAccAWSELB_AccessLogs(t *testing.T) {
} ,
resource . TestStep {
Config : testAccAWSELBAccessLogsOn ,
Config : testAccAWSELBAccessLogsDisabled ( rName ) ,
Check : resource . ComposeTestCheckFunc (
testAccCheckAWSELBExists ( "aws_elb.foo" , & conf ) ,
resource . TestCheckResourceAttr (
"aws_elb.foo" , "access_logs.#" , "1" ) ,
resource . TestCheckResourceAttr (
"aws_elb.foo" , "access_logs.0.bucket" , "terraform-access-logs-bucket" ) ,
"aws_elb.foo" , "access_logs.0.bucket" , rName ) ,
resource . TestCheckResourceAttr (
"aws_elb.foo" , "access_logs.0.interval" , "5" ) ,
resource . TestCheckResourceAttr (
"aws_elb.foo" , "access_logs.0.enabled" , "false" ) ,
) ,
} ,
@ -995,12 +1044,14 @@ resource "aws_elb" "foo" {
}
}
`
const testAccAWSELBAccessLogsOn = `
func testAccAWSELBAccessLogsOn ( r string ) string {
return fmt . Sprintf ( `
# an S3 bucket configured for Access logs
# The 797873946194 is the AWS ID for us - west - 2 , so this test
# must be ran in us - west - 2
resource "aws_s3_bucket" "acceslogs_bucket" {
bucket = " terraform-access-logs-bucket "
bucket = " %s "
acl = "private"
force_destroy = true
policy = << EOF
@ -1013,7 +1064,7 @@ resource "aws_s3_bucket" "acceslogs_bucket" {
"Principal" : {
"AWS" : "arn:aws:iam::797873946194:root"
} ,
"Resource" : "arn:aws:s3::: terraform-access-logs-bucket /*",
"Resource" : "arn:aws:s3::: %s /*",
"Sid" : "Stmt1446575236270"
}
] ,
@ -1037,7 +1088,55 @@ resource "aws_elb" "foo" {
bucket = "${aws_s3_bucket.acceslogs_bucket.bucket}"
}
}
`
` , r , r )
}
func testAccAWSELBAccessLogsDisabled ( r string ) string {
return fmt . Sprintf ( `
# an S3 bucket configured for Access logs
# The 797873946194 is the AWS ID for us - west - 2 , so this test
# must be ran in us - west - 2
resource "aws_s3_bucket" "acceslogs_bucket" {
bucket = "%s"
acl = "private"
force_destroy = true
policy = << EOF
{
"Id" : "Policy1446577137248" ,
"Statement" : [
{
"Action" : "s3:PutObject" ,
"Effect" : "Allow" ,
"Principal" : {
"AWS" : "arn:aws:iam::797873946194:root"
} ,
"Resource" : "arn:aws:s3:::%s/*" ,
"Sid" : "Stmt1446575236270"
}
] ,
"Version" : "2012-10-17"
}
EOF
}
resource "aws_elb" "foo" {
availability_zones = [ "us-west-2a" , "us-west-2b" , "us-west-2c" ]
listener {
instance_port = 8000
instance_protocol = "http"
lb_port = 80
lb_protocol = "http"
}
access_logs {
interval = 5
bucket = "${aws_s3_bucket.acceslogs_bucket.bucket}"
enabled = false
}
}
` , r , r )
}
const testAccAWSELBGeneratedName = `
resource "aws_elb" "foo" {