forked from hashicorp/terraform-provider-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_source_aws_sqs_queue.go
57 lines (48 loc) · 1.32 KB
/
data_source_aws_sqs_queue.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package aws
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/sqs"
"github.com/hashicorp/terraform/helper/schema"
)
func dataSourceAwsSqsQueue() *schema.Resource {
return &schema.Resource{
Read: dataSourceAwsSqsQueueRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"arn": {
Type: schema.TypeString,
Computed: true,
},
"url": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
func dataSourceAwsSqsQueueRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).sqsconn
name := d.Get("name").(string)
urlOutput, err := conn.GetQueueUrl(&sqs.GetQueueUrlInput{
QueueName: aws.String(name),
})
if err != nil || urlOutput.QueueUrl == nil {
return fmt.Errorf("Error getting queue URL: %s", err)
}
queueURL := aws.StringValue(urlOutput.QueueUrl)
attributesOutput, err := conn.GetQueueAttributes(&sqs.GetQueueAttributesInput{
QueueUrl: aws.String(queueURL),
AttributeNames: []*string{aws.String(sqs.QueueAttributeNameQueueArn)},
})
if err != nil {
return fmt.Errorf("Error getting queue attributes: %s", err)
}
d.Set("arn", aws.StringValue(attributesOutput.Attributes[sqs.QueueAttributeNameQueueArn]))
d.Set("url", queueURL)
d.SetId(queueURL)
return nil
}