github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/aws/resource_aws_simpledb_domain.go (about)

     1  package aws
     2  
     3  import (
     4  	"fmt"
     5  	"log"
     6  
     7  	"github.com/hashicorp/terraform/helper/schema"
     8  
     9  	"github.com/aws/aws-sdk-go/aws"
    10  	"github.com/aws/aws-sdk-go/aws/awserr"
    11  	"github.com/aws/aws-sdk-go/service/simpledb"
    12  )
    13  
    14  func resourceAwsSimpleDBDomain() *schema.Resource {
    15  	return &schema.Resource{
    16  		Create: resourceAwsSimpleDBDomainCreate,
    17  		Read:   resourceAwsSimpleDBDomainRead,
    18  		Delete: resourceAwsSimpleDBDomainDelete,
    19  		Importer: &schema.ResourceImporter{
    20  			State: schema.ImportStatePassthrough,
    21  		},
    22  
    23  		Schema: map[string]*schema.Schema{
    24  			"name": &schema.Schema{
    25  				Type:     schema.TypeString,
    26  				Required: true,
    27  				ForceNew: true,
    28  			},
    29  		},
    30  	}
    31  }
    32  
    33  func resourceAwsSimpleDBDomainCreate(d *schema.ResourceData, meta interface{}) error {
    34  	conn := meta.(*AWSClient).simpledbconn
    35  
    36  	name := d.Get("name").(string)
    37  	input := &simpledb.CreateDomainInput{
    38  		DomainName: aws.String(name),
    39  	}
    40  	_, err := conn.CreateDomain(input)
    41  	if err != nil {
    42  		return fmt.Errorf("Create SimpleDB Domain failed: %s", err)
    43  	}
    44  
    45  	d.SetId(name)
    46  	return nil
    47  }
    48  
    49  func resourceAwsSimpleDBDomainRead(d *schema.ResourceData, meta interface{}) error {
    50  	conn := meta.(*AWSClient).simpledbconn
    51  
    52  	input := &simpledb.DomainMetadataInput{
    53  		DomainName: aws.String(d.Id()),
    54  	}
    55  	_, err := conn.DomainMetadata(input)
    56  	if awsErr, ok := err.(awserr.Error); ok {
    57  		if awsErr.Code() == "NoSuchDomain" {
    58  			log.Printf("[WARN] Removing SimpleDB domain %q because it's gone.", d.Id())
    59  			d.SetId("")
    60  			return nil
    61  		}
    62  	}
    63  	if err != nil {
    64  		return err
    65  	}
    66  
    67  	d.Set("name", d.Id())
    68  	return nil
    69  }
    70  
    71  func resourceAwsSimpleDBDomainDelete(d *schema.ResourceData, meta interface{}) error {
    72  	conn := meta.(*AWSClient).simpledbconn
    73  
    74  	input := &simpledb.DeleteDomainInput{
    75  		DomainName: aws.String(d.Id()),
    76  	}
    77  	_, err := conn.DeleteDomain(input)
    78  	if err != nil {
    79  		return fmt.Errorf("Delete SimpleDB Domain failed: %s", err)
    80  	}
    81  
    82  	d.SetId("")
    83  	return nil
    84  }