provider/aws: aws_flow_log id-only

This commit is contained in:
Mitchell Hashimoto 2016-04-20 17:45:57 -07:00
parent 54e119d32d
commit 0722f0b138
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 21 additions and 7 deletions

View File

@ -3,6 +3,7 @@ package aws
import ( import (
"fmt" "fmt"
"log" "log"
"strings"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ec2"
@ -129,11 +130,22 @@ func resourceAwsLogFlowRead(d *schema.ResourceData, meta interface{}) error {
} }
fl := resp.FlowLogs[0] fl := resp.FlowLogs[0]
d.Set("traffic_type", fl.TrafficType) d.Set("traffic_type", fl.TrafficType)
d.Set("log_group_name", fl.LogGroupName) d.Set("log_group_name", fl.LogGroupName)
d.Set("iam_role_arn", fl.DeliverLogsPermissionArn) d.Set("iam_role_arn", fl.DeliverLogsPermissionArn)
var resourceKey string
if strings.HasPrefix(*fl.ResourceId, "vpc-") {
resourceKey = "vpc_id"
} else if strings.HasPrefix(*fl.ResourceId, "subnet-") {
resourceKey = "subnet_id"
} else if strings.HasPrefix(*fl.ResourceId, "eni-") {
resourceKey = "eni_id"
}
if resourceKey != "" {
d.Set(resourceKey, fl.ResourceId)
}
return nil return nil
} }

View File

@ -14,9 +14,10 @@ func TestAccAWSFlowLog_basic(t *testing.T) {
var flowLog ec2.FlowLog var flowLog ec2.FlowLog
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, IDRefreshName: "aws_flow_log.test_flow_log",
CheckDestroy: testAccCheckFlowLogDestroy, Providers: testAccProviders,
CheckDestroy: testAccCheckFlowLogDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccFlowLogConfig_basic, Config: testAccFlowLogConfig_basic,
@ -33,9 +34,10 @@ func TestAccAWSFlowLog_subnet(t *testing.T) {
var flowLog ec2.FlowLog var flowLog ec2.FlowLog
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, IDRefreshName: "aws_flow_log.test_flow_log_subnet",
CheckDestroy: testAccCheckFlowLogDestroy, Providers: testAccProviders,
CheckDestroy: testAccCheckFlowLogDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccFlowLogConfig_subnet, Config: testAccFlowLogConfig_subnet,