forked from hashicorp/terraform-provider-aws
/
resource_aws_swf_domain.go
140 lines (118 loc) · 3.43 KB
/
resource_aws_swf_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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package aws
import (
"fmt"
"log"
"strconv"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/swf"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
)
func resourceAwsSwfDomain() *schema.Resource {
return &schema.Resource{
Create: resourceAwsSwfDomainCreate,
Read: resourceAwsSwfDomainRead,
Delete: resourceAwsSwfDomainDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ConflictsWith: []string{"name_prefix"},
},
"name_prefix": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ConflictsWith: []string{"name"},
},
"description": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"workflow_execution_retention_period_in_days": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: func(v interface{}, k string) (ws []string, es []error) {
value, err := strconv.Atoi(v.(string))
if err != nil || value > 90 || value < 0 {
es = append(es, fmt.Errorf(
"%q must be between 0 and 90 days inclusive", k))
}
return
},
},
},
}
}
func resourceAwsSwfDomainCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).swfconn
var name string
if v, ok := d.GetOk("name"); ok {
name = v.(string)
} else if v, ok := d.GetOk("name_prefix"); ok {
name = resource.PrefixedUniqueId(v.(string))
} else {
name = resource.UniqueId()
}
input := &swf.RegisterDomainInput{
Name: aws.String(name),
WorkflowExecutionRetentionPeriodInDays: aws.String(d.Get("workflow_execution_retention_period_in_days").(string)),
}
if v, ok := d.GetOk("description"); ok {
input.Description = aws.String(v.(string))
}
_, err := conn.RegisterDomain(input)
if err != nil {
return err
}
d.SetId(name)
return resourceAwsSwfDomainRead(d, meta)
}
func resourceAwsSwfDomainRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).swfconn
input := &swf.DescribeDomainInput{
Name: aws.String(d.Id()),
}
resp, err := conn.DescribeDomain(input)
if err != nil {
if isAWSErr(err, swf.ErrCodeUnknownResourceFault, "") {
log.Printf("[WARN] SWF Domain %q not found, removing from state", d.Id())
d.SetId("")
return nil
}
return fmt.Errorf("error reading SWF Domain: %s", err)
}
if resp == nil || resp.Configuration == nil || resp.DomainInfo == nil {
log.Printf("[WARN] SWF Domain %q not found, removing from state", d.Id())
d.SetId("")
return nil
}
d.Set("name", resp.DomainInfo.Name)
d.Set("description", resp.DomainInfo.Description)
d.Set("workflow_execution_retention_period_in_days", resp.Configuration.WorkflowExecutionRetentionPeriodInDays)
return nil
}
func resourceAwsSwfDomainDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).swfconn
input := &swf.DeprecateDomainInput{
Name: aws.String(d.Get("name").(string)),
}
_, err := conn.DeprecateDomain(input)
if err != nil {
if isAWSErr(err, swf.ErrCodeDomainDeprecatedFault, "") {
return nil
}
if isAWSErr(err, swf.ErrCodeUnknownResourceFault, "") {
return nil
}
return fmt.Errorf("error deleting SWF Domain: %s", err)
}
return nil
}