-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
359ebf9
commit 4519529
Showing
5 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package aws | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/sqs" | ||
"github.com/hashicorp/errwrap" | ||
"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 | ||
target := d.Get("name").(string) | ||
|
||
urlOutput, err := conn.GetQueueUrl(&sqs.GetQueueUrlInput{ | ||
QueueName: aws.String(target), | ||
}) | ||
if err != nil { | ||
return errwrap.Wrapf("Error getting queue URL: {{err}}", err) | ||
} | ||
|
||
queueURL := *urlOutput.QueueUrl | ||
|
||
attributesOutput, err := conn.GetQueueAttributes(&sqs.GetQueueAttributesInput{ | ||
QueueUrl: &queueURL, | ||
AttributeNames: []*string{aws.String(sqs.QueueAttributeNameQueueArn)}, | ||
}) | ||
if err != nil { | ||
return errwrap.Wrapf("Error getting queue attributes: {{err}}", err) | ||
} | ||
|
||
d.Set("arn", *attributesOutput.Attributes[sqs.QueueAttributeNameQueueArn]) | ||
d.Set("url", queueURL) | ||
d.SetId(queueURL) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestAccDataSourceAwsSqsQueue(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccDataSourceAwsSqsQueueConfig, | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccDataSourceAwsSqsQueueCheck("data.aws_sqs_queue.by_name"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceAwsSqsQueueCheck(name string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[name] | ||
if !ok { | ||
return fmt.Errorf("root module has no resource called %s", name) | ||
} | ||
|
||
sqsQueueRs, ok := s.RootModule().Resources["aws_sqs_queue.tf_test"] | ||
if !ok { | ||
return fmt.Errorf("can't find aws_sqs_queue.tf_test in state") | ||
} | ||
|
||
attr := rs.Primary.Attributes | ||
|
||
if attr["name"] != sqsQueueRs.Primary.Attributes["name"] { | ||
return fmt.Errorf( | ||
"name is %s; want %s", | ||
attr["name"], | ||
sqsQueueRs.Primary.Attributes["name"], | ||
) | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
const testAccDataSourceAwsSqsQueueConfig = ` | ||
provider "aws" { | ||
region = "us-west-2" | ||
} | ||
resource "aws_sqs_queue" "tf_wrong1" { | ||
name = "wrong1" | ||
} | ||
resource "aws_sqs_queue" "tf_test" { | ||
name = "tf_test" | ||
} | ||
resource "aws_sqs_queue" "tf_wrong2" { | ||
name = "wrong2" | ||
} | ||
data "aws_sqs_queue" "by_name" { | ||
name = "${aws_sqs_queue.tf_test.name}" | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
layout: "aws" | ||
page_title: "AWS: aws_sqs_queue" | ||
sidebar_current: "docs-aws-datasource-sqs-queue" | ||
description: |- | ||
Get information on an Amazon Simple Queue Service (SQS) Queue | ||
--- | ||
|
||
# aws\_sqs\_queue | ||
|
||
Use this data source to get the ARN and URL of queue in AWS Simple Queue Service (SQS). | ||
By using this data source, you can reference SQS queues without having to hardcode | ||
the ARNs as input. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "aws_sqs_queue" "example" { | ||
name = "queue" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `name` - (Required) The name of the queue to match. | ||
|
||
## Attributes Reference | ||
|
||
* `arn` - The Amazon Resource Name (ARN) of the queue. | ||
* `url` - The URL of the queue. |