diff --git a/aws/config.go b/aws/config.go index c9a1081e2e7..3eeecebf423 100644 --- a/aws/config.go +++ b/aws/config.go @@ -76,6 +76,7 @@ import ( "github.com/aws/aws-sdk-go/service/sqs" "github.com/aws/aws-sdk-go/service/ssm" "github.com/aws/aws-sdk-go/service/sts" + "github.com/aws/aws-sdk-go/service/swf" "github.com/aws/aws-sdk-go/service/waf" "github.com/aws/aws-sdk-go/service/wafregional" "github.com/davecgh/go-spew/spew" @@ -195,6 +196,7 @@ type AWSClient struct { sdconn *servicediscovery.ServiceDiscovery sfnconn *sfn.SFN ssmconn *ssm.SSM + swfconn *swf.SWF wafconn *waf.WAF wafregionalconn *wafregional.WAFRegional iotconn *iot.IoT @@ -444,6 +446,7 @@ func (c *Config) Client() (interface{}, error) { client.snsconn = sns.New(awsSnsSess) client.sqsconn = sqs.New(awsSqsSess) client.ssmconn = ssm.New(sess) + client.swfconn = swf.New(sess) client.wafconn = waf.New(sess) client.wafregionalconn = wafregional.New(sess) client.batchconn = batch.New(sess) diff --git a/aws/provider.go b/aws/provider.go index 81a1dc110aa..c4419c0baa9 100644 --- a/aws/provider.go +++ b/aws/provider.go @@ -499,6 +499,7 @@ func Provider() terraform.ResourceProvider { "aws_sfn_state_machine": resourceAwsSfnStateMachine(), "aws_default_subnet": resourceAwsDefaultSubnet(), "aws_subnet": resourceAwsSubnet(), + "aws_swf_domain": resourceAwsSwfDomain(), "aws_volume_attachment": resourceAwsVolumeAttachment(), "aws_vpc_dhcp_options_association": resourceAwsVpcDhcpOptionsAssociation(), "aws_default_vpc_dhcp_options": resourceAwsDefaultVpcDhcpOptions(), diff --git a/aws/resource_aws_swf_domain.go b/aws/resource_aws_swf_domain.go new file mode 100644 index 00000000000..cf155c7d041 --- /dev/null +++ b/aws/resource_aws_swf_domain.go @@ -0,0 +1,126 @@ +package aws + +import ( + "fmt" + "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": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "description": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "workflow_execution_retention_period_in_days": &schema.Schema{ + 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() + } + d.Set("name", name) + + 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 { + return err + } + + info := resp.DomainInfo + config := resp.Configuration + d.Set("name", info.Name) + d.Set("description", info.Description) + d.Set("workflow_execution_retention_period_in_days", config.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 { + return err + } + + d.SetId("") + + return nil +} diff --git a/aws/resource_aws_swf_domain_test.go b/aws/resource_aws_swf_domain_test.go new file mode 100644 index 00000000000..ad16c159e0e --- /dev/null +++ b/aws/resource_aws_swf_domain_test.go @@ -0,0 +1,90 @@ +package aws + +import ( + "fmt" + "testing" + + "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/terraform" +) + +func TestAccAwsSwfDomain_basic(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAwsSwfDomainDestroy, + Steps: []resource.TestStep{ + { + Config: fmt.Sprintf(testAccAwsSwfDomainConfig, "test_swf_domain_"), + Check: testAccCheckAwsSwfDomainExists("aws_swf_domain.test"), + }, + }, + }) +} + +func testAccCheckAwsSwfDomainDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*AWSClient).swfconn + + for _, rs := range s.RootModule().Resources { + if rs.Type != "aws_swf_domain" { + continue + } + + name := rs.Primary.ID + input := &swf.DescribeDomainInput{ + Name: aws.String(name), + } + + resp, err := conn.DescribeDomain(input) + if err != nil { + return err + } + + if *resp.DomainInfo.Status != "DEPRECATED" { + return fmt.Errorf(`SWF Domain %s status is %s instead of "DEPRECATED". Failing!`, name, *resp.DomainInfo.Status) + } + } + + return nil +} + +func testAccCheckAwsSwfDomainExists(n string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("SWF Domain not found: %s", n) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("SWF Domain name not set") + } + + name := rs.Primary.ID + conn := testAccProvider.Meta().(*AWSClient).swfconn + + input := &swf.DescribeDomainInput{ + Name: aws.String(name), + } + + resp, err := conn.DescribeDomain(input) + if err != nil { + return fmt.Errorf("SWF Domain %s not found in AWS", name) + } + + if *resp.DomainInfo.Status != "REGISTERED" { + return fmt.Errorf(`SWF Domain %s status is %s instead of "REGISTERED". Failing!`, name, *resp.DomainInfo.Status) + } + return nil + } +} + +const testAccAwsSwfDomainConfig = ` +resource "aws_swf_domain" "test" { + name_prefix = "%s" + workflow_execution_retention_period_in_days = 1 +} +` diff --git a/website/aws.erb b/website/aws.erb index 6975f28532c..cec9acd2631 100644 --- a/website/aws.erb +++ b/website/aws.erb @@ -1615,6 +1615,16 @@ +