Improve error reporting at creation

Code borrowed from nearby subscription filter resource.
This commit is contained in:
Matt Dainty 2017-02-15 09:39:37 +00:00
parent 3939a7220d
commit e4b4d2b563
No known key found for this signature in database
GPG Key ID: D57145DF9EBCC9BA

View File

@ -2,11 +2,13 @@ package aws
import ( import (
"fmt" "fmt"
"time"
"github.com/hashicorp/terraform/helper/schema"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/cloudwatchlogs" "github.com/aws/aws-sdk-go/service/cloudwatchlogs"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
) )
func resourceAwsCloudWatchLogDestination() *schema.Resource { func resourceAwsCloudWatchLogDestination() *schema.Resource {
@ -62,15 +64,25 @@ func resourceAwsCloudWatchLogDestinationPut(d *schema.ResourceData, meta interfa
TargetArn: aws.String(target_arn), TargetArn: aws.String(target_arn),
} }
resp, err := conn.PutDestination(params) return resource.Retry(30*time.Second, func() *resource.RetryError {
resp, err := conn.PutDestination(params)
if err != nil { if err == nil {
return fmt.Errorf("Error creating Destination with name %s: %#v", name, err) d.SetId(*resp.Destination.Arn)
} d.Set("arn", *resp.Destination.Arn)
}
d.SetId(*resp.Destination.Arn) awsErr, ok := err.(awserr.Error)
d.Set("arn", *resp.Destination.Arn) if !ok {
return resourceAwsCloudWatchLogDestinationRead(d, meta) return resource.RetryableError(err)
}
if awsErr.Code() == "InvalidParameterException" {
return resource.NonRetryableError(err)
}
return resource.NonRetryableError(err)
})
} }
func resourceAwsCloudWatchLogDestinationRead(d *schema.ResourceData, meta interface{}) error { func resourceAwsCloudWatchLogDestinationRead(d *schema.ResourceData, meta interface{}) error {