aws: Randomize opsworks application names in test

This commit is contained in:
Radek Simko 2017-03-13 08:05:41 +00:00
parent a67bddef98
commit 6293d7a4fc
No known key found for this signature in database
GPG Key ID: 6823F3DCCE01BB19
1 changed files with 21 additions and 10 deletions

View File

@ -8,25 +8,30 @@ import (
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/opsworks" "github.com/aws/aws-sdk-go/service/opsworks"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
func TestAccAWSOpsworksApplication(t *testing.T) { func TestAccAWSOpsworksApplication(t *testing.T) {
var opsapp opsworks.App var opsapp opsworks.App
rInt := acctest.RandInt()
name := fmt.Sprintf("tf-ops-acc-application-%d", rInt)
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckAwsOpsworksApplicationDestroy, CheckDestroy: testAccCheckAwsOpsworksApplicationDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccAwsOpsworksApplicationCreate, Config: testAccAwsOpsworksApplicationCreate(name),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSOpsworksApplicationExists( testAccCheckAWSOpsworksApplicationExists(
"aws_opsworks_application.tf-acc-app", &opsapp), "aws_opsworks_application.tf-acc-app", &opsapp),
testAccCheckAWSOpsworksCreateAppAttributes(&opsapp), testAccCheckAWSOpsworksCreateAppAttributes(&opsapp),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_opsworks_application.tf-acc-app", "name", "tf-ops-acc-application", "aws_opsworks_application.tf-acc-app", "name", name,
), ),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_opsworks_application.tf-acc-app", "type", "other", "aws_opsworks_application.tf-acc-app", "type", "other",
@ -58,13 +63,13 @@ func TestAccAWSOpsworksApplication(t *testing.T) {
), ),
}, },
resource.TestStep{ resource.TestStep{
Config: testAccAwsOpsworksApplicationUpdate, Config: testAccAwsOpsworksApplicationUpdate(name),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSOpsworksApplicationExists( testAccCheckAWSOpsworksApplicationExists(
"aws_opsworks_application.tf-acc-app", &opsapp), "aws_opsworks_application.tf-acc-app", &opsapp),
testAccCheckAWSOpsworksUpdateAppAttributes(&opsapp), testAccCheckAWSOpsworksUpdateAppAttributes(&opsapp),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_opsworks_application.tf-acc-app", "name", "tf-ops-acc-application", "aws_opsworks_application.tf-acc-app", "name", name,
), ),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_opsworks_application.tf-acc-app", "type", "rails", "aws_opsworks_application.tf-acc-app", "type", "rails",
@ -308,10 +313,12 @@ func testAccCheckAwsOpsworksApplicationDestroy(s *terraform.State) error {
return nil return nil
} }
var testAccAwsOpsworksApplicationCreate = testAccAwsOpsworksStackConfigVpcCreate("tf-ops-acc-application") + ` func testAccAwsOpsworksApplicationCreate(name string) string {
return testAccAwsOpsworksStackConfigVpcCreate(name) +
fmt.Sprintf(`
resource "aws_opsworks_application" "tf-acc-app" { resource "aws_opsworks_application" "tf-acc-app" {
stack_id = "${aws_opsworks_stack.tf-acc.id}" stack_id = "${aws_opsworks_stack.tf-acc.id}"
name = "tf-ops-acc-application" name = "%s"
type = "other" type = "other"
enable_ssl = false enable_ssl = false
app_source ={ app_source ={
@ -320,12 +327,15 @@ resource "aws_opsworks_application" "tf-acc-app" {
environment = { key = "key1" value = "value1" secure = false} environment = { key = "key1" value = "value1" secure = false}
document_root = "foo" document_root = "foo"
} }
` `, name)
}
var testAccAwsOpsworksApplicationUpdate = testAccAwsOpsworksStackConfigVpcCreate("tf-ops-acc-application") + ` func testAccAwsOpsworksApplicationUpdate(name string) string {
return testAccAwsOpsworksStackConfigVpcCreate(name) +
fmt.Sprintf(`
resource "aws_opsworks_application" "tf-acc-app" { resource "aws_opsworks_application" "tf-acc-app" {
stack_id = "${aws_opsworks_stack.tf-acc.id}" stack_id = "${aws_opsworks_stack.tf-acc.id}"
name = "tf-ops-acc-application" name = "%s"
type = "rails" type = "rails"
domains = ["example.com", "sub.example.com"] domains = ["example.com", "sub.example.com"]
enable_ssl = true enable_ssl = true
@ -372,4 +382,5 @@ EOS
auto_bundle_on_deploy = "true" auto_bundle_on_deploy = "true"
rails_env = "staging" rails_env = "staging"
} }
` `, name)
}