github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/aws/resource_aws_sfn_activity.go (about) 1 package aws 2 3 import ( 4 "fmt" 5 "log" 6 "time" 7 8 "github.com/aws/aws-sdk-go/aws" 9 "github.com/aws/aws-sdk-go/aws/awserr" 10 "github.com/aws/aws-sdk-go/service/sfn" 11 "github.com/hashicorp/terraform/helper/resource" 12 "github.com/hashicorp/terraform/helper/schema" 13 ) 14 15 func resourceAwsSfnActivity() *schema.Resource { 16 return &schema.Resource{ 17 Create: resourceAwsSfnActivityCreate, 18 Read: resourceAwsSfnActivityRead, 19 Delete: resourceAwsSfnActivityDelete, 20 Importer: &schema.ResourceImporter{ 21 State: schema.ImportStatePassthrough, 22 }, 23 24 Schema: map[string]*schema.Schema{ 25 "name": { 26 Type: schema.TypeString, 27 Required: true, 28 ForceNew: true, 29 ValidateFunc: validateSfnActivityName, 30 }, 31 32 "creation_date": { 33 Type: schema.TypeString, 34 Computed: true, 35 }, 36 }, 37 } 38 } 39 40 func resourceAwsSfnActivityCreate(d *schema.ResourceData, meta interface{}) error { 41 conn := meta.(*AWSClient).sfnconn 42 log.Print("[DEBUG] Creating Step Function Activity") 43 44 params := &sfn.CreateActivityInput{ 45 Name: aws.String(d.Get("name").(string)), 46 } 47 48 activity, err := conn.CreateActivity(params) 49 if err != nil { 50 return fmt.Errorf("Error creating Step Function Activity: %s", err) 51 } 52 53 d.SetId(*activity.ActivityArn) 54 55 return resourceAwsSfnActivityRead(d, meta) 56 } 57 58 func resourceAwsSfnActivityRead(d *schema.ResourceData, meta interface{}) error { 59 conn := meta.(*AWSClient).sfnconn 60 log.Printf("[DEBUG] Reading Step Function Activity: %s", d.Id()) 61 62 sm, err := conn.DescribeActivity(&sfn.DescribeActivityInput{ 63 ActivityArn: aws.String(d.Id()), 64 }) 65 if err != nil { 66 if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "ActivityDoesNotExist" { 67 d.SetId("") 68 return nil 69 } 70 return err 71 } 72 73 d.Set("name", sm.Name) 74 75 if err := d.Set("creation_date", sm.CreationDate.Format(time.RFC3339)); err != nil { 76 log.Printf("[DEBUG] Error setting creation_date: %s", err) 77 } 78 79 return nil 80 } 81 82 func resourceAwsSfnActivityDelete(d *schema.ResourceData, meta interface{}) error { 83 conn := meta.(*AWSClient).sfnconn 84 log.Printf("[DEBUG] Deleting Step Functions Activity: %s", d.Id()) 85 86 return resource.Retry(5*time.Minute, func() *resource.RetryError { 87 _, err := conn.DeleteActivity(&sfn.DeleteActivityInput{ 88 ActivityArn: aws.String(d.Id()), 89 }) 90 91 if err == nil { 92 return nil 93 } 94 95 return resource.NonRetryableError(err) 96 }) 97 }