Skip to content

Commit

Permalink
resource/aws_swf_domain: Address #2803 PR feedback
Browse files Browse the repository at this point in the history
make testacc TEST=./aws TESTARGS='-run=TestAccAWSSwfDomain'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSSwfDomain -timeout 120m
=== RUN   TestAccAWSSwfDomain_basic
--- PASS: TestAccAWSSwfDomain_basic (13.01s)
=== RUN   TestAccAWSSwfDomain_NamePrefix
--- PASS: TestAccAWSSwfDomain_NamePrefix (11.40s)
=== RUN   TestAccAWSSwfDomain_GeneratedName
--- PASS: TestAccAWSSwfDomain_GeneratedName (12.78s)
=== RUN   TestAccAWSSwfDomain_Description
--- PASS: TestAccAWSSwfDomain_Description (11.61s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	48.829s
  • Loading branch information
bflad committed Jul 9, 2018
1 parent 4a7b508 commit ec25406
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 26 deletions.
46 changes: 30 additions & 16 deletions aws/resource_aws_swf_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws

import (
"fmt"
"log"
"strconv"

"github.com/aws/aws-sdk-go/aws"
Expand All @@ -27,17 +28,18 @@ func resourceAwsSwfDomain() *schema.Resource {
ForceNew: true,
ConflictsWith: []string{"name_prefix"},
},
"name_prefix": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
"name_prefix": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ConflictsWith: []string{"name"},
},
"description": &schema.Schema{
"description": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"workflow_execution_retention_period_in_days": &schema.Schema{
"workflow_execution_retention_period_in_days": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Expand Down Expand Up @@ -66,7 +68,6 @@ func resourceAwsSwfDomainCreate(d *schema.ResourceData, meta interface{}) error
} else {
name = resource.UniqueId()
}
d.Set("name", name)

input := &swf.RegisterDomainInput{
Name: aws.String(name),
Expand Down Expand Up @@ -96,14 +97,23 @@ func resourceAwsSwfDomainRead(d *schema.ResourceData, meta interface{}) error {

resp, err := conn.DescribeDomain(input)
if err != nil {
return err
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
}

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)
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
}
Expand All @@ -117,10 +127,14 @@ func resourceAwsSwfDomainDelete(d *schema.ResourceData, meta interface{}) error

_, err := conn.DeprecateDomain(input)
if err != nil {
return err
if isAWSErr(err, swf.ErrCodeDomainDeprecatedFault, "") {
return nil
}
if isAWSErr(err, swf.ErrCodeUnknownResourceFault, "") {
return nil
}
return fmt.Errorf("error deleting SWF Domain: %s", err)
}

d.SetId("")

return nil
}
130 changes: 124 additions & 6 deletions aws/resource_aws_swf_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,47 @@ package aws

import (
"fmt"
"regexp"
"testing"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/swf"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)

func TestAccAwsSwfDomain_basic(t *testing.T) {
func TestAccAWSSwfDomain_basic(t *testing.T) {
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_swf_domain.test"

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsSwfDomainDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSSwfDomainConfig_Name(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAwsSwfDomainExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "description", ""),
resource.TestCheckResourceAttr(resourceName, "name", rName),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAWSSwfDomain_NamePrefix(t *testing.T) {
resourceName := "aws_swf_domain.test"

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
Expand All @@ -19,8 +51,69 @@ func TestAccAwsSwfDomain_basic(t *testing.T) {
CheckDestroy: testAccCheckAwsSwfDomainDestroy,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(testAccAwsSwfDomainConfig, "test_swf_domain_"),
Check: testAccCheckAwsSwfDomainExists("aws_swf_domain.test"),
Config: testAccAWSSwfDomainConfig_NamePrefix,
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAwsSwfDomainExists(resourceName),
resource.TestMatchResourceAttr(resourceName, "name", regexp.MustCompile(`^tf-acc-test`)),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"name_prefix"}, // this line is only necessary if the test configuration is using name_prefix
},
},
})
}

func TestAccAWSSwfDomain_GeneratedName(t *testing.T) {
resourceName := "aws_swf_domain.test"

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsSwfDomainDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSSwfDomainConfig_GeneratedName,
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAwsSwfDomainExists(resourceName),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAWSSwfDomain_Description(t *testing.T) {
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_swf_domain.test"

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsSwfDomainDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSSwfDomainConfig_Description(rName, "description1"),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAwsSwfDomainExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "description", "description1"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
Expand Down Expand Up @@ -82,9 +175,34 @@ func testAccCheckAwsSwfDomainExists(n string) resource.TestCheckFunc {
}
}

const testAccAwsSwfDomainConfig = `
func testAccAWSSwfDomainConfig_Description(rName, description string) string {
return fmt.Sprintf(`
resource "aws_swf_domain" "test" {
description = %q
name = %q
workflow_execution_retention_period_in_days = 1
}
`, description, rName)
}

const testAccAWSSwfDomainConfig_GeneratedName = `
resource "aws_swf_domain" "test" {
workflow_execution_retention_period_in_days = 1
}
`

func testAccAWSSwfDomainConfig_Name(rName string) string {
return fmt.Sprintf(`
resource "aws_swf_domain" "test" {
name = %q
workflow_execution_retention_period_in_days = 1
}
`, rName)
}

const testAccAWSSwfDomainConfig_NamePrefix = `
resource "aws_swf_domain" "test" {
name_prefix = "%s"
workflow_execution_retention_period_in_days = 1
name_prefix = "tf-acc-test"
workflow_execution_retention_period_in_days = 1
}
`
6 changes: 2 additions & 4 deletions website/docs/r/swf_domain.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ The following arguments are supported:

## Attributes Reference

The following attributes are exported:
In addition to all arguments above, 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.
* `id` - The name of the domain.

## Import

Expand Down

0 comments on commit ec25406

Please sign in to comment.