provider/aws: Fix aws_db_event_subscription import
Previously the db_event_subscription import would only work if there was a single db_event_subscription resource. This fixes the import, allowing it to work as expected. Also fixes the acceptance test for the resource to reflect this. ``` $ make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSDBEventSubscription_importBasic' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2017/02/07 10:38:10 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSDBEventSubscription_importBasic -timeout 120m === RUN TestAccAWSDBEventSubscription_importBasic --- PASS: TestAccAWSDBEventSubscription_importBasic (633.33s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 633.353s ```
This commit is contained in:
parent
441b1cca90
commit
20a75ec6d7
|
@ -0,0 +1,17 @@
|
||||||
|
package aws
|
||||||
|
|
||||||
|
import "github.com/hashicorp/terraform/helper/schema"
|
||||||
|
|
||||||
|
func resourceAwsDbEventSubscriptionImport(
|
||||||
|
d *schema.ResourceData,
|
||||||
|
meta interface{}) ([]*schema.ResourceData, error) {
|
||||||
|
|
||||||
|
// The db event subscription Read function only needs the "name" of the event subscription
|
||||||
|
// in order to populate the necessary values. This takes the "id" from the supplied StateFunc
|
||||||
|
// and sets it as the "name" attribute, as described in the import documentation. This allows
|
||||||
|
// the Read function to actually succeed and set the ID of the resource
|
||||||
|
results := make([]*schema.ResourceData, 1, 1)
|
||||||
|
d.Set("name", d.Id())
|
||||||
|
results[0] = d
|
||||||
|
return results, nil
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package aws
|
package aws
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
|
@ -10,6 +11,7 @@ import (
|
||||||
func TestAccAWSDBEventSubscription_importBasic(t *testing.T) {
|
func TestAccAWSDBEventSubscription_importBasic(t *testing.T) {
|
||||||
resourceName := "aws_db_event_subscription.bar"
|
resourceName := "aws_db_event_subscription.bar"
|
||||||
rInt := acctest.RandInt()
|
rInt := acctest.RandInt()
|
||||||
|
subscriptionName := fmt.Sprintf("tf-acc-test-rds-event-subs-%d", rInt)
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
@ -24,6 +26,7 @@ func TestAccAWSDBEventSubscription_importBasic(t *testing.T) {
|
||||||
ResourceName: resourceName,
|
ResourceName: resourceName,
|
||||||
ImportState: true,
|
ImportState: true,
|
||||||
ImportStateVerify: true,
|
ImportStateVerify: true,
|
||||||
|
ImportStateId: subscriptionName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -19,26 +19,26 @@ func resourceAwsDbEventSubscription() *schema.Resource {
|
||||||
Update: resourceAwsDbEventSubscriptionUpdate,
|
Update: resourceAwsDbEventSubscriptionUpdate,
|
||||||
Delete: resourceAwsDbEventSubscriptionDelete,
|
Delete: resourceAwsDbEventSubscriptionDelete,
|
||||||
Importer: &schema.ResourceImporter{
|
Importer: &schema.ResourceImporter{
|
||||||
State: schema.ImportStatePassthrough,
|
State: resourceAwsDbEventSubscriptionImport,
|
||||||
},
|
},
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"name": &schema.Schema{
|
"name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
ValidateFunc: validateDbEventSubscriptionName,
|
ValidateFunc: validateDbEventSubscriptionName,
|
||||||
},
|
},
|
||||||
"sns_topic": &schema.Schema{
|
"sns_topic": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
"event_categories": &schema.Schema{
|
"event_categories": {
|
||||||
Type: schema.TypeSet,
|
Type: schema.TypeSet,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Elem: &schema.Schema{Type: schema.TypeString},
|
Elem: &schema.Schema{Type: schema.TypeString},
|
||||||
Set: schema.HashString,
|
Set: schema.HashString,
|
||||||
},
|
},
|
||||||
"source_ids": &schema.Schema{
|
"source_ids": {
|
||||||
Type: schema.TypeSet,
|
Type: schema.TypeSet,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Elem: &schema.Schema{Type: schema.TypeString},
|
Elem: &schema.Schema{Type: schema.TypeString},
|
||||||
|
@ -46,16 +46,16 @@ func resourceAwsDbEventSubscription() *schema.Resource {
|
||||||
// ValidateFunc: validateDbEventSubscriptionSourceIds,
|
// ValidateFunc: validateDbEventSubscriptionSourceIds,
|
||||||
// requires source_type to be set, does not seem to be a way to validate this
|
// requires source_type to be set, does not seem to be a way to validate this
|
||||||
},
|
},
|
||||||
"source_type": &schema.Schema{
|
"source_type": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
},
|
},
|
||||||
"enabled": &schema.Schema{
|
"enabled": {
|
||||||
Type: schema.TypeBool,
|
Type: schema.TypeBool,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Default: true,
|
Default: true,
|
||||||
},
|
},
|
||||||
"customer_aws_id": &schema.Schema{
|
"customer_aws_id": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue