opentofu/builtin/providers/aws/resource_aws_simpledb_domain.go
Paul Stack 7a58ad95f5 provider/aws: Support Import for aws_simpledb_domain (#7601)
```
% make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSSimpleDBDomain_'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
TF_ACC=1 go test ./builtin/providers/aws -v
-run=TestAccAWSSimpleDBDomain_ -timeout 120m
=== RUN   TestAccAWSSimpleDBDomain_importBasic
--- PASS: TestAccAWSSimpleDBDomain_importBasic (19.59s)
=== RUN   TestAccAWSSimpleDBDomain_basic
--- PASS: TestAccAWSSimpleDBDomain_basic (19.93s)
PASS
ok      github.com/hashicorp/terraform/builtin/providers/aws    39.535s
```
2016-07-12 13:15:47 +01:00

85 lines
1.9 KiB
Go

package aws
import (
"fmt"
"log"
"github.com/hashicorp/terraform/helper/schema"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/simpledb"
)
func resourceAwsSimpleDBDomain() *schema.Resource {
return &schema.Resource{
Create: resourceAwsSimpleDBDomainCreate,
Read: resourceAwsSimpleDBDomainRead,
Delete: resourceAwsSimpleDBDomainDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
},
}
}
func resourceAwsSimpleDBDomainCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).simpledbconn
name := d.Get("name").(string)
input := &simpledb.CreateDomainInput{
DomainName: aws.String(name),
}
_, err := conn.CreateDomain(input)
if err != nil {
return fmt.Errorf("Create SimpleDB Domain failed: %s", err)
}
d.SetId(name)
return nil
}
func resourceAwsSimpleDBDomainRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).simpledbconn
input := &simpledb.DomainMetadataInput{
DomainName: aws.String(d.Id()),
}
_, err := conn.DomainMetadata(input)
if awsErr, ok := err.(awserr.Error); ok {
if awsErr.Code() == "NoSuchDomain" {
log.Printf("[WARN] Removing SimpleDB domain %q because it's gone.", d.Id())
d.SetId("")
return nil
}
}
if err != nil {
return err
}
d.Set("name", d.Id())
return nil
}
func resourceAwsSimpleDBDomainDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).simpledbconn
input := &simpledb.DeleteDomainInput{
DomainName: aws.String(d.Id()),
}
_, err := conn.DeleteDomain(input)
if err != nil {
return fmt.Errorf("Delete SimpleDB Domain failed: %s", err)
}
d.SetId("")
return nil
}