forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 2
/
resource_aws_simpledb_domain.go
84 lines (70 loc) · 1.85 KB
/
resource_aws_simpledb_domain.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
}