forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 2
/
resource_aws_sfn_activity.go
97 lines (78 loc) · 2.31 KB
/
resource_aws_sfn_activity.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
package aws
import (
"fmt"
"log"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/sfn"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
)
func resourceAwsSfnActivity() *schema.Resource {
return &schema.Resource{
Create: resourceAwsSfnActivityCreate,
Read: resourceAwsSfnActivityRead,
Delete: resourceAwsSfnActivityDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validateSfnActivityName,
},
"creation_date": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
func resourceAwsSfnActivityCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).sfnconn
log.Print("[DEBUG] Creating Step Function Activity")
params := &sfn.CreateActivityInput{
Name: aws.String(d.Get("name").(string)),
}
activity, err := conn.CreateActivity(params)
if err != nil {
return fmt.Errorf("Error creating Step Function Activity: %s", err)
}
d.SetId(*activity.ActivityArn)
return resourceAwsSfnActivityRead(d, meta)
}
func resourceAwsSfnActivityRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).sfnconn
log.Printf("[DEBUG] Reading Step Function Activity: %s", d.Id())
sm, err := conn.DescribeActivity(&sfn.DescribeActivityInput{
ActivityArn: aws.String(d.Id()),
})
if err != nil {
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "ActivityDoesNotExist" {
d.SetId("")
return nil
}
return err
}
d.Set("name", sm.Name)
if err := d.Set("creation_date", sm.CreationDate.Format(time.RFC3339)); err != nil {
log.Printf("[DEBUG] Error setting creation_date: %s", err)
}
return nil
}
func resourceAwsSfnActivityDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).sfnconn
log.Printf("[DEBUG] Deleting Step Functions Activity: %s", d.Id())
return resource.Retry(5*time.Minute, func() *resource.RetryError {
_, err := conn.DeleteActivity(&sfn.DeleteActivityInput{
ActivityArn: aws.String(d.Id()),
})
if err == nil {
return nil
}
return resource.NonRetryableError(err)
})
}