本文整理匯總了Golang中github.com/hashicorp/terraform/helper/acctest.RandInt函數的典型用法代碼示例。如果您正苦於以下問題:Golang RandInt函數的具體用法?Golang RandInt怎麽用?Golang RandInt使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了RandInt函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestAccAWSUser_basic
func TestAccAWSUser_basic(t *testing.T) {
var conf iam.GetUserOutput
name1 := fmt.Sprintf("test-user-%d", acctest.RandInt())
name2 := fmt.Sprintf("test-user-%d", acctest.RandInt())
path1 := "/"
path2 := "/path2/"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSUserDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSUserConfig(name1, path1),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSUserExists("aws_iam_user.user", &conf),
testAccCheckAWSUserAttributes(&conf, name1, "/"),
),
},
resource.TestStep{
Config: testAccAWSUserConfig(name2, path2),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSUserExists("aws_iam_user.user", &conf),
testAccCheckAWSUserAttributes(&conf, name2, "/path2/"),
),
},
},
})
}
示例2: TestAccAWSOpsworksUserProfile
func TestAccAWSOpsworksUserProfile(t *testing.T) {
rName := fmt.Sprintf("test-user-%d", acctest.RandInt())
roleName := fmt.Sprintf("tf-ops-user-profile-%d", acctest.RandInt())
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsOpsworksUserProfileDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAwsOpsworksUserProfileCreate(rName, roleName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSOpsworksUserProfileExists(
"aws_opsworks_user_profile.user", rName),
resource.TestCheckResourceAttr(
"aws_opsworks_user_profile.user", "ssh_public_key", "",
),
resource.TestCheckResourceAttr(
"aws_opsworks_user_profile.user", "ssh_username", rName,
),
resource.TestCheckResourceAttr(
"aws_opsworks_user_profile.user", "allow_self_management", "false",
),
),
},
},
})
}
示例3: TestAccAWSRDSClusterInstance_basic
func TestAccAWSRDSClusterInstance_basic(t *testing.T) {
var v rds.DBInstance
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSClusterInstanceConfig(acctest.RandInt()),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterInstanceExists("aws_rds_cluster_instance.cluster_instances", &v),
testAccCheckAWSDBClusterInstanceAttributes(&v),
resource.TestCheckResourceAttr("aws_rds_cluster_instance.cluster_instances", "auto_minor_version_upgrade", "true"),
),
},
{
Config: testAccAWSClusterInstanceConfigModified(acctest.RandInt()),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterInstanceExists("aws_rds_cluster_instance.cluster_instances", &v),
testAccCheckAWSDBClusterInstanceAttributes(&v),
resource.TestCheckResourceAttr("aws_rds_cluster_instance.cluster_instances", "auto_minor_version_upgrade", "false"),
),
},
},
})
}
示例4: TestAccAzureRMLoadBalancerProbe_update
func TestAccAzureRMLoadBalancerProbe_update(t *testing.T) {
var lb network.LoadBalancer
ri := acctest.RandInt()
probeName := fmt.Sprintf("probe-%d", ri)
probe2Name := fmt.Sprintf("probe-%d", acctest.RandInt())
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMLoadBalancerDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMLoadBalancerProbe_multipleProbes(ri, probeName, probe2Name),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb),
testCheckAzureRMLoadBalancerProbeExists(probeName, &lb),
testCheckAzureRMLoadBalancerProbeExists(probe2Name, &lb),
resource.TestCheckResourceAttr("azurerm_lb_probe.test2", "port", "80"),
),
},
{
Config: testAccAzureRMLoadBalancerProbe_multipleProbesUpdate(ri, probeName, probe2Name),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb),
testCheckAzureRMLoadBalancerProbeExists(probeName, &lb),
testCheckAzureRMLoadBalancerProbeExists(probe2Name, &lb),
resource.TestCheckResourceAttr("azurerm_lb_probe.test2", "port", "8080"),
),
},
},
})
}
示例5: TestAccAWSPolicyAttachment_basic
func TestAccAWSPolicyAttachment_basic(t *testing.T) {
var out iam.ListEntitiesForPolicyOutput
user1 := fmt.Sprintf("test-user-%d", acctest.RandInt())
user2 := fmt.Sprintf("test-user-%d", acctest.RandInt())
user3 := fmt.Sprintf("test-user-%d", acctest.RandInt())
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSPolicyAttachmentDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSPolicyAttachConfig(user1),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSPolicyAttachmentExists("aws_iam_policy_attachment.test-attach", 3, &out),
testAccCheckAWSPolicyAttachmentAttributes([]string{user1}, []string{"test-role"}, []string{"test-group"}, &out),
),
},
resource.TestStep{
Config: testAccAWSPolicyAttachConfigUpdate(user1, user2, user3),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSPolicyAttachmentExists("aws_iam_policy_attachment.test-attach", 6, &out),
testAccCheckAWSPolicyAttachmentAttributes([]string{user3, user3}, []string{"test-role2", "test-role3"}, []string{"test-group2", "test-group3"}, &out),
),
},
},
})
}
示例6: TestAccAzureRMLoadBalancerNatRule_update
func TestAccAzureRMLoadBalancerNatRule_update(t *testing.T) {
var lb network.LoadBalancer
ri := acctest.RandInt()
natRuleName := fmt.Sprintf("NatRule-%d", ri)
natRule2Name := fmt.Sprintf("NatRule-%d", acctest.RandInt())
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMLoadBalancerDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMLoadBalancerNatRule_multipleRules(ri, natRuleName, natRule2Name),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb),
testCheckAzureRMLoadBalancerNatRuleExists(natRuleName, &lb),
testCheckAzureRMLoadBalancerNatRuleExists(natRule2Name, &lb),
resource.TestCheckResourceAttr("azurerm_lb_nat_rule.test2", "frontend_port", "3390"),
resource.TestCheckResourceAttr("azurerm_lb_nat_rule.test2", "backend_port", "3390"),
),
},
{
Config: testAccAzureRMLoadBalancerNatRule_multipleRulesUpdate(ri, natRuleName, natRule2Name),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb),
testCheckAzureRMLoadBalancerNatRuleExists(natRuleName, &lb),
testCheckAzureRMLoadBalancerNatRuleExists(natRule2Name, &lb),
resource.TestCheckResourceAttr("azurerm_lb_nat_rule.test2", "frontend_port", "3391"),
resource.TestCheckResourceAttr("azurerm_lb_nat_rule.test2", "backend_port", "3391"),
),
},
},
})
}
示例7: testAccAWSSecurityGroupConfig_drift_complex
func testAccAWSSecurityGroupConfig_drift_complex() string {
return fmt.Sprintf(`
resource "aws_security_group" "otherweb" {
name = "tf_acc_%d"
description = "Used in the terraform acceptance tests"
}
resource "aws_security_group" "web" {
name = "tf_acc_%d"
description = "Used in the terraform acceptance tests"
ingress {
protocol = "tcp"
from_port = 80
to_port = 8000
cidr_blocks = ["10.0.0.0/8"]
}
ingress {
protocol = "tcp"
from_port = 80
to_port = 8000
cidr_blocks = ["206.0.0.0/8"]
}
ingress {
protocol = "tcp"
from_port = 22
to_port = 22
security_groups = ["${aws_security_group.otherweb.id}"]
}
egress {
protocol = "tcp"
from_port = 80
to_port = 8000
cidr_blocks = ["206.0.0.0/8"]
}
egress {
protocol = "tcp"
from_port = 80
to_port = 8000
cidr_blocks = ["10.0.0.0/8"]
}
egress {
protocol = "tcp"
from_port = 22
to_port = 22
security_groups = ["${aws_security_group.otherweb.id}"]
}
tags {
Name = "tf-acc-test"
}
}`, acctest.RandInt(), acctest.RandInt())
}
示例8: TestAccAWSS3BucketNotification_importBasic
func TestAccAWSS3BucketNotification_importBasic(t *testing.T) {
resourceName := "aws_s3_bucket_notification.notification"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSS3BucketNotificationDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSS3BucketConfigWithTopicNotification(acctest.RandInt()),
},
resource.TestStep{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"bucket"},
},
},
})
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSS3BucketNotificationDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSS3BucketConfigWithQueueNotification(acctest.RandInt()),
},
resource.TestStep{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"bucket"},
},
},
})
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSS3BucketNotificationDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSS3BucketConfigWithLambdaNotification(acctest.RandInt()),
},
resource.TestStep{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"bucket"},
},
},
})
}
示例9: TestAccAWSS3Bucket_acceleration
func TestAccAWSS3Bucket_acceleration(t *testing.T) {
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSS3BucketDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSS3BucketConfigWithAcceleration(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
resource.TestCheckResourceAttr(
"aws_s3_bucket.bucket", "acceleration_status", "Enabled"),
),
},
resource.TestStep{
Config: testAccAWSS3BucketConfigWithoutAcceleration(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
resource.TestCheckResourceAttr(
"aws_s3_bucket.bucket", "acceleration_status", "Suspended"),
),
},
},
})
}
示例10: TestAccAWSS3Bucket_Versioning
func TestAccAWSS3Bucket_Versioning(t *testing.T) {
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSS3BucketDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSS3BucketConfig(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
testAccCheckAWSS3BucketVersioning(
"aws_s3_bucket.bucket", ""),
),
},
resource.TestStep{
Config: testAccAWSS3BucketConfigWithVersioning(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
testAccCheckAWSS3BucketVersioning(
"aws_s3_bucket.bucket", s3.BucketVersioningStatusEnabled),
),
},
resource.TestStep{
Config: testAccAWSS3BucketConfigWithDisableVersioning(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
testAccCheckAWSS3BucketVersioning(
"aws_s3_bucket.bucket", s3.BucketVersioningStatusSuspended),
),
},
},
})
}
示例11: TestAccAWSS3Bucket_Cors
func TestAccAWSS3Bucket_Cors(t *testing.T) {
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSS3BucketDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSS3BucketConfigWithCORS(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
testAccCheckAWSS3BucketCors(
"aws_s3_bucket.bucket",
[]*s3.CORSRule{
&s3.CORSRule{
AllowedHeaders: []*string{aws.String("*")},
AllowedMethods: []*string{aws.String("PUT"), aws.String("POST")},
AllowedOrigins: []*string{aws.String("https://www.example.com")},
ExposeHeaders: []*string{aws.String("x-amz-server-side-encryption"), aws.String("ETag")},
MaxAgeSeconds: aws.Int64(3000),
},
},
),
),
},
},
})
}
示例12: TestAccAzureRMLoadBalancerRule_duplicateRules
func TestAccAzureRMLoadBalancerRule_duplicateRules(t *testing.T) {
var lb network.LoadBalancer
ri := acctest.RandInt()
lbRuleName := fmt.Sprintf("LbRule-%s", acctest.RandStringFromCharSet(8, acctest.CharSetAlpha))
subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID")
lbRuleID := fmt.Sprintf(
"/subscriptions/%s/resourceGroups/acctestrg-%d/providers/Microsoft.Network/loadBalancers/arm-test-loadbalancer-%d/loadBalancingRules/%s",
subscriptionID, ri, ri, lbRuleName)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMLoadBalancerDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMLoadBalancerRule_multipleRules(ri, lbRuleName, lbRuleName),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb),
testCheckAzureRMLoadBalancerRuleExists(lbRuleName, &lb),
resource.TestCheckResourceAttr("azurerm_lb_rule.test", "id", lbRuleID),
),
ExpectError: regexp.MustCompile(fmt.Sprintf("A LoadBalancer Rule with name %q already exists.", lbRuleName)),
},
},
})
}
示例13: TestAccAWSS3Bucket_basic
func TestAccAWSS3Bucket_basic(t *testing.T) {
rInt := acctest.RandInt()
arnRegexp := regexp.MustCompile(
"^arn:aws:s3:::")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
/*
IDRefreshName: "aws_s3_bucket.bucket",
IDRefreshIgnore: []string{"force_destroy"},
*/
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSS3BucketDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSS3BucketConfig(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
resource.TestCheckResourceAttr(
"aws_s3_bucket.bucket", "hosted_zone_id", HostedZoneIDForRegion("us-west-2")),
resource.TestCheckResourceAttr(
"aws_s3_bucket.bucket", "region", "us-west-2"),
resource.TestCheckResourceAttr(
"aws_s3_bucket.bucket", "website_endpoint", ""),
resource.TestMatchResourceAttr(
"aws_s3_bucket.bucket", "arn", arnRegexp),
),
},
},
})
}
示例14: TestAccAzureRMStorageAccount_blobEncryption
func TestAccAzureRMStorageAccount_blobEncryption(t *testing.T) {
ri := acctest.RandInt()
rs := acctest.RandString(4)
preConfig := fmt.Sprintf(testAccAzureRMStorageAccount_blobEncryption, ri, rs)
postConfig := fmt.Sprintf(testAccAzureRMStorageAccount_blobEncryptionDisabled, ri, rs)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMStorageAccountDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: preConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMStorageAccountExists("azurerm_storage_account.testsa"),
resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "enable_blob_encryption", "true"),
),
},
resource.TestStep{
Config: postConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMStorageAccountExists("azurerm_storage_account.testsa"),
resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "enable_blob_encryption", "false"),
),
},
},
})
}
示例15: TestAccAzureRMStorageAccount_basic
func TestAccAzureRMStorageAccount_basic(t *testing.T) {
ri := acctest.RandInt()
rs := acctest.RandString(4)
preConfig := fmt.Sprintf(testAccAzureRMStorageAccount_basic, ri, rs)
postConfig := fmt.Sprintf(testAccAzureRMStorageAccount_update, ri, rs)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMStorageAccountDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: preConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMStorageAccountExists("azurerm_storage_account.testsa"),
resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "account_type", "Standard_LRS"),
resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "tags.%", "1"),
resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "tags.environment", "production"),
),
},
resource.TestStep{
Config: postConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMStorageAccountExists("azurerm_storage_account.testsa"),
resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "account_type", "Standard_GRS"),
resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "tags.%", "1"),
resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "tags.environment", "staging"),
),
},
},
})
}