providers/aws: sns_topic id-only

This commit is contained in:
Mitchell Hashimoto 2016-04-21 08:18:04 -07:00
parent edd14e42b3
commit 3a43ce8f8e
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 20 additions and 7 deletions

View File

@ -18,6 +18,7 @@ import (
// Mutable attributes
var SNSAttributeMap = map[string]string{
"arn": "TopicArn",
"display_name": "DisplayName",
"policy": "Policy",
"delivery_policy": "DeliveryPolicy",
@ -163,7 +164,6 @@ func resourceAwsSnsTopicRead(d *schema.ResourceData, meta interface{}) error {
attributeOutput, err := snsconn.GetTopicAttributes(&sns.GetTopicAttributesInput{
TopicArn: aws.String(d.Id()),
})
if err != nil {
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "NotFound" {
log.Printf("[WARN] SNS Topic (%s) not found, error code (404)", d.Id())
@ -198,6 +198,17 @@ func resourceAwsSnsTopicRead(d *schema.ResourceData, meta interface{}) error {
}
}
// If we have no name set (import) then determine it from the ARN.
// This is a bit of a heuristic for now since AWS provides no other
// way to get it.
if _, ok := d.GetOk("name"); !ok {
arn := d.Get("arn").(string)
idx := strings.LastIndex(arn, ":")
if idx > -1 {
d.Set("name", arn[idx+1:])
}
}
return nil
}

View File

@ -13,9 +13,10 @@ import (
func TestAccAWSSNSTopic_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSSNSTopicDestroy,
PreCheck: func() { testAccPreCheck(t) },
IDRefreshName: "aws_sns_topic.test_topic",
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSSNSTopicDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSSNSTopicConfig,
@ -29,9 +30,10 @@ func TestAccAWSSNSTopic_basic(t *testing.T) {
func TestAccAWSSNSTopic_withIAMRole(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSSNSTopicDestroy,
PreCheck: func() { testAccPreCheck(t) },
IDRefreshName: "aws_sns_topic.test_topic",
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSSNSTopicDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSSNSTopicConfig_withIAMRole,