-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Robin Joseph
committed
Jan 14, 2018
1 parent
984d50b
commit 58e1493
Showing
6 changed files
with
278 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
layout: "aws" | ||
page_title: "AWS: aws_swf_domain" | ||
sidebar_current: "docs-aws-resource-swf-domain" | ||
description: |- | ||
Provides an SWF Domain resource | ||
--- | ||
|
||
# aws_swf_domain | ||
|
||
Provides an SWF Domain resource. | ||
|
||
## Example Usage | ||
|
||
To register a basic SWF domain: | ||
|
||
```hcl | ||
resource "aws_swf_domain" "foo" { | ||
name = "foo" | ||
description = "Terraform SWF Domain" | ||
workflow_execution_retention_period_in_days = 30 | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name` - (Optional, Forces new resource) The name of the domain. If omitted, Terraform will assign a random, unique name. | ||
* `name_prefix` - (Optional, Forces new resource) Creates a unique name beginning with the specified prefix. Conflicts with `name`. | ||
* `description` - (Optional, Forces new resource) The domain description. | ||
* `workflow_execution_retention_period_in_days` - (Required, Forces new resource) Length of time that SWF will continue to retain information about the workflow execution after the workflow execution is complete, must be between 0 and 90 days. | ||
|
||
## Attributes Reference | ||
|
||
The following attributes are exported: | ||
|
||
* `name` - The name of the parameter. | ||
* `description` - The domain description. | ||
* `workflow_execution_retention_period_in_days` - Length of time that SWF will continue to retain information about the workflow execution after the workflow execution is complete. | ||
|
||
## Import | ||
|
||
SWF Domains can be imported using the `name`, e.g. | ||
|
||
``` | ||
$ terraform import aws_swf_domain.foo test-domain | ||
``` |