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