Export ARN in SQS queue and SNS topic / subscription; updated tests for new AWS SDK errors; updated documentation.
This commit is contained in:
parent
0196a0c2ae
commit
1dd95df5ab
|
@ -47,6 +47,10 @@ func resourceAwsSnsTopic() *schema.Resource {
|
||||||
Optional: true,
|
Optional: true,
|
||||||
ForceNew: false,
|
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)
|
d.SetId(*output.TopicARN)
|
||||||
|
|
||||||
|
// Write the ARN to the 'arn' field for export
|
||||||
|
d.Set("arn", *output.TopicARN)
|
||||||
|
|
||||||
return resourceAwsSnsTopicUpdate(d, meta)
|
return resourceAwsSnsTopicUpdate(d, meta)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,6 +112,7 @@ func resourceAwsSnsTopicRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
attributeOutput, err := snsconn.GetTopicAttributes(&sns.GetTopicAttributesInput{
|
attributeOutput, err := snsconn.GetTopicAttributes(&sns.GetTopicAttributesInput{
|
||||||
TopicARN: aws.String(d.Id()),
|
TopicARN: aws.String(d.Id()),
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -123,7 +131,6 @@ func resourceAwsSnsTopicRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
value := *attrmap[oKey]
|
value := *attrmap[oKey]
|
||||||
log.Printf("[DEBUG] Updating %s => %s -> %s", iKey, oKey, value)
|
log.Printf("[DEBUG] Updating %s => %s -> %s", iKey, oKey, value)
|
||||||
d.Set(iKey, *attrmap[oKey])
|
d.Set(iKey, *attrmap[oKey])
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,10 @@ func resourceAwsSnsTopicSubscription() *schema.Resource {
|
||||||
ForceNew: false,
|
ForceNew: false,
|
||||||
Default: 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)
|
log.Printf("New subscription ARN: %s", *output.SubscriptionARN)
|
||||||
d.SetId(*output.SubscriptionARN)
|
d.SetId(*output.SubscriptionARN)
|
||||||
|
|
||||||
|
// Write the ARN to the 'arn' field for export
|
||||||
|
d.Set("arn", *output.SubscriptionARN)
|
||||||
|
|
||||||
return resourceAwsSnsTopicSubscriptionUpdate(d, meta)
|
return resourceAwsSnsTopicSubscriptionUpdate(d, meta)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/awslabs/aws-sdk-go/service/sns"
|
"github.com/awslabs/aws-sdk-go/service/sns"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
"github.com/awslabs/aws-sdk-go/aws/awserr"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccAWSSNSTopicSubscription(t *testing.T) {
|
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
|
// Verify the error is an API error, not something else
|
||||||
_, ok := err.(aws.APIError)
|
_, ok := err.(awserr.Error)
|
||||||
if !ok {
|
if !ok {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -90,9 +91,13 @@ resource "aws_sns_topic" "test_topic" {
|
||||||
name = "terraform-test-topic"
|
name = "terraform-test-topic"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resource "aws_sqs_queue" "test_queue" {
|
||||||
|
name = "terraform-subscription-test-queue"
|
||||||
|
}
|
||||||
|
|
||||||
resource "aws_sns_topic_subscription" "test_subscription" {
|
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"
|
protocol = "sqs"
|
||||||
endpoint = "arn:aws:sqs:us-west-2:432981146916:terraform-queue-too"
|
endpoint = "${aws_sqs_queue.test_queue.arn}"
|
||||||
}
|
}
|
||||||
`
|
`
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/awslabs/aws-sdk-go/service/sns"
|
"github.com/awslabs/aws-sdk-go/service/sns"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
"github.com/awslabs/aws-sdk-go/aws/awserr"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccAWSSNSTopic(t *testing.T) {
|
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
|
// Verify the error is an API error, not something else
|
||||||
_, ok := err.(aws.APIError)
|
_, ok := err.(awserr.Error)
|
||||||
if !ok {
|
if !ok {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ var AttributeMap = map[string]string{
|
||||||
"visibility_timeout_seconds": "VisibilityTimeout",
|
"visibility_timeout_seconds": "VisibilityTimeout",
|
||||||
"policy": "Policy",
|
"policy": "Policy",
|
||||||
"redrive_policy": "RedrivePolicy",
|
"redrive_policy": "RedrivePolicy",
|
||||||
|
"arn": "QueueArn",
|
||||||
}
|
}
|
||||||
|
|
||||||
// A number of these are marked as computed because if you don't
|
// A number of these are marked as computed because if you don't
|
||||||
|
@ -70,6 +71,10 @@ func resourceAwsSqsQueue() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
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()),
|
QueueURL: aws.String(d.Id()),
|
||||||
AttributeNames: []*string{aws.String("All")},
|
AttributeNames: []*string{aws.String("All")},
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,5 @@ The following arguments are supported:
|
||||||
The following attributes are exported:
|
The following attributes are exported:
|
||||||
|
|
||||||
* `id` - The ARN of the SNS topic
|
* `id` - The ARN of the SNS topic
|
||||||
* `policy` - The fully-formed AWS policy as JSON
|
* `arn` - The ARN of the SNS topic, as a more obvious property (clone of id)
|
||||||
* `delivery_policy` - The SNS delivery policy
|
|
||||||
|
|
||||||
|
|
|
@ -15,35 +15,35 @@ probably be SQS queues.
|
||||||
|
|
||||||
## Example Usage
|
## 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" {
|
resource "aws_sns_topic_subscription" "user_updates_sqs_target" {
|
||||||
topic_arn = "arn:aws:sns:us-west-2:432981146916:user-updates-topic"
|
topic_arn = "arn:aws:sns:us-west-2:432981146916:user-updates-topic"
|
||||||
topic_arn = "${aws_sns_topic.user_updates.id}"
|
|
||||||
protocol = "sqs"
|
protocol = "sqs"
|
||||||
endpoint = "arn:aws:sqs:us-west-2:432981146916:terraform-queue-too"
|
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" {
|
resource "aws_sns_topic" "user_updates" {
|
||||||
name = "user-updates-topic"
|
name = "user-updates-topic"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resource "aws_sqs_queue" "user_updates_queue" {
|
||||||
|
name = "user-updates-queue"
|
||||||
|
}
|
||||||
|
|
||||||
resource "aws_sns_topic_subscription" "user_updates_sqs_target" {
|
resource "aws_sns_topic_subscription" "user_updates_sqs_target" {
|
||||||
topic_arn = "${aws_sns_topic.user_updates.id}"
|
topic_arn = "${aws_sns_topic.user_updates.arn}"
|
||||||
protocol = "sqs"
|
protocol = "sqs"
|
||||||
endpoint = "arn:aws:sqs:us-west-2:432981146916:terraform-queue-too"
|
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
|
## Argument Reference
|
||||||
|
|
||||||
The following arguments are supported:
|
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
|
* `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)
|
* `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)
|
* `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
|
### Protocols supported
|
||||||
|
|
||||||
|
@ -88,4 +89,5 @@ The following attributes are exported:
|
||||||
* `topic_arn` - The ARN of the topic the subscription belongs to
|
* `topic_arn` - The ARN of the topic the subscription belongs to
|
||||||
* `protocol` - The protocol being used
|
* `protocol` - The protocol being used
|
||||||
* `endpoint` - The full endpoint to send data to (SQS ARN, HTTP(S) URL, Application ARN, SMS number, etc.)
|
* `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
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ description: |-
|
||||||
## Example Usage
|
## Example Usage
|
||||||
|
|
||||||
```
|
```
|
||||||
resource "aws_sqs_queue" "terrform_queue" {
|
resource "aws_sqs_queue" "terraform_queue" {
|
||||||
name = "terraform-example-queue"
|
name = "terraform-example-queue"
|
||||||
delay_seconds = 90
|
delay_seconds = 90
|
||||||
max_message_size = 2048
|
max_message_size = 2048
|
||||||
|
@ -36,3 +36,4 @@ The following arguments are supported:
|
||||||
The following attributes are exported:
|
The following attributes are exported:
|
||||||
|
|
||||||
* `id` - The URL for the created Amazon SQS queue.
|
* `id` - The URL for the created Amazon SQS queue.
|
||||||
|
* `arn` - The ARN of the SQS queue
|
Loading…
Reference in New Issue