Skip to content

Commit

Permalink
resource/aws_servicecatalog_portfolio: Replace IdempotencyToken time.…
Browse files Browse the repository at this point in the history
…Now() usage with resource.UniqueId()

Reference: #9470

The implementation of `resource.UniqueId()` includes a monotonic counter, so it is safer for concurrent operations.

Output from acceptance testing:

```
--- PASS: TestAccAWSServiceCatalogPortfolio_Disappears (10.62s)
--- PASS: TestAccAWSServiceCatalogPortfolio_Import (13.26s)
--- PASS: TestAccAWSServiceCatalogPortfolio_Basic (29.31s)
```
  • Loading branch information
bflad committed Jul 24, 2019
1 parent e78d213 commit 87123fb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
9 changes: 4 additions & 5 deletions aws/resource_aws_servicecatalog_portfolio.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/servicecatalog"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
)
Expand Down Expand Up @@ -61,12 +62,10 @@ func resourceAwsServiceCatalogPortfolio() *schema.Resource {
func resourceAwsServiceCatalogPortfolioCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).scconn
input := servicecatalog.CreatePortfolioInput{
AcceptLanguage: aws.String("en"),
AcceptLanguage: aws.String("en"),
DisplayName: aws.String(d.Get("name").(string)),
IdempotencyToken: aws.String(resource.UniqueId()),
}
name := d.Get("name").(string)
input.DisplayName = &name
now := time.Now()
input.IdempotencyToken = aws.String(fmt.Sprintf("%d", now.UnixNano()))

if v, ok := d.GetOk("description"); ok {
input.Description = aws.String(v.(string))
Expand Down
6 changes: 3 additions & 3 deletions aws/resource_aws_servicecatalog_portfolio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"testing"
)

func TestAccAWSServiceCatalogPortfolioBasic(t *testing.T) {
func TestAccAWSServiceCatalogPortfolio_Basic(t *testing.T) {
name := acctest.RandString(5)
var dpo servicecatalog.DescribePortfolioOutput
resource.ParallelTest(t, resource.TestCase{
Expand Down Expand Up @@ -65,7 +65,7 @@ func TestAccAWSServiceCatalogPortfolioBasic(t *testing.T) {
})
}

func TestAccAWSServiceCatalogPortfolioDisappears(t *testing.T) {
func TestAccAWSServiceCatalogPortfolio_Disappears(t *testing.T) {
name := acctest.RandString(5)
var dpo servicecatalog.DescribePortfolioOutput
resource.ParallelTest(t, resource.TestCase{
Expand All @@ -85,7 +85,7 @@ func TestAccAWSServiceCatalogPortfolioDisappears(t *testing.T) {
})
}

func TestAccAWSServiceCatalogPortfolioImport(t *testing.T) {
func TestAccAWSServiceCatalogPortfolio_Import(t *testing.T) {
resourceName := "aws_servicecatalog_portfolio.test"

name := acctest.RandString(5)
Expand Down

0 comments on commit 87123fb

Please sign in to comment.