From 9d125944c0d9fde5d0b474adcd8649cf00629715 Mon Sep 17 00:00:00 2001 From: Srikalyan Swayampakula Date: Sun, 17 Jan 2016 12:24:32 -0800 Subject: [PATCH 1/6] Added support for http/https endpoints that auto confirms SNS topic subscription. http and https SNS topic subscription endpoints require confirmation to set a valid arn otherwise arn would be set to "pending confirmation". If the endpoints auto confirm then arn is set asynchronously but if we try to create another subscription with same parameters then api returns "pending subscription" as arn but does not create another a duplicate subscription. In order to solve this we should be fetching the subscription list for the topic and identify the subscription with same parameters i.e., protocol, topic_arn, endpoint and extract the subscription arn. Following changes were made to support the http/https endpoints that auto confirms 1. Added 3 extra parameters i.e., 1. endpoint_auto_confirms -> boolean indicates if end points auto confirms 2. max_fetch_retries -> number of times to fetch subscription list for the topic to get the subscription arn 3. fetch_retry_delay -> delay b/w fetch subscription list call as the confirmation is done asynchronously. With these parameters help added support http and https protocol based endpoints that auto confirm. 2. Update website doc appropriately --- .../resource_aws_sns_topic_subscription.go | 86 ++++++++++++++++++- .../r/sns_topic_subscription.html.markdown | 12 ++- 2 files changed, 94 insertions(+), 4 deletions(-) diff --git a/builtin/providers/aws/resource_aws_sns_topic_subscription.go b/builtin/providers/aws/resource_aws_sns_topic_subscription.go index 72e9c3307a02..d7fe93496c20 100644 --- a/builtin/providers/aws/resource_aws_sns_topic_subscription.go +++ b/builtin/providers/aws/resource_aws_sns_topic_subscription.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/sns" + "time" ) const awsSNSPendingConfirmationMessage = "pending confirmation" @@ -27,7 +28,7 @@ func resourceAwsSnsTopicSubscription() *schema.Resource { ForceNew: false, ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) { value := v.(string) - forbidden := []string{"email", "sms", "http"} + forbidden := []string{"email", "sms"} for _, f := range forbidden { if strings.Contains(value, f) { errors = append( @@ -44,6 +45,24 @@ func resourceAwsSnsTopicSubscription() *schema.Resource { Required: true, ForceNew: false, }, + "endpoint_auto_confirms": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + ForceNew: false, + Default: false, + }, + "max_fetch_retries": &schema.Schema{ + Type: schema.TypeInt, + Optional: true, + ForceNew: false, + Default: 3, + }, + "fetch_retry_delay": &schema.Schema{ + Type: schema.TypeInt, + Optional: true, + ForceNew: false, + Default: 1, + }, "topic_arn": &schema.Schema{ Type: schema.TypeString, Required: true, @@ -178,6 +197,13 @@ func subscribeToSNSTopic(d *schema.ResourceData, snsconn *sns.SNS) (output *sns. protocol := d.Get("protocol").(string) endpoint := d.Get("endpoint").(string) topic_arn := d.Get("topic_arn").(string) + endpoint_auto_confirms := d.Get("endpoint_auto_confirms").(bool) + max_fetch_retries := d.Get("max_fetch_retries").(int) + fetch_retry_delay := time.Duration(d.Get("fetch_retry_delay").(int)) + + if strings.Contains(protocol, "http") && !endpoint_auto_confirms { + return nil, fmt.Errorf("Protocol http/https is only supported for endpoints which auto confirms!") + } log.Printf("[DEBUG] SNS create topic subscription: %s (%s) @ '%s'", endpoint, protocol, topic_arn) @@ -192,6 +218,64 @@ func subscribeToSNSTopic(d *schema.ResourceData, snsconn *sns.SNS) (output *sns. return nil, fmt.Errorf("Error creating SNS topic: %s", err) } + if strings.Contains(protocol, "http") && (output.SubscriptionArn == nil || *output.SubscriptionArn == awsSNSPendingConfirmationMessage) { + + log.Printf("[DEBUG] SNS create topic subscritpion is pending so fetching the subscription list for topic : %s (%s) @ '%s'", endpoint, protocol, topic_arn) + + for i := 0; i < max_fetch_retries && output.SubscriptionArn != nil && *output.SubscriptionArn == awsSNSPendingConfirmationMessage; i++ { + + subscription, err := findSubscriptionByNonID(d, snsconn) + + if err != nil { + return nil, fmt.Errorf("Error fetching subscriptions for SNS topic %s: %s", topic_arn, err) + } + + if subscription != nil { + output.SubscriptionArn = subscription.SubscriptionArn + break + } + + time.Sleep(time.Second * fetch_retry_delay) + } + + if output.SubscriptionArn == nil || *output.SubscriptionArn == awsSNSPendingConfirmationMessage { + return nil, fmt.Errorf("Endpoint (%s) did not autoconfirm the subscription for topic %s", endpoint, topic_arn) + } + } + log.Printf("[DEBUG] Created new subscription!") return output, nil } + +// finds a subscription using protocol, endpoint and topic_arn (which is a key in sns subscription) +func findSubscriptionByNonID(d *schema.ResourceData, snsconn *sns.SNS) (*sns.Subscription, error) { + protocol := d.Get("protocol").(string) + endpoint := d.Get("endpoint").(string) + topic_arn := d.Get("topic_arn").(string) + + req := &sns.ListSubscriptionsByTopicInput{ + TopicArn: aws.String(topic_arn), + } + + for { + + res, err := snsconn.ListSubscriptionsByTopic(req) + + if err != nil { + return nil, fmt.Errorf("Error fetching subscripitions for topic %s : %s", topic_arn, err) + } + + for _, subscription := range res.Subscriptions { + if *subscription.Endpoint == endpoint && *subscription.Protocol == protocol && *subscription.TopicArn == topic_arn { + return subscription, nil + } + } + + // if there are more than 100 subscriptions then go to the next 100 otherwise return nil + if res.NextToken != nil { + req.NextToken = res.NextToken + } else { + return nil, nil + } + } +} diff --git a/website/source/docs/providers/aws/r/sns_topic_subscription.html.markdown b/website/source/docs/providers/aws/r/sns_topic_subscription.html.markdown index 6e13bea7182f..bd84fe723870 100644 --- a/website/source/docs/providers/aws/r/sns_topic_subscription.html.markdown +++ b/website/source/docs/providers/aws/r/sns_topic_subscription.html.markdown @@ -49,8 +49,11 @@ resource "aws_sns_topic_subscription" "user_updates_sqs_target" { The following arguments are supported: * `topic_arn` - (Required) The ARN of the SNS topic to subscribe to -* `protocol` - (Required) The protocol to use. The possible values for this are: `sqs`, `lambda`, or `application`. (`email`, `http`, `https`, `sms`, are options but unsupported, see below) +* `protocol` - (Required) The protocol to use. The possible values for this are: `sqs`, `lambda`, `application`. (`http` or `https` are partially supported, see below) (`email`, `sms`, are options but unsupported, see below). * `endpoint` - (Required) The endpoint to send data to, the contents will vary with the protocol. (see below for more information) +* `endpoint_auto_confirms` - (Optional) Boolean indicating whether the end point is capable of auto confirming subscription (default is false) +* `max_fetch_retries` - (Optional) Integer indicating number of times the subscriptions list for a topic to be fetched to get the subscription arn for auto confirming end points. +* `fetch_retry_delay` - (Optional) Integer indicating number of seconds to sleep before re-fetching the subscription list for the topic. * `raw_message_delivery` - (Optional) Boolean indicating whether or not to enable raw message delivery (the original message is directly passed, not wrapped in JSON with the original message in the message property). ### Protocols supported @@ -61,12 +64,15 @@ Supported SNS protocols include: * `sqs` -- delivery of JSON-encoded message to an Amazon SQS queue * `application` -- delivery of JSON-encoded message to an EndpointArn for a mobile app and device +Partially supported SNS protocols include: + +* `http` -- delivery of JSON-encoded messages via HTTP. Supported only for the end points that auto confirms the subscription. +* `https` -- delivery of JSON-encoded messages via HTTPS. Supported only for the end points that auto confirms the subscription. + Unsupported protocols include the following: * `email` -- delivery of message via SMTP * `email-json` -- delivery of JSON-encoded message via SMTP -* `http` -- delivery via HTTP -* `http(s)` -- delivery via HTTPS * `sms` -- delivery text message These are unsupported because the endpoint needs to be authorized and does not From 63d6d8dbe202abab5cf049d0dd12adc2fdb9ae28 Mon Sep 17 00:00:00 2001 From: Srikalyan Swayampakula Date: Mon, 18 Jan 2016 14:00:11 -0800 Subject: [PATCH 2/6] Forgot to add one last condition to ensure that non pending confirmation subscription is returned. --- builtin/providers/aws/resource_aws_sns_topic_subscription.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_sns_topic_subscription.go b/builtin/providers/aws/resource_aws_sns_topic_subscription.go index d7fe93496c20..081236f7cb08 100644 --- a/builtin/providers/aws/resource_aws_sns_topic_subscription.go +++ b/builtin/providers/aws/resource_aws_sns_topic_subscription.go @@ -266,7 +266,7 @@ func findSubscriptionByNonID(d *schema.ResourceData, snsconn *sns.SNS) (*sns.Sub } for _, subscription := range res.Subscriptions { - if *subscription.Endpoint == endpoint && *subscription.Protocol == protocol && *subscription.TopicArn == topic_arn { + if *subscription.Endpoint == endpoint && *subscription.Protocol == protocol && *subscription.TopicArn == topic_arn && *subscription.SubscriptionArn != awsSNSPendingConfirmationMessage { return subscription, nil } } From 3d256dd02197c83f51854470b33c8843c27b5b4e Mon Sep 17 00:00:00 2001 From: Srikalyan Swayampakula Date: Mon, 18 Jan 2016 15:38:34 -0800 Subject: [PATCH 3/6] Found an issue with more testing aws api is responding with various of "pending confirmation" such as "PendingConfirmation", "Pending Confirmation" etc. --- .../resource_aws_sns_topic_subscription.go | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/builtin/providers/aws/resource_aws_sns_topic_subscription.go b/builtin/providers/aws/resource_aws_sns_topic_subscription.go index 081236f7cb08..dee6210f0314 100644 --- a/builtin/providers/aws/resource_aws_sns_topic_subscription.go +++ b/builtin/providers/aws/resource_aws_sns_topic_subscription.go @@ -96,7 +96,7 @@ func resourceAwsSnsTopicSubscriptionCreate(d *schema.ResourceData, meta interfac return err } - if output.SubscriptionArn != nil && *output.SubscriptionArn == awsSNSPendingConfirmationMessage { + if subscriptionHasPendingConfirmation(output.SubscriptionArn) { log.Printf("[WARN] Invalid SNS Subscription, received a \"%s\" ARN", awsSNSPendingConfirmationMessage) return nil } @@ -218,11 +218,13 @@ func subscribeToSNSTopic(d *schema.ResourceData, snsconn *sns.SNS) (output *sns. return nil, fmt.Errorf("Error creating SNS topic: %s", err) } - if strings.Contains(protocol, "http") && (output.SubscriptionArn == nil || *output.SubscriptionArn == awsSNSPendingConfirmationMessage) { + log.Printf("[DEBUG] Finished subscribing to topic %s with subscription arn %s", topic_arn, *output.SubscriptionArn) + + if strings.Contains(protocol, "http") && subscriptionHasPendingConfirmation(output.SubscriptionArn) { log.Printf("[DEBUG] SNS create topic subscritpion is pending so fetching the subscription list for topic : %s (%s) @ '%s'", endpoint, protocol, topic_arn) - for i := 0; i < max_fetch_retries && output.SubscriptionArn != nil && *output.SubscriptionArn == awsSNSPendingConfirmationMessage; i++ { + for i := 0; i < max_fetch_retries && subscriptionHasPendingConfirmation(output.SubscriptionArn); i++ { subscription, err := findSubscriptionByNonID(d, snsconn) @@ -238,12 +240,12 @@ func subscribeToSNSTopic(d *schema.ResourceData, snsconn *sns.SNS) (output *sns. time.Sleep(time.Second * fetch_retry_delay) } - if output.SubscriptionArn == nil || *output.SubscriptionArn == awsSNSPendingConfirmationMessage { + if subscriptionHasPendingConfirmation(output.SubscriptionArn) { return nil, fmt.Errorf("Endpoint (%s) did not autoconfirm the subscription for topic %s", endpoint, topic_arn) } } - log.Printf("[DEBUG] Created new subscription!") + log.Printf("[DEBUG] Created new subscription! %s", *output.SubscriptionArn) return output, nil } @@ -266,7 +268,8 @@ func findSubscriptionByNonID(d *schema.ResourceData, snsconn *sns.SNS) (*sns.Sub } for _, subscription := range res.Subscriptions { - if *subscription.Endpoint == endpoint && *subscription.Protocol == protocol && *subscription.TopicArn == topic_arn && *subscription.SubscriptionArn != awsSNSPendingConfirmationMessage { + log.Printf("[DEBUG] check subscription with EndPoint %s, Protocol %s, topicARN %s and SubscriptionARN %s", *subscription.Endpoint, *subscription.Protocol, *subscription.TopicArn, *subscription.SubscriptionArn) + if *subscription.Endpoint == endpoint && *subscription.Protocol == protocol && *subscription.TopicArn == topic_arn && !subscriptionHasPendingConfirmation(subscription.SubscriptionArn) { return subscription, nil } } @@ -279,3 +282,12 @@ func findSubscriptionByNonID(d *schema.ResourceData, snsconn *sns.SNS) (*sns.Sub } } } + +// returns true if arn is nil or has both pending and confirmation words in the arn +func subscriptionHasPendingConfirmation(arn *string) bool { + if arn != nil && !strings.Contains(strings.ToLower(*arn), "pending") && !strings.Contains(strings.ToLower(*arn), "confirmation") { + return false + } + + return true +} From 5f558c05367398a77bdad01d2ec009f953f4d4ba Mon Sep 17 00:00:00 2001 From: Srikalyan Swayampakula Date: Thu, 11 Feb 2016 09:23:45 -0800 Subject: [PATCH 4/6] Updated the documentation to include the defaults for the remaining fields added in the PR and add the link to amazon describing the auto confirming subscription. --- .../providers/aws/r/sns_topic_subscription.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/website/source/docs/providers/aws/r/sns_topic_subscription.html.markdown b/website/source/docs/providers/aws/r/sns_topic_subscription.html.markdown index bd84fe723870..b8811aa867df 100644 --- a/website/source/docs/providers/aws/r/sns_topic_subscription.html.markdown +++ b/website/source/docs/providers/aws/r/sns_topic_subscription.html.markdown @@ -51,9 +51,9 @@ The following arguments are supported: * `topic_arn` - (Required) The ARN of the SNS topic to subscribe to * `protocol` - (Required) The protocol to use. The possible values for this are: `sqs`, `lambda`, `application`. (`http` or `https` are partially supported, see below) (`email`, `sms`, are options but unsupported, see below). * `endpoint` - (Required) The endpoint to send data to, the contents will vary with the protocol. (see below for more information) -* `endpoint_auto_confirms` - (Optional) Boolean indicating whether the end point is capable of auto confirming subscription (default is false) -* `max_fetch_retries` - (Optional) Integer indicating number of times the subscriptions list for a topic to be fetched to get the subscription arn for auto confirming end points. -* `fetch_retry_delay` - (Optional) Integer indicating number of seconds to sleep before re-fetching the subscription list for the topic. +* `endpoint_auto_confirms` - (Optional) Boolean indicating whether the end point is capable of [auto confirming subscription](http://docs.aws.amazon.com/sns/latest/dg/SendMessageToHttp.html#SendMessageToHttp.prepare) (default is false) +* `max_fetch_retries` - (Optional) Integer indicating number of times the subscriptions list for a topic to be fetched to get the subscription arn for auto confirming end points (default is 3 times). +* `fetch_retry_delay` - (Optional) Integer indicating number of seconds to sleep before re-fetching the subscription list for the topic (default is 1 second). * `raw_message_delivery` - (Optional) Boolean indicating whether or not to enable raw message delivery (the original message is directly passed, not wrapped in JSON with the original message in the message property). ### Protocols supported From f21dc995c53a5c88263015f2547a1047d0fcb328 Mon Sep 17 00:00:00 2001 From: Srikalyan Swayampakula Date: Fri, 12 Feb 2016 12:21:52 -0800 Subject: [PATCH 5/6] Update code based on the review suggestions. 1. Used resource.Retry instead of custom solution 2. Removed unnecessary variables and added required variable to resource.Retry. --- .../resource_aws_sns_topic_subscription.go | 43 +++++++------------ .../r/sns_topic_subscription.html.markdown | 5 +-- 2 files changed, 18 insertions(+), 30 deletions(-) diff --git a/builtin/providers/aws/resource_aws_sns_topic_subscription.go b/builtin/providers/aws/resource_aws_sns_topic_subscription.go index dee6210f0314..75909fefbe0f 100644 --- a/builtin/providers/aws/resource_aws_sns_topic_subscription.go +++ b/builtin/providers/aws/resource_aws_sns_topic_subscription.go @@ -9,10 +9,12 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/sns" + "github.com/hashicorp/terraform/helper/resource" "time" ) const awsSNSPendingConfirmationMessage = "pending confirmation" +const awsSNSPendingConfirmationMessageWithoutSpaces = "pendingconfirmation" func resourceAwsSnsTopicSubscription() *schema.Resource { return &schema.Resource{ @@ -43,40 +45,28 @@ func resourceAwsSnsTopicSubscription() *schema.Resource { "endpoint": &schema.Schema{ Type: schema.TypeString, Required: true, - ForceNew: false, }, "endpoint_auto_confirms": &schema.Schema{ Type: schema.TypeBool, Optional: true, - ForceNew: false, Default: false, }, - "max_fetch_retries": &schema.Schema{ - Type: schema.TypeInt, - Optional: true, - ForceNew: false, - Default: 3, - }, - "fetch_retry_delay": &schema.Schema{ + "confirmation_timeout_in_minutes": &schema.Schema{ Type: schema.TypeInt, Optional: true, - ForceNew: false, Default: 1, }, "topic_arn": &schema.Schema{ Type: schema.TypeString, Required: true, - ForceNew: false, }, "delivery_policy": &schema.Schema{ Type: schema.TypeString, Optional: true, - ForceNew: false, }, "raw_message_delivery": &schema.Schema{ Type: schema.TypeBool, Optional: true, - ForceNew: false, Default: false, }, "arn": &schema.Schema{ @@ -198,8 +188,7 @@ func subscribeToSNSTopic(d *schema.ResourceData, snsconn *sns.SNS) (output *sns. endpoint := d.Get("endpoint").(string) topic_arn := d.Get("topic_arn").(string) endpoint_auto_confirms := d.Get("endpoint_auto_confirms").(bool) - max_fetch_retries := d.Get("max_fetch_retries").(int) - fetch_retry_delay := time.Duration(d.Get("fetch_retry_delay").(int)) + confirmation_timeout_in_minutes := time.Duration(d.Get("confirmation_timeout_in_minutes").(int)) if strings.Contains(protocol, "http") && !endpoint_auto_confirms { return nil, fmt.Errorf("Protocol http/https is only supported for endpoints which auto confirms!") @@ -222,26 +211,26 @@ func subscribeToSNSTopic(d *schema.ResourceData, snsconn *sns.SNS) (output *sns. if strings.Contains(protocol, "http") && subscriptionHasPendingConfirmation(output.SubscriptionArn) { - log.Printf("[DEBUG] SNS create topic subscritpion is pending so fetching the subscription list for topic : %s (%s) @ '%s'", endpoint, protocol, topic_arn) + log.Printf("[DEBUG] SNS create topic subscription is pending so fetching the subscription list for topic : %s (%s) @ '%s'", endpoint, protocol, topic_arn) - for i := 0; i < max_fetch_retries && subscriptionHasPendingConfirmation(output.SubscriptionArn); i++ { + err = resource.Retry(time.Minute*confirmation_timeout_in_minutes, func() error { subscription, err := findSubscriptionByNonID(d, snsconn) - if err != nil { - return nil, fmt.Errorf("Error fetching subscriptions for SNS topic %s: %s", topic_arn, err) - } - if subscription != nil { output.SubscriptionArn = subscription.SubscriptionArn - break + return nil } - time.Sleep(time.Second * fetch_retry_delay) - } + if err != nil { + return fmt.Errorf("Error fetching subscriptions for SNS topic %s: %s", topic_arn, err) + } + + return fmt.Errorf("Endpoint (%s) did not autoconfirm the subscription for topic %s", endpoint, topic_arn) + }) - if subscriptionHasPendingConfirmation(output.SubscriptionArn) { - return nil, fmt.Errorf("Endpoint (%s) did not autoconfirm the subscription for topic %s", endpoint, topic_arn) + if err != nil { + return nil, err } } @@ -285,7 +274,7 @@ func findSubscriptionByNonID(d *schema.ResourceData, snsconn *sns.SNS) (*sns.Sub // returns true if arn is nil or has both pending and confirmation words in the arn func subscriptionHasPendingConfirmation(arn *string) bool { - if arn != nil && !strings.Contains(strings.ToLower(*arn), "pending") && !strings.Contains(strings.ToLower(*arn), "confirmation") { + if arn != nil && !strings.Contains(strings.Replace(strings.ToLower(*arn), " ", "", -1), awsSNSPendingConfirmationMessageWithoutSpaces) { return false } diff --git a/website/source/docs/providers/aws/r/sns_topic_subscription.html.markdown b/website/source/docs/providers/aws/r/sns_topic_subscription.html.markdown index b8811aa867df..ab4ffd594ebf 100644 --- a/website/source/docs/providers/aws/r/sns_topic_subscription.html.markdown +++ b/website/source/docs/providers/aws/r/sns_topic_subscription.html.markdown @@ -51,9 +51,8 @@ The following arguments are supported: * `topic_arn` - (Required) The ARN of the SNS topic to subscribe to * `protocol` - (Required) The protocol to use. The possible values for this are: `sqs`, `lambda`, `application`. (`http` or `https` are partially supported, see below) (`email`, `sms`, are options but unsupported, see below). * `endpoint` - (Required) The endpoint to send data to, the contents will vary with the protocol. (see below for more information) -* `endpoint_auto_confirms` - (Optional) Boolean indicating whether the end point is capable of [auto confirming subscription](http://docs.aws.amazon.com/sns/latest/dg/SendMessageToHttp.html#SendMessageToHttp.prepare) (default is false) -* `max_fetch_retries` - (Optional) Integer indicating number of times the subscriptions list for a topic to be fetched to get the subscription arn for auto confirming end points (default is 3 times). -* `fetch_retry_delay` - (Optional) Integer indicating number of seconds to sleep before re-fetching the subscription list for the topic (default is 1 second). +* `endpoint_auto_confirms` - (Optional) Boolean indicating whether the end point is capable of [auto confirming subscription](http://docs.aws.amazon.com/sns/latest/dg/SendMessageToHttp.html#SendMessageToHttp.prepare) e.g., PagerDuty (default is false) +* `confirmation_timeout_in_minutes` - (Optional) Integer indicating number of minutes to wait in retying mode for fetching subscription arn before marking it as failure. Only applicable for http and https protocols (default is 1 minute). * `raw_message_delivery` - (Optional) Boolean indicating whether or not to enable raw message delivery (the original message is directly passed, not wrapped in JSON with the original message in the message property). ### Protocols supported From 345dbce77afd80fc8cab1d05df7d0a0358d7386d Mon Sep 17 00:00:00 2001 From: Srikalyan Swayampakula Date: Sat, 13 Feb 2016 12:15:29 -0800 Subject: [PATCH 6/6] Made the necessary changes to ensure the variable name represents right value. --- .../providers/aws/resource_aws_sns_topic_subscription.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/providers/aws/resource_aws_sns_topic_subscription.go b/builtin/providers/aws/resource_aws_sns_topic_subscription.go index 75909fefbe0f..cece62b8a40a 100644 --- a/builtin/providers/aws/resource_aws_sns_topic_subscription.go +++ b/builtin/providers/aws/resource_aws_sns_topic_subscription.go @@ -5,11 +5,11 @@ import ( "log" "strings" + "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/sns" - "github.com/hashicorp/terraform/helper/resource" "time" ) @@ -188,7 +188,7 @@ func subscribeToSNSTopic(d *schema.ResourceData, snsconn *sns.SNS) (output *sns. endpoint := d.Get("endpoint").(string) topic_arn := d.Get("topic_arn").(string) endpoint_auto_confirms := d.Get("endpoint_auto_confirms").(bool) - confirmation_timeout_in_minutes := time.Duration(d.Get("confirmation_timeout_in_minutes").(int)) + confirmation_timeout_in_minutes := d.Get("confirmation_timeout_in_minutes").(int) if strings.Contains(protocol, "http") && !endpoint_auto_confirms { return nil, fmt.Errorf("Protocol http/https is only supported for endpoints which auto confirms!") @@ -213,7 +213,7 @@ func subscribeToSNSTopic(d *schema.ResourceData, snsconn *sns.SNS) (output *sns. log.Printf("[DEBUG] SNS create topic subscription is pending so fetching the subscription list for topic : %s (%s) @ '%s'", endpoint, protocol, topic_arn) - err = resource.Retry(time.Minute*confirmation_timeout_in_minutes, func() error { + err = resource.Retry(time.Duration(int(time.Minute)*confirmation_timeout_in_minutes), func() error { subscription, err := findSubscriptionByNonID(d, snsconn)