providers/aws: sns_topic id-only
This commit is contained in:
parent
edd14e42b3
commit
3a43ce8f8e
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue