diff --git a/builtin/providers/aws/resource_aws_sns_topic.go b/builtin/providers/aws/resource_aws_sns_topic.go index 81eb34376..780ff2f38 100644 --- a/builtin/providers/aws/resource_aws_sns_topic.go +++ b/builtin/providers/aws/resource_aws_sns_topic.go @@ -47,6 +47,10 @@ func resourceAwsSnsTopic() *schema.Resource { Optional: true, ForceNew: false, }, + "arn": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, }, } } @@ -69,6 +73,9 @@ func resourceAwsSnsTopicCreate(d *schema.ResourceData, meta interface{}) error { d.SetId(*output.TopicARN) + // Write the ARN to the 'arn' field for export + d.Set("arn", *output.TopicARN) + return resourceAwsSnsTopicUpdate(d, meta) } @@ -105,6 +112,7 @@ func resourceAwsSnsTopicRead(d *schema.ResourceData, meta interface{}) error { attributeOutput, err := snsconn.GetTopicAttributes(&sns.GetTopicAttributesInput{ TopicARN: aws.String(d.Id()), }) + if err != nil { return err } @@ -123,7 +131,6 @@ func resourceAwsSnsTopicRead(d *schema.ResourceData, meta interface{}) error { value := *attrmap[oKey] log.Printf("[DEBUG] Updating %s => %s -> %s", iKey, oKey, value) d.Set(iKey, *attrmap[oKey]) - } } } diff --git a/builtin/providers/aws/resource_aws_sns_topic_subscription.go b/builtin/providers/aws/resource_aws_sns_topic_subscription.go index 542de0021..fd8c67604 100644 --- a/builtin/providers/aws/resource_aws_sns_topic_subscription.go +++ b/builtin/providers/aws/resource_aws_sns_topic_subscription.go @@ -45,6 +45,10 @@ func resourceAwsSnsTopicSubscription() *schema.Resource { ForceNew: false, Default: false, }, + "arn": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, }, } } @@ -65,6 +69,9 @@ func resourceAwsSnsTopicSubscriptionCreate(d *schema.ResourceData, meta interfac log.Printf("New subscription ARN: %s", *output.SubscriptionARN) d.SetId(*output.SubscriptionARN) + // Write the ARN to the 'arn' field for export + d.Set("arn", *output.SubscriptionARN) + return resourceAwsSnsTopicSubscriptionUpdate(d, meta) } diff --git a/builtin/providers/aws/resource_aws_sns_topic_subscription_test.go b/builtin/providers/aws/resource_aws_sns_topic_subscription_test.go index 6c630a4f9..ada177ccd 100644 --- a/builtin/providers/aws/resource_aws_sns_topic_subscription_test.go +++ b/builtin/providers/aws/resource_aws_sns_topic_subscription_test.go @@ -8,6 +8,7 @@ import ( "github.com/awslabs/aws-sdk-go/service/sns" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" + "github.com/awslabs/aws-sdk-go/aws/awserr" ) func TestAccAWSSNSTopicSubscription(t *testing.T) { @@ -49,7 +50,7 @@ func testAccCheckAWSSNSTopicSubscriptionDestroy(s *terraform.State) error { } // Verify the error is an API error, not something else - _, ok := err.(aws.APIError) + _, ok := err.(awserr.Error) if !ok { return err } @@ -90,9 +91,13 @@ resource "aws_sns_topic" "test_topic" { name = "terraform-test-topic" } +resource "aws_sqs_queue" "test_queue" { + name = "terraform-subscription-test-queue" +} + resource "aws_sns_topic_subscription" "test_subscription" { - topic_arn = "${aws_sns_topic.test_topic.id}" + topic_arn = "${aws_sns_topic.test_topic.arn}" protocol = "sqs" - endpoint = "arn:aws:sqs:us-west-2:432981146916:terraform-queue-too" + endpoint = "${aws_sqs_queue.test_queue.arn}" } ` \ No newline at end of file diff --git a/builtin/providers/aws/resource_aws_sns_topic_test.go b/builtin/providers/aws/resource_aws_sns_topic_test.go index ab52bd152..f13c0b677 100644 --- a/builtin/providers/aws/resource_aws_sns_topic_test.go +++ b/builtin/providers/aws/resource_aws_sns_topic_test.go @@ -8,6 +8,7 @@ import ( "github.com/awslabs/aws-sdk-go/service/sns" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" + "github.com/awslabs/aws-sdk-go/aws/awserr" ) func TestAccAWSSNSTopic(t *testing.T) { @@ -45,7 +46,7 @@ func testAccCheckAWSSNSTopicDestroy(s *terraform.State) error { } // Verify the error is an API error, not something else - _, ok := err.(aws.APIError) + _, ok := err.(awserr.Error) if !ok { return err } diff --git a/builtin/providers/aws/resource_aws_sqs_queue.go b/builtin/providers/aws/resource_aws_sqs_queue.go index b664bf2eb..7c7473f04 100644 --- a/builtin/providers/aws/resource_aws_sqs_queue.go +++ b/builtin/providers/aws/resource_aws_sqs_queue.go @@ -19,6 +19,7 @@ var AttributeMap = map[string]string{ "visibility_timeout_seconds": "VisibilityTimeout", "policy": "Policy", "redrive_policy": "RedrivePolicy", + "arn": "QueueArn", } // A number of these are marked as computed because if you don't @@ -70,6 +71,10 @@ func resourceAwsSqsQueue() *schema.Resource { Type: schema.TypeString, Optional: true, }, + "arn": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, }, } } @@ -154,6 +159,7 @@ func resourceAwsSqsQueueRead(d *schema.ResourceData, meta interface{}) error { QueueURL: aws.String(d.Id()), AttributeNames: []*string{aws.String("All")}, }) + if err != nil { return err } diff --git a/website/source/docs/providers/aws/r/sns_topic.html.markdown b/website/source/docs/providers/aws/r/sns_topic.html.markdown index 1306d780d..62a3c23f7 100644 --- a/website/source/docs/providers/aws/r/sns_topic.html.markdown +++ b/website/source/docs/providers/aws/r/sns_topic.html.markdown @@ -31,6 +31,5 @@ The following arguments are supported: The following attributes are exported: * `id` - The ARN of the SNS topic -* `policy` - The fully-formed AWS policy as JSON -* `delivery_policy` - The SNS delivery policy +* `arn` - The ARN of the SNS topic, as a more obvious property (clone of id) 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 027b6cee8..f27644350 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 @@ -15,35 +15,35 @@ probably be SQS queues. ## Example Usage -You can directly supply a topic ARN by hand in the `topic_arn` property: +You can directly supply a topic and ARN by hand in the `topic_arn` property along with the queue ARN: ``` resource "aws_sns_topic_subscription" "user_updates_sqs_target" { topic_arn = "arn:aws:sns:us-west-2:432981146916:user-updates-topic" - topic_arn = "${aws_sns_topic.user_updates.id}" protocol = "sqs" endpoint = "arn:aws:sqs:us-west-2:432981146916:terraform-queue-too" } ``` -Alternatively you can use the identifier of a previously created SNS topic: +Alternatively you can use the ARN properties of a managed SNS topic and SQS queue: ``` resource "aws_sns_topic" "user_updates" { name = "user-updates-topic" } +resource "aws_sqs_queue" "user_updates_queue" { + name = "user-updates-queue" +} + resource "aws_sns_topic_subscription" "user_updates_sqs_target" { - topic_arn = "${aws_sns_topic.user_updates.id}" - protocol = "sqs" - endpoint = "arn:aws:sqs:us-west-2:432981146916:terraform-queue-too" + topic_arn = "${aws_sns_topic.user_updates.arn}" + protocol = "sqs" + endpoint = "${aws_sqs_queue.user_updates_queue.arn}" } ``` -Currently there is no SQS support, so you need to know the queue ARN ahead of time, however it would make sense to be -able to populate the endpoint from an SQS resource in your JSON file. - ## Argument Reference The following arguments are supported: @@ -51,6 +51,7 @@ 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`, `http`, `https`, `sms`, or `application`. (`email` is an option but unsupported, see below) * `endpoint` - (Required) The endpoint to send data to, the contents will vary with the protocol. (see below for more information) +* `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 @@ -88,4 +89,5 @@ The following attributes are exported: * `topic_arn` - The ARN of the topic the subscription belongs to * `protocol` - The protocol being used * `endpoint` - The full endpoint to send data to (SQS ARN, HTTP(S) URL, Application ARN, SMS number, etc.) +* `arn` - The ARN of the subscription stored as a more user-friendly property diff --git a/website/source/docs/providers/aws/r/sqs_queue.html.markdown b/website/source/docs/providers/aws/r/sqs_queue.html.markdown index e03c4a2f5..47cae1f7a 100644 --- a/website/source/docs/providers/aws/r/sqs_queue.html.markdown +++ b/website/source/docs/providers/aws/r/sqs_queue.html.markdown @@ -11,7 +11,7 @@ description: |- ## Example Usage ``` -resource "aws_sqs_queue" "terrform_queue" { +resource "aws_sqs_queue" "terraform_queue" { name = "terraform-example-queue" delay_seconds = 90 max_message_size = 2048 @@ -35,4 +35,5 @@ The following arguments are supported: The following attributes are exported: -* `id` - The URL for the created Amazon SQS queue. \ No newline at end of file +* `id` - The URL for the created Amazon SQS queue. +* `arn` - The ARN of the SQS queue \ No newline at end of file