diff --git a/builtin/providers/aws/resource_aws_directory_service_directory_test.go b/builtin/providers/aws/resource_aws_directory_service_directory_test.go index 779e56df4..a0dce9524 100644 --- a/builtin/providers/aws/resource_aws_directory_service_directory_test.go +++ b/builtin/providers/aws/resource_aws_directory_service_directory_test.go @@ -8,6 +8,7 @@ import ( "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/directoryservice" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) @@ -316,7 +317,7 @@ resource "aws_subnet" "bar" { } ` -var randomInteger = genRandInt() +var randomInteger = acctest.RandInt() var testAccDirectoryServiceDirectoryConfig_withAlias = fmt.Sprintf(` resource "aws_directory_service_directory" "bar_a" { name = "corp.notexample.com" diff --git a/builtin/providers/aws/resource_aws_elasticache_cluster.go b/builtin/providers/aws/resource_aws_elasticache_cluster.go index 8e34b01ca..765a65310 100644 --- a/builtin/providers/aws/resource_aws_elasticache_cluster.go +++ b/builtin/providers/aws/resource_aws_elasticache_cluster.go @@ -539,7 +539,7 @@ func resourceAwsElasticacheClusterDelete(d *schema.ResourceData, meta interface{ Pending: []string{"creating", "available", "deleting", "incompatible-parameters", "incompatible-network", "restore-failed"}, Target: []string{}, Refresh: cacheClusterStateRefreshFunc(conn, d.Id(), "", []string{}), - Timeout: 10 * time.Minute, + Timeout: 20 * time.Minute, Delay: 10 * time.Second, MinTimeout: 3 * time.Second, } diff --git a/builtin/providers/aws/resource_aws_elasticache_cluster_test.go b/builtin/providers/aws/resource_aws_elasticache_cluster_test.go index 3cbc4790a..7d0371eaa 100644 --- a/builtin/providers/aws/resource_aws_elasticache_cluster_test.go +++ b/builtin/providers/aws/resource_aws_elasticache_cluster_test.go @@ -2,14 +2,13 @@ package aws import ( "fmt" - "math/rand" "strings" "testing" - "time" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/elasticache" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) @@ -37,9 +36,9 @@ func TestAccAWSElasticacheCluster_basic(t *testing.T) { func TestAccAWSElasticacheCluster_snapshotsWithUpdates(t *testing.T) { var ec elasticache.CacheCluster - ri := genRandInt() - preConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfig_snapshots, ri, ri, ri) - postConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfig_snapshotsUpdated, ri, ri, ri) + ri := acctest.RandInt() + preConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfig_snapshots, ri, ri, acctest.RandString(10)) + postConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfig_snapshotsUpdated, ri, ri, acctest.RandString(10)) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -76,9 +75,9 @@ func TestAccAWSElasticacheCluster_snapshotsWithUpdates(t *testing.T) { func TestAccAWSElasticacheCluster_decreasingCacheNodes(t *testing.T) { var ec elasticache.CacheCluster - ri := genRandInt() - preConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfigDecreasingNodes, ri, ri, ri) - postConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfigDecreasingNodes_update, ri, ri, ri) + ri := acctest.RandInt() + preConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfigDecreasingNodes, ri, ri, acctest.RandString(10)) + postConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfigDecreasingNodes_update, ri, ri, acctest.RandString(10)) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -218,10 +217,6 @@ func testAccCheckAWSElasticacheClusterExists(n string, v *elasticache.CacheClust } } -func genRandInt() int { - return rand.New(rand.NewSource(time.Now().UnixNano())).Int() % 1000 -} - var testAccAWSElasticacheClusterConfig = fmt.Sprintf(` provider "aws" { region = "us-east-1" @@ -244,7 +239,7 @@ resource "aws_elasticache_security_group" "bar" { } resource "aws_elasticache_cluster" "bar" { - cluster_id = "tf-test-%03d" + cluster_id = "tf-%s" engine = "memcached" node_type = "cache.m1.small" num_cache_nodes = 1 @@ -252,7 +247,7 @@ resource "aws_elasticache_cluster" "bar" { parameter_group_name = "default.memcached1.4" security_group_names = ["${aws_elasticache_security_group.bar.name}"] } -`, genRandInt(), genRandInt(), genRandInt()) +`, acctest.RandInt(), acctest.RandInt(), acctest.RandString(10)) var testAccAWSElasticacheClusterConfig_snapshots = ` provider "aws" { @@ -276,7 +271,7 @@ resource "aws_elasticache_security_group" "bar" { } resource "aws_elasticache_cluster" "bar" { - cluster_id = "tf-test-%03d" + cluster_id = "tf-%s" engine = "redis" node_type = "cache.m1.small" num_cache_nodes = 1 @@ -310,7 +305,7 @@ resource "aws_elasticache_security_group" "bar" { } resource "aws_elasticache_cluster" "bar" { - cluster_id = "tf-test-%03d" + cluster_id = "tf-%s" engine = "redis" node_type = "cache.m1.small" num_cache_nodes = 1 @@ -345,7 +340,7 @@ resource "aws_elasticache_security_group" "bar" { } resource "aws_elasticache_cluster" "bar" { - cluster_id = "tf-test-%03d" + cluster_id = "tf-%s" engine = "memcached" node_type = "cache.m1.small" num_cache_nodes = 3 @@ -377,7 +372,7 @@ resource "aws_elasticache_security_group" "bar" { } resource "aws_elasticache_cluster" "bar" { - cluster_id = "tf-test-%03d" + cluster_id = "tf-%s" engine = "memcached" node_type = "cache.m1.small" num_cache_nodes = 1 @@ -427,7 +422,7 @@ resource "aws_elasticache_cluster" "bar" { // Including uppercase letters in this name to ensure // that we correctly handle the fact that the API // normalizes names to lowercase. - cluster_id = "tf-TEST-%03d" + cluster_id = "tf-%s" node_type = "cache.m1.small" num_cache_nodes = 1 engine = "redis" @@ -443,7 +438,7 @@ resource "aws_elasticache_cluster" "bar" { resource "aws_sns_topic" "topic_example" { name = "tf-ecache-cluster-test" } -`, genRandInt(), genRandInt(), genRandInt()) +`, acctest.RandInt(), acctest.RandInt(), acctest.RandString(10)) var testAccAWSElasticacheClusterMultiAZInVPCConfig = fmt.Sprintf(` resource "aws_vpc" "foo" { @@ -493,7 +488,7 @@ resource "aws_security_group" "bar" { } resource "aws_elasticache_cluster" "bar" { - cluster_id = "tf-test-%03d" + cluster_id = "tf-%s" engine = "memcached" node_type = "cache.m1.small" num_cache_nodes = 2 @@ -507,4 +502,4 @@ resource "aws_elasticache_cluster" "bar" { "us-west-2b" ] } -`, genRandInt(), genRandInt(), genRandInt(), genRandInt(), genRandInt()) +`, acctest.RandInt(), acctest.RandInt(), acctest.RandInt(), acctest.RandInt(), acctest.RandString(10)) diff --git a/builtin/providers/aws/resource_aws_elasticache_security_group_test.go b/builtin/providers/aws/resource_aws_elasticache_security_group_test.go index 452e7b896..009a2d809 100644 --- a/builtin/providers/aws/resource_aws_elasticache_security_group_test.go +++ b/builtin/providers/aws/resource_aws_elasticache_security_group_test.go @@ -7,6 +7,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/elasticache" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) @@ -91,4 +92,4 @@ resource "aws_elasticache_security_group" "bar" { description = "tf-test-security-group-descr" security_group_names = ["${aws_security_group.bar.name}"] } -`, genRandInt(), genRandInt()) +`, acctest.RandInt(), acctest.RandInt()) diff --git a/builtin/providers/aws/resource_aws_elasticache_subnet_group_test.go b/builtin/providers/aws/resource_aws_elasticache_subnet_group_test.go index 55fe25cbc..0918b8a14 100644 --- a/builtin/providers/aws/resource_aws_elasticache_subnet_group_test.go +++ b/builtin/providers/aws/resource_aws_elasticache_subnet_group_test.go @@ -7,13 +7,14 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/elasticache" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) func TestAccAWSElasticacheSubnetGroup_basic(t *testing.T) { var csg elasticache.CacheSubnetGroup - config := fmt.Sprintf(testAccAWSElasticacheSubnetGroupConfig, genRandInt()) + config := fmt.Sprintf(testAccAWSElasticacheSubnetGroupConfig, acctest.RandInt()) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -33,7 +34,7 @@ func TestAccAWSElasticacheSubnetGroup_basic(t *testing.T) { func TestAccAWSElasticacheSubnetGroup_update(t *testing.T) { var csg elasticache.CacheSubnetGroup rn := "aws_elasticache_subnet_group.bar" - ri := genRandInt() + ri := acctest.RandInt() preConfig := fmt.Sprintf(testAccAWSElasticacheSubnetGroupUpdateConfigPre, ri) postConfig := fmt.Sprintf(testAccAWSElasticacheSubnetGroupUpdateConfigPost, ri) diff --git a/builtin/providers/aws/resource_aws_network_interface_test.go b/builtin/providers/aws/resource_aws_network_interface_test.go index bcddd87f9..421817eb1 100644 --- a/builtin/providers/aws/resource_aws_network_interface_test.go +++ b/builtin/providers/aws/resource_aws_network_interface_test.go @@ -333,7 +333,7 @@ resource "aws_subnet" "foo" { cidr_block = "172.16.10.0/24" availability_zone = "us-west-2a" tags { - Name = "tf-eni-test" + Name = "tf-foo-eni-test" } } @@ -342,7 +342,7 @@ resource "aws_subnet" "bar" { cidr_block = "172.16.11.0/24" availability_zone = "us-west-2a" tags { - Name = "tf-eni-test" + Name = "tf-bar-eni-test" } } @@ -359,7 +359,7 @@ resource "aws_instance" "foo" { associate_public_ip_address = false private_ip = "172.16.11.50" tags { - Name = "tf-eni-test" + Name = "foo-tf-eni-test" } } diff --git a/builtin/providers/aws/resource_aws_s3_bucket_test.go b/builtin/providers/aws/resource_aws_s3_bucket_test.go index 9030b49b6..8a591c4bc 100644 --- a/builtin/providers/aws/resource_aws_s3_bucket_test.go +++ b/builtin/providers/aws/resource_aws_s3_bucket_test.go @@ -74,7 +74,7 @@ func TestAccAWSS3Bucket_Policy(t *testing.T) { } func TestAccAWSS3Bucket_UpdateAcl(t *testing.T) { - ri := genRandInt() + ri := acctest.RandInt() preConfig := fmt.Sprintf(testAccAWSS3BucketConfigWithAcl, ri) postConfig := fmt.Sprintf(testAccAWSS3BucketConfigWithAclUpdate, ri) diff --git a/builtin/providers/aws/resource_aws_security_group_rule_test.go b/builtin/providers/aws/resource_aws_security_group_rule_test.go index 5cf96dace..7f6fa6d6f 100644 --- a/builtin/providers/aws/resource_aws_security_group_rule_test.go +++ b/builtin/providers/aws/resource_aws_security_group_rule_test.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/ec2" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) @@ -750,7 +751,7 @@ var testAccAWSSecurityGroupRuleRace = func() string { name = "tf-sg-rule-race-group-%d" vpc_id = "${aws_vpc.default.id}" } - `, genRandInt())) + `, acctest.RandInt())) for i := 1; i < iterations; i++ { b.WriteString(fmt.Sprintf(` resource "aws_security_group_rule" "ingress%d" { diff --git a/builtin/providers/azure/provider_test.go b/builtin/providers/azure/provider_test.go index 57e852ce0..8e88dea93 100644 --- a/builtin/providers/azure/provider_test.go +++ b/builtin/providers/azure/provider_test.go @@ -3,11 +3,9 @@ package azure import ( "io" "io/ioutil" - "math/rand" "os" "strings" "testing" - "time" "github.com/hashicorp/terraform/config" "github.com/hashicorp/terraform/helper/schema" @@ -154,10 +152,6 @@ func TestAzure_providerConfigure(t *testing.T) { } } -func genRandInt() int { - return rand.New(rand.NewSource(time.Now().UnixNano())).Int() % 100000 -} - // testAzurePublishSettingsStr is a revoked publishsettings file const testAzurePublishSettingsStr = ` diff --git a/builtin/providers/azure/resource_azure_data_disk_test.go b/builtin/providers/azure/resource_azure_data_disk_test.go index 2c6660f66..fbbfc0018 100644 --- a/builtin/providers/azure/resource_azure_data_disk_test.go +++ b/builtin/providers/azure/resource_azure_data_disk_test.go @@ -7,13 +7,14 @@ import ( "github.com/Azure/azure-sdk-for-go/management" "github.com/Azure/azure-sdk-for-go/management/virtualmachinedisk" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) func TestAccAzureDataDisk_basic(t *testing.T) { var disk virtualmachinedisk.DataDiskResponse - name := fmt.Sprintf("terraform-test%d", genRandInt()) + name := fmt.Sprintf("terraform-test%d", acctest.RandInt()) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -38,7 +39,7 @@ func TestAccAzureDataDisk_basic(t *testing.T) { func TestAccAzureDataDisk_update(t *testing.T) { var disk virtualmachinedisk.DataDiskResponse - name := fmt.Sprintf("terraform-test%d", genRandInt()) + name := fmt.Sprintf("terraform-test%d", acctest.RandInt()) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, diff --git a/builtin/providers/google/resource_sql_database_instance_test.go b/builtin/providers/google/resource_sql_database_instance_test.go index fda17660e..865dde538 100644 --- a/builtin/providers/google/resource_sql_database_instance_test.go +++ b/builtin/providers/google/resource_sql_database_instance_test.go @@ -12,6 +12,7 @@ import ( "strconv" "testing" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -20,7 +21,7 @@ import ( func TestAccGoogleSqlDatabaseInstance_basic(t *testing.T) { var instance sqladmin.DatabaseInstance - databaseID := genRandInt() + databaseID := acctest.RandInt() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -64,7 +65,7 @@ func TestAccGoogleSqlDatabaseInstance_basic2(t *testing.T) { func TestAccGoogleSqlDatabaseInstance_settings_basic(t *testing.T) { var instance sqladmin.DatabaseInstance - databaseID := genRandInt() + databaseID := acctest.RandInt() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -87,7 +88,7 @@ func TestAccGoogleSqlDatabaseInstance_settings_basic(t *testing.T) { func TestAccGoogleSqlDatabaseInstance_settings_upgrade(t *testing.T) { var instance sqladmin.DatabaseInstance - databaseID := genRandInt() + databaseID := acctest.RandInt() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -120,7 +121,7 @@ func TestAccGoogleSqlDatabaseInstance_settings_upgrade(t *testing.T) { func TestAccGoogleSqlDatabaseInstance_settings_downgrade(t *testing.T) { var instance sqladmin.DatabaseInstance - databaseID := genRandInt() + databaseID := acctest.RandInt() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, diff --git a/builtin/providers/google/test_util.go b/builtin/providers/google/test_util.go deleted file mode 100644 index 09fcaaffa..000000000 --- a/builtin/providers/google/test_util.go +++ /dev/null @@ -1,10 +0,0 @@ -package google - -import ( - "math/rand" - "time" -) - -func genRandInt() int { - return rand.New(rand.NewSource(time.Now().UnixNano())).Int() -}