mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-06 10:41:07 +00:00
Pubsub importable (#392)
This commit is contained in:
parent
7c884c7e09
commit
bf51f26c07
35
google/import_pubsub_topic_test.go
Normal file
35
google/import_pubsub_topic_test.go
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package google
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAccPubsubTopic_import(t *testing.T) {
|
||||||
|
topicName := fmt.Sprintf("tf-test-topic-%d", acctest.RandInt())
|
||||||
|
conf := fmt.Sprintf(`
|
||||||
|
resource "google_pubsub_topic" "tf-test" {
|
||||||
|
name = "%s"
|
||||||
|
}`, topicName)
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckPubsubTopicDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: conf,
|
||||||
|
},
|
||||||
|
resource.TestStep{
|
||||||
|
ResourceName: "google_pubsub_topic.tf-test",
|
||||||
|
ImportStateId: topicName,
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateVerify: true,
|
||||||
|
ImportStateVerifyIgnore: []string{"force_destroy"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
@ -13,11 +13,16 @@ func resourcePubsubTopic() *schema.Resource {
|
|||||||
Read: resourcePubsubTopicRead,
|
Read: resourcePubsubTopicRead,
|
||||||
Delete: resourcePubsubTopicDelete,
|
Delete: resourcePubsubTopicDelete,
|
||||||
|
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
State: resourcePubsubTopicStateImporter,
|
||||||
|
},
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"name": &schema.Schema{
|
"name": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
|
DiffSuppressFunc: linkDiffSuppress,
|
||||||
},
|
},
|
||||||
|
|
||||||
"project": &schema.Schema{
|
"project": &schema.Schema{
|
||||||
@ -56,11 +61,13 @@ func resourcePubsubTopicRead(d *schema.ResourceData, meta interface{}) error {
|
|||||||
|
|
||||||
name := d.Id()
|
name := d.Id()
|
||||||
call := config.clientPubsub.Projects.Topics.Get(name)
|
call := config.clientPubsub.Projects.Topics.Get(name)
|
||||||
_, err := call.Do()
|
res, err := call.Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return handleNotFoundError(err, d, fmt.Sprintf("Pubsub Topic %q", name))
|
return handleNotFoundError(err, d, fmt.Sprintf("Pubsub Topic %q", name))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d.Set("name", res.Name)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,3 +83,18 @@ func resourcePubsubTopicDelete(d *schema.ResourceData, meta interface{}) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func resourcePubsubTopicStateImporter(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
|
||||||
|
config := meta.(*Config)
|
||||||
|
|
||||||
|
project, err := getProject(d, config)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
id := fmt.Sprintf("projects/%s/topics/%s", project, d.Id())
|
||||||
|
|
||||||
|
d.SetId(id)
|
||||||
|
|
||||||
|
return []*schema.ResourceData{d}, nil
|
||||||
|
}
|
||||||
|
@ -36,3 +36,11 @@ The following arguments are supported:
|
|||||||
## Attributes Reference
|
## Attributes Reference
|
||||||
|
|
||||||
Only the arguments listed above are exposed as attributes.
|
Only the arguments listed above are exposed as attributes.
|
||||||
|
|
||||||
|
## Import
|
||||||
|
|
||||||
|
Pubsub topics can be imported using the `name`, e.g.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ terraform import google_pubsub_topic.mytopic mytopic
|
||||||
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user