Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(resource_vpc_flow_log): logformat field added #10174

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions aws/resource_aws_flow_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ func resourceAwsFlowLog() *schema.Resource {
Required: true,
ForceNew: true,
},

"log_format": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
},
}
}
Expand Down Expand Up @@ -134,6 +140,9 @@ func resourceAwsLogFlowCreate(d *schema.ResourceData, meta interface{}) error {
if v, ok := d.GetOk("log_group_name"); ok && v != "" {
opts.LogGroupName = aws.String(v.(string))
}
if v, ok := d.GetOk("log_format"); ok && v != "" {
opts.LogFormat = aws.String(v.(string))
}

log.Printf(
"[DEBUG] Flow Log Create configuration: %s", opts)
Expand Down
78 changes: 78 additions & 0 deletions aws/resource_aws_flow_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,38 @@ func TestAccAWSFlowLog_VPCID(t *testing.T) {
})
}

func TestAccAWSFlowLog_LogFormat(t *testing.T) {
var flowLog ec2.FlowLog
resourceName := "aws_flow_log.test"
rName := acctest.RandomWithPrefix("tf-acc-test")
logFormat := "${version} ${vpc-id} ${subnet-id}"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckFlowLogDestroy,
Steps: []resource.TestStep{
{
Config: testAccFlowLogConfig_LogFormat(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckFlowLogExists(resourceName, &flowLog),
testAccCheckAWSFlowLogAttributes(&flowLog),
resource.TestCheckResourceAttr(resourceName, "log_format", logFormat),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccFlowLogConfig_LogDestinationType_CloudWatchLogs(rName),
ExpectNonEmptyPlan: false,
},
},
})
}

func TestAccAWSFlowLog_SubnetID(t *testing.T) {
var flowLog ec2.FlowLog
cloudwatchLogGroupResourceName := "aws_cloudwatch_log_group.test"
Expand Down Expand Up @@ -406,3 +438,49 @@ resource "aws_flow_log" "test" {
}
`, rName, rName, rName)
}
func testAccFlowLogConfig_LogFormat(rName string) string {
return fmt.Sprintf(`
resource "aws_vpc" "test" {
cidr_block = "10.0.0.0/16"

tags = {
Name = %q
}
}

resource "aws_iam_role" "test" {
name = %q

assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"ec2.amazonaws.com"
]
},
"Action": [
"sts:AssumeRole"
]
}
]
}
EOF
}

resource "aws_cloudwatch_log_group" "test" {
name = %q
}

resource "aws_flow_log" "test" {
iam_role_arn = "${aws_iam_role.test.arn}"
log_group_name = "${aws_cloudwatch_log_group.test.name}"
traffic_type = "ALL"
vpc_id = "${aws_vpc.test.id}"
log_format = "${version} ${vpc-id} ${subnet-id}"
}
`, rName, rName, rName)
}