diff --git a/builtin/providers/aws/resource_aws_flow_log.go b/builtin/providers/aws/resource_aws_flow_log.go index 8580378c7..c02868f1d 100644 --- a/builtin/providers/aws/resource_aws_flow_log.go +++ b/builtin/providers/aws/resource_aws_flow_log.go @@ -3,6 +3,7 @@ package aws import ( "fmt" "log" + "strings" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" @@ -129,11 +130,22 @@ func resourceAwsLogFlowRead(d *schema.ResourceData, meta interface{}) error { } fl := resp.FlowLogs[0] - d.Set("traffic_type", fl.TrafficType) d.Set("log_group_name", fl.LogGroupName) 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 } diff --git a/builtin/providers/aws/resource_aws_flow_log_test.go b/builtin/providers/aws/resource_aws_flow_log_test.go index 061643e94..1b44aafee 100644 --- a/builtin/providers/aws/resource_aws_flow_log_test.go +++ b/builtin/providers/aws/resource_aws_flow_log_test.go @@ -14,9 +14,10 @@ func TestAccAWSFlowLog_basic(t *testing.T) { var flowLog ec2.FlowLog resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckFlowLogDestroy, + PreCheck: func() { testAccPreCheck(t) }, + IDRefreshName: "aws_flow_log.test_flow_log", + Providers: testAccProviders, + CheckDestroy: testAccCheckFlowLogDestroy, Steps: []resource.TestStep{ resource.TestStep{ Config: testAccFlowLogConfig_basic, @@ -33,9 +34,10 @@ func TestAccAWSFlowLog_subnet(t *testing.T) { var flowLog ec2.FlowLog resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckFlowLogDestroy, + PreCheck: func() { testAccPreCheck(t) }, + IDRefreshName: "aws_flow_log.test_flow_log_subnet", + Providers: testAccProviders, + CheckDestroy: testAccCheckFlowLogDestroy, Steps: []resource.TestStep{ resource.TestStep{ Config: testAccFlowLogConfig_subnet,