func TestAccAWSCloudFrontOriginAccessIdentity_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckCloudFrontOriginAccessIdentityDestroy, Steps: []resource.TestStep{ resource.TestStep{ Config: testAccAWSCloudFrontOriginAccessIdentityConfig, Check: resource.ComposeTestCheckFunc( testAccCheckCloudFrontOriginAccessIdentityExistence("aws_cloudfront_origin_access_identity.origin_access_identity"), resource.TestCheckResourceAttr("aws_cloudfront_origin_access_identity.origin_access_identity", "comment", "some comment"), resource.TestMatchResourceAttr("aws_cloudfront_origin_access_identity.origin_access_identity", "caller_reference", regexp.MustCompile("^20[0-9]{2}.*")), resource.TestMatchResourceAttr("aws_cloudfront_origin_access_identity.origin_access_identity", "s3_canonical_user_id", regexp.MustCompile("^[a-z0-9]+")), resource.TestMatchResourceAttr("aws_cloudfront_origin_access_identity.origin_access_identity", "cloudfront_access_identity_path", regexp.MustCompile("^origin-access-identity/cloudfront/[A-Z0-9]+")), ), }, }, }) }
func TestAccAWSAmiDataSource_instanceStore(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckAwsAmiDataSourceInstanceStoreConfig, Check: resource.ComposeTestCheckFunc( testAccCheckAwsAmiDataSourceID("data.aws_ami.instance_store_ami"), resource.TestCheckResourceAttr("data.aws_ami.instance_store_ami", "architecture", "x86_64"), resource.TestCheckResourceAttr("data.aws_ami.instance_store_ami", "block_device_mappings.#", "0"), resource.TestMatchResourceAttr("data.aws_ami.instance_store_ami", "creation_date", regexp.MustCompile("^20[0-9]{2}-")), resource.TestCheckResourceAttr("data.aws_ami.instance_store_ami", "hypervisor", "xen"), resource.TestMatchResourceAttr("data.aws_ami.instance_store_ami", "image_id", regexp.MustCompile("^ami-")), resource.TestMatchResourceAttr("data.aws_ami.instance_store_ami", "image_location", regexp.MustCompile("images/hvm-instance/ubuntu-trusty-14.04-amd64-server")), resource.TestCheckResourceAttr("data.aws_ami.instance_store_ami", "image_type", "machine"), resource.TestCheckResourceAttr("data.aws_ami.instance_store_ami", "most_recent", "true"), resource.TestMatchResourceAttr("data.aws_ami.instance_store_ami", "name", regexp.MustCompile("^ubuntu/images/hvm-instance/ubuntu-trusty-14.04-amd64-server")), resource.TestCheckResourceAttr("data.aws_ami.instance_store_ami", "owner_id", "099720109477"), resource.TestCheckResourceAttr("data.aws_ami.instance_store_ami", "public", "true"), resource.TestCheckResourceAttr("data.aws_ami.instance_store_ami", "product_codes.#", "0"), resource.TestCheckResourceAttr("data.aws_ami.instance_store_ami", "root_device_type", "instance-store"), resource.TestCheckResourceAttr("data.aws_ami.instance_store_ami", "sriov_net_support", "simple"), resource.TestCheckResourceAttr("data.aws_ami.instance_store_ami", "state", "available"), resource.TestCheckResourceAttr("data.aws_ami.instance_store_ami", "state_reason.code", "UNSET"), resource.TestCheckResourceAttr("data.aws_ami.instance_store_ami", "state_reason.message", "UNSET"), resource.TestCheckResourceAttr("data.aws_ami.instance_store_ami", "tags.#", "0"), resource.TestCheckResourceAttr("data.aws_ami.instance_store_ami", "virtualization_type", "hvm"), ), }, }, }) }
func TestAccAzureRMServiceBusNamespace_readDefaultKeys(t *testing.T) { ri := acctest.RandInt() config := fmt.Sprintf(testAccAzureRMServiceBusNamespace_basic, ri, ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testCheckAzureRMServiceBusNamespaceDestroy, Steps: []resource.TestStep{ resource.TestStep{ Config: config, Check: resource.ComposeTestCheckFunc( testCheckAzureRMServiceBusNamespaceExists("azurerm_servicebus_namespace.test"), resource.TestMatchResourceAttr( "azurerm_servicebus_namespace.test", "default_primary_connection_string", regexp.MustCompile("Endpoint=.+")), resource.TestMatchResourceAttr( "azurerm_servicebus_namespace.test", "default_secondary_connection_string", regexp.MustCompile("Endpoint=.+")), resource.TestMatchResourceAttr( "azurerm_servicebus_namespace.test", "default_primary_key", regexp.MustCompile(".+")), resource.TestMatchResourceAttr( "azurerm_servicebus_namespace.test", "default_secondary_key", regexp.MustCompile(".+")), ), }, }, }) }
func TestAccAWSBeanstalkEnv_outputs(t *testing.T) { var app elasticbeanstalk.EnvironmentDescription beanstalkAsgNameRegexp := regexp.MustCompile("awseb.+?AutoScalingGroup[^,]+") beanstalkElbNameRegexp := regexp.MustCompile("awseb.+?EBLoa[^,]+") beanstalkInstancesNameRegexp := regexp.MustCompile("i-([0-9a-fA-F]{8}|[0-9a-fA-F]{17})") beanstalkLcNameRegexp := regexp.MustCompile("awseb.+?AutoScalingLaunch[^,]+") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckBeanstalkEnvDestroy, Steps: []resource.TestStep{ resource.TestStep{ Config: testAccBeanstalkEnvConfig, Check: resource.ComposeTestCheckFunc( testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app), resource.TestMatchResourceAttr( "aws_elastic_beanstalk_environment.tfenvtest", "autoscaling_groups.0", beanstalkAsgNameRegexp), resource.TestMatchResourceAttr( "aws_elastic_beanstalk_environment.tfenvtest", "load_balancers.0", beanstalkElbNameRegexp), resource.TestMatchResourceAttr( "aws_elastic_beanstalk_environment.tfenvtest", "instances.0", beanstalkInstancesNameRegexp), resource.TestMatchResourceAttr( "aws_elastic_beanstalk_environment.tfenvtest", "launch_configurations.0", beanstalkLcNameRegexp), ), }, }, }) }
func TestAccAzureRMVirtualMachineExtension_basic(t *testing.T) { ri := acctest.RandInt() preConfig := fmt.Sprintf(testAccAzureRMVirtualMachineExtension_basic, ri, ri, ri, ri, ri, ri, ri, ri) postConfig := fmt.Sprintf(testAccAzureRMVirtualMachineExtension_basicUpdate, ri, ri, ri, ri, ri, ri, ri, ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testCheckAzureRMVirtualMachineExtensionDestroy, Steps: []resource.TestStep{ resource.TestStep{ Config: preConfig, Check: resource.ComposeTestCheckFunc( testCheckAzureRMVirtualMachineExtensionExists("azurerm_virtual_machine_extension.test"), resource.TestMatchResourceAttr("azurerm_virtual_machine_extension.test", "settings", regexp.MustCompile("hostname")), ), }, resource.TestStep{ Config: postConfig, Check: resource.ComposeTestCheckFunc( testCheckAzureRMVirtualMachineExtensionExists("azurerm_virtual_machine_extension.test"), resource.TestMatchResourceAttr("azurerm_virtual_machine_extension.test", "settings", regexp.MustCompile("whoami")), ), }, }, }) }
// Regression for https://github.com/hashicorp/terraform/issues/2427 func TestAccAWSEcsServiceWithRenamedCluster(t *testing.T) { originalRegexp := regexp.MustCompile( "^arn:aws:ecs:[^:]+:[0-9]+:cluster/terraformecstest3$") modifiedRegexp := regexp.MustCompile( "^arn:aws:ecs:[^:]+:[0-9]+:cluster/terraformecstest3modified$") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAWSEcsServiceDestroy, Steps: []resource.TestStep{ resource.TestStep{ Config: testAccAWSEcsServiceWithRenamedCluster, Check: resource.ComposeTestCheckFunc( testAccCheckAWSEcsServiceExists("aws_ecs_service.ghost"), resource.TestMatchResourceAttr( "aws_ecs_service.ghost", "cluster", originalRegexp), ), }, resource.TestStep{ Config: testAccAWSEcsServiceWithRenamedClusterModified, Check: resource.ComposeTestCheckFunc( testAccCheckAWSEcsServiceExists("aws_ecs_service.ghost"), resource.TestMatchResourceAttr( "aws_ecs_service.ghost", "cluster", modifiedRegexp), ), }, }, }) }
func TestAccAWSCloudWatchEventTarget_basic(t *testing.T) { var target events.Target resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAWSCloudWatchEventTargetDestroy, Steps: []resource.TestStep{ resource.TestStep{ Config: testAccAWSCloudWatchEventTargetConfig, Check: resource.ComposeTestCheckFunc( testAccCheckCloudWatchEventTargetExists("aws_cloudwatch_event_target.moobar", &target), resource.TestCheckResourceAttr("aws_cloudwatch_event_target.moobar", "rule", "tf-acc-cw-event-rule-basic"), resource.TestCheckResourceAttr("aws_cloudwatch_event_target.moobar", "target_id", "tf-acc-cw-target-basic"), resource.TestMatchResourceAttr("aws_cloudwatch_event_target.moobar", "arn", regexp.MustCompile(":tf-acc-moon$")), ), }, resource.TestStep{ Config: testAccAWSCloudWatchEventTargetConfigModified, Check: resource.ComposeTestCheckFunc( testAccCheckCloudWatchEventTargetExists("aws_cloudwatch_event_target.moobar", &target), resource.TestCheckResourceAttr("aws_cloudwatch_event_target.moobar", "rule", "tf-acc-cw-event-rule-basic"), resource.TestCheckResourceAttr("aws_cloudwatch_event_target.moobar", "target_id", "tf-acc-cw-target-modified"), resource.TestMatchResourceAttr("aws_cloudwatch_event_target.moobar", "arn", regexp.MustCompile(":tf-acc-sun$")), ), }, }, }) }
func TestAccAWSLambdaFunction_versioned(t *testing.T) { var conf lambda.GetFunctionOutput rName := fmt.Sprintf("tf_test_%s", acctest.RandString(5)) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckLambdaFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccAWSLambdaConfigVersioned(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_test", rName, &conf), testAccCheckAwsLambdaFunctionName(&conf, rName), testAccCheckAwsLambdaFunctionArnHasSuffix(&conf, ":"+rName), resource.TestMatchResourceAttr("aws_lambda_function.lambda_function_test", "version", regexp.MustCompile("^[0-9]+$")), resource.TestMatchResourceAttr("aws_lambda_function.lambda_function_test", "qualified_arn", regexp.MustCompile(":"+rName+":[0-9]+$")), ), }, }, }) }
func TestAccAWSAPIGatewayAuthorizer_basic(t *testing.T) { var conf apigateway.Authorizer expectedAuthUri := regexp.MustCompile("arn:aws:apigateway:region:lambda:path/2015-03-31/functions/" + "arn:aws:lambda:[a-z0-9-]+:[0-9]{12}:function:tf_acc_api_gateway_authorizer/invocations") expectedCreds := regexp.MustCompile("arn:aws:iam::[0-9]{12}:role/tf_acc_api_gateway_auth_invocation_role") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAWSAPIGatewayAuthorizerDestroy, Steps: []resource.TestStep{ resource.TestStep{ Config: testAccAWSAPIGatewayAuthorizerConfig, Check: resource.ComposeTestCheckFunc( testAccCheckAWSAPIGatewayAuthorizerExists("aws_api_gateway_authorizer.test", &conf), testAccCheckAWSAPIGatewayAuthorizerAuthorizerUri(&conf, expectedAuthUri), resource.TestMatchResourceAttr("aws_api_gateway_authorizer.test", "authorizer_uri", expectedAuthUri), testAccCheckAWSAPIGatewayAuthorizerIdentitySource(&conf, "method.request.header.Authorization"), resource.TestCheckResourceAttr("aws_api_gateway_authorizer.test", "identity_source", "method.request.header.Authorization"), testAccCheckAWSAPIGatewayAuthorizerName(&conf, "tf-acc-test-authorizer"), resource.TestCheckResourceAttr("aws_api_gateway_authorizer.test", "name", "tf-acc-test-authorizer"), testAccCheckAWSAPIGatewayAuthorizerType(&conf, "TOKEN"), resource.TestCheckResourceAttr("aws_api_gateway_authorizer.test", "type", "TOKEN"), testAccCheckAWSAPIGatewayAuthorizerAuthorizerCredentials(&conf, expectedCreds), resource.TestMatchResourceAttr("aws_api_gateway_authorizer.test", "authorizer_credentials", expectedCreds), testAccCheckAWSAPIGatewayAuthorizerAuthorizerResultTtlInSeconds(&conf, nil), resource.TestCheckResourceAttr("aws_api_gateway_authorizer.test", "authorizer_result_ttl_in_seconds", "0"), testAccCheckAWSAPIGatewayAuthorizerIdentityValidationExpression(&conf, nil), resource.TestCheckResourceAttr("aws_api_gateway_authorizer.test", "identity_validation_expression", ""), ), }, resource.TestStep{ Config: testAccAWSAPIGatewayAuthorizerUpdatedConfig, Check: resource.ComposeTestCheckFunc( testAccCheckAWSAPIGatewayAuthorizerExists("aws_api_gateway_authorizer.test", &conf), testAccCheckAWSAPIGatewayAuthorizerAuthorizerUri(&conf, expectedAuthUri), resource.TestMatchResourceAttr("aws_api_gateway_authorizer.test", "authorizer_uri", expectedAuthUri), testAccCheckAWSAPIGatewayAuthorizerIdentitySource(&conf, "method.request.header.Authorization"), resource.TestCheckResourceAttr("aws_api_gateway_authorizer.test", "identity_source", "method.request.header.Authorization"), testAccCheckAWSAPIGatewayAuthorizerName(&conf, "tf-acc-test-authorizer_modified"), resource.TestCheckResourceAttr("aws_api_gateway_authorizer.test", "name", "tf-acc-test-authorizer_modified"), testAccCheckAWSAPIGatewayAuthorizerType(&conf, "TOKEN"), resource.TestCheckResourceAttr("aws_api_gateway_authorizer.test", "type", "TOKEN"), testAccCheckAWSAPIGatewayAuthorizerAuthorizerCredentials(&conf, expectedCreds), resource.TestMatchResourceAttr("aws_api_gateway_authorizer.test", "authorizer_credentials", expectedCreds), testAccCheckAWSAPIGatewayAuthorizerAuthorizerResultTtlInSeconds(&conf, aws.Int64(360)), resource.TestCheckResourceAttr("aws_api_gateway_authorizer.test", "authorizer_result_ttl_in_seconds", "360"), testAccCheckAWSAPIGatewayAuthorizerIdentityValidationExpression(&conf, aws.String(".*")), resource.TestCheckResourceAttr("aws_api_gateway_authorizer.test", "identity_validation_expression", ".*"), ), }, }, }) }
func TestAccArchiveFile_Basic(t *testing.T) { var fileSize string r.Test(t, r.TestCase{ Providers: testProviders, Steps: []r.TestStep{ r.TestStep{ Config: testAccArchiveFileContentConfig, Check: r.ComposeTestCheckFunc( testAccArchiveFileExists("zip_file_acc_test.zip", &fileSize), r.TestCheckResourceAttrPtr("data.archive_file.foo", "output_size", &fileSize), // We just check the hashes for syntax rather than exact // content since we don't want to break if the archive // library starts generating different bytes that are // functionally equivalent. r.TestMatchResourceAttr( "data.archive_file.foo", "output_base64sha256", regexp.MustCompile(`^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$`), ), r.TestMatchResourceAttr( "data.archive_file.foo", "output_md5", regexp.MustCompile(`^[0-9a-f]{32}$`), ), r.TestMatchResourceAttr( "data.archive_file.foo", "output_sha", regexp.MustCompile(`^[0-9a-f]{40}$`), ), ), }, r.TestStep{ Config: testAccArchiveFileFileConfig, Check: r.ComposeTestCheckFunc( testAccArchiveFileExists("zip_file_acc_test.zip", &fileSize), r.TestCheckResourceAttrPtr("data.archive_file.foo", "output_size", &fileSize), ), }, r.TestStep{ Config: testAccArchiveFileDirConfig, Check: r.ComposeTestCheckFunc( testAccArchiveFileExists("zip_file_acc_test.zip", &fileSize), r.TestCheckResourceAttrPtr("data.archive_file.foo", "output_size", &fileSize), ), }, r.TestStep{ Config: testAccArchiveFileOutputPath, Check: r.ComposeTestCheckFunc( testAccArchiveFileExists(fmt.Sprintf("%s/test.zip", tmpDir), &fileSize), ), }, }, }) }
func TestAccAWSEFSMountTarget_basic(t *testing.T) { var mount efs.MountTargetDescription ct := fmt.Sprintf("createtoken-%d", acctest.RandInt()) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckEfsMountTargetDestroy, Steps: []resource.TestStep{ resource.TestStep{ Config: testAccAWSEFSMountTargetConfig(ct), Check: resource.ComposeTestCheckFunc( testAccCheckEfsMountTarget( "aws_efs_mount_target.alpha", &mount, ), resource.TestMatchResourceAttr( "aws_efs_mount_target.alpha", "dns_name", regexp.MustCompile("^[^.]+.efs.us-west-2.amazonaws.com$"), ), ), }, resource.TestStep{ Config: testAccAWSEFSMountTargetConfigModified(ct), Check: resource.ComposeTestCheckFunc( testAccCheckEfsMountTarget( "aws_efs_mount_target.alpha", &mount, ), resource.TestMatchResourceAttr( "aws_efs_mount_target.alpha", "dns_name", regexp.MustCompile("^[^.]+.efs.us-west-2.amazonaws.com$"), ), testAccCheckEfsMountTarget( "aws_efs_mount_target.beta", &mount, ), resource.TestMatchResourceAttr( "aws_efs_mount_target.beta", "dns_name", regexp.MustCompile("^[^.]+.efs.us-west-2.amazonaws.com$"), ), ), }, }, }) }
func TestAccDataSourceAWSS3BucketObject_allParams(t *testing.T) { rInt := acctest.RandInt() resourceOnlyConf, conf := testAccAWSDataSourceS3ObjectConfig_allParams(rInt) var rObj s3.GetObjectOutput var dsObj s3.GetObjectOutput resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, PreventPostDestroyRefresh: true, Steps: []resource.TestStep{ resource.TestStep{ Config: resourceOnlyConf, Check: resource.ComposeTestCheckFunc( testAccCheckAWSS3BucketObjectExists("aws_s3_bucket_object.object", &rObj), ), }, resource.TestStep{ Config: conf, Check: resource.ComposeTestCheckFunc( testAccCheckAwsS3ObjectDataSourceExists("data.aws_s3_bucket_object.obj", &dsObj), resource.TestCheckResourceAttr("data.aws_s3_bucket_object.obj", "content_length", "21"), resource.TestCheckResourceAttr("data.aws_s3_bucket_object.obj", "content_type", "application/unknown"), resource.TestCheckResourceAttr("data.aws_s3_bucket_object.obj", "etag", "723f7a6ac0c57b445790914668f98640"), resource.TestMatchResourceAttr("data.aws_s3_bucket_object.obj", "last_modified", regexp.MustCompile("^[a-zA-Z]{3}, [0-9]+ [a-zA-Z]+ [0-9]{4} [0-9:]+ [A-Z]+$")), resource.TestMatchResourceAttr("data.aws_s3_bucket_object.obj", "version_id", regexp.MustCompile("^.{32}$")), resource.TestCheckResourceAttr("data.aws_s3_bucket_object.obj", "body", ""), resource.TestCheckResourceAttr("data.aws_s3_bucket_object.obj", "cache_control", "no-cache"), resource.TestCheckResourceAttr("data.aws_s3_bucket_object.obj", "content_disposition", "attachment"), resource.TestCheckResourceAttr("data.aws_s3_bucket_object.obj", "content_encoding", "gzip"), resource.TestCheckResourceAttr("data.aws_s3_bucket_object.obj", "content_language", "en-GB"), // Encryption is off resource.TestCheckResourceAttr("data.aws_s3_bucket_object.obj", "server_side_encryption", ""), resource.TestCheckResourceAttr("data.aws_s3_bucket_object.obj", "sse_kms_key_id", ""), // Supported, but difficult to reproduce in short testing time resource.TestCheckResourceAttr("data.aws_s3_bucket_object.obj", "storage_class", ""), resource.TestCheckResourceAttr("data.aws_s3_bucket_object.obj", "expiration", ""), // Currently unsupported in aws_s3_bucket_object resource resource.TestCheckResourceAttr("data.aws_s3_bucket_object.obj", "expires", ""), resource.TestCheckResourceAttr("data.aws_s3_bucket_object.obj", "website_redirect_location", ""), resource.TestCheckResourceAttr("data.aws_s3_bucket_object.obj", "metadata.#", "0"), ), }, }, }) }
func TestAccAWSS3Bucket_basic(t *testing.T) { arnRegexp := regexp.MustCompile( "^arn:aws:s3:::") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAWSS3BucketDestroy, Steps: []resource.TestStep{ resource.TestStep{ Config: testAccAWSS3BucketConfig, 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), ), }, }, }) }
func TestAccLBV2LoadBalancer_basic(t *testing.T) { var lb loadbalancers.LoadBalancer resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckLBV2LoadBalancerDestroy, Steps: []resource.TestStep{ resource.TestStep{ Config: testAccLBV2LoadBalancerConfig_basic, Check: resource.ComposeTestCheckFunc( testAccCheckLBV2LoadBalancerExists("openstack_lb_loadbalancer_v2.loadbalancer_1", &lb), ), }, resource.TestStep{ Config: testAccLBV2LoadBalancerConfig_update, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "openstack_lb_loadbalancer_v2.loadbalancer_1", "name", "loadbalancer_1_updated"), resource.TestMatchResourceAttr( "openstack_lb_loadbalancer_v2.loadbalancer_1", "vip_port_id", regexp.MustCompile("^[a-f0-9-]+")), ), }, }, }) }
func TestAccVcdNetwork_Basic(t *testing.T) { var network govcd.OrgVDCNetwork generatedHrefRegexp := regexp.MustCompile("^https://") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckVcdNetworkDestroy, Steps: []resource.TestStep{ resource.TestStep{ Config: fmt.Sprintf(testAccCheckVcdNetwork_basic, os.Getenv("VCD_EDGE_GATWEWAY")), Check: resource.ComposeTestCheckFunc( testAccCheckVcdNetworkExists("vcd_network.foonet", &network), testAccCheckVcdNetworkAttributes(&network), resource.TestCheckResourceAttr( "vcd_network.foonet", "name", "foonet"), resource.TestCheckResourceAttr( "vcd_network.foonet", "static_ip_pool.#", "1"), resource.TestCheckResourceAttr( "vcd_network.foonet", "gateway", "10.10.102.1"), resource.TestMatchResourceAttr( "vcd_network.foonet", "href", generatedHrefRegexp), ), }, }, }) }
// returns TestCheckFunc's that are used in many of our tests // mem defaults to 1024 // cpu defaults to 2 // disks defatuls to 1 // vmResource defaults to "terraform-test" // vmName defaults to "vsphere_virtual_machine.foo func (test TestFuncData) testCheckFuncBasic() ( resource.TestCheckFunc, resource.TestCheckFunc, resource.TestCheckFunc, resource.TestCheckFunc, resource.TestCheckFunc, resource.TestCheckFunc, resource.TestCheckFunc, resource.TestCheckFunc) { // log.Printf("[DEBUG] data= %v", test) mem := test.mem if mem == "" { mem = "1024" } cpu := test.numCPU if cpu == "" { cpu = "2" } disks := test.numDisks if disks == "" { disks = "1" } res := test.vmResource if res == "" { res = "terraform-test" } vmName := test.vmName if vmName == "" { vmName = "vsphere_virtual_machine.foo" } return testAccCheckVSphereVirtualMachineExists(vmName, &test.vm), resource.TestCheckResourceAttr(vmName, "name", res), resource.TestCheckResourceAttr(vmName, "vcpu", cpu), resource.TestMatchResourceAttr(vmName, "uuid", regexp.MustCompile("[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}")), resource.TestCheckResourceAttr(vmName, "memory", mem), resource.TestCheckResourceAttr(vmName, "disk.#", disks), resource.TestCheckResourceAttr(vmName, "network_interface.#", "1"), resource.TestCheckResourceAttr(vmName, "network_interface.0.label", test.label) }
func TestAccAWSLambdaFunction_encryptedEnvVariables(t *testing.T) { var conf lambda.GetFunctionOutput rName := fmt.Sprintf("tf_test_%s", acctest.RandString(5)) keyRegex := regexp.MustCompile("^arn:aws:kms:") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckLambdaFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccAWSLambdaConfigEncryptedEnvVariables(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_test", rName, &conf), testAccCheckAwsLambdaFunctionName(&conf, rName), testAccCheckAwsLambdaFunctionArnHasSuffix(&conf, ":"+rName), resource.TestCheckResourceAttr("aws_lambda_function.lambda_function_test", "environment.0.variables.foo", "bar"), resource.TestMatchResourceAttr("aws_lambda_function.lambda_function_test", "kms_key_arn", keyRegex), ), }, { Config: testAccAWSLambdaConfigEncryptedEnvVariablesModified(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_test", rName, &conf), testAccCheckAwsLambdaFunctionName(&conf, rName), testAccCheckAwsLambdaFunctionArnHasSuffix(&conf, ":"+rName), resource.TestCheckResourceAttr("aws_lambda_function.lambda_function_test", "environment.0.variables.foo", "bar"), resource.TestCheckResourceAttr("aws_lambda_function.lambda_function_test", "kms_key_arn", ""), ), }, }, }) }
func TestAccAWSRedshiftCluster_kmsKey(t *testing.T) { var v redshift.Cluster ri := rand.New(rand.NewSource(time.Now().UnixNano())).Int() config := fmt.Sprintf(testAccAWSRedshiftClusterConfig_kmsKey, ri, ri) keyRegex := regexp.MustCompile("^arn:aws:([a-zA-Z0-9\\-])+:([a-z]{2}-[a-z]+-\\d{1})?:(\\d{12})?:(.*)$") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAWSRedshiftClusterDestroy, Steps: []resource.TestStep{ { Config: config, Check: resource.ComposeTestCheckFunc( testAccCheckAWSRedshiftClusterExists("aws_redshift_cluster.default", &v), resource.TestCheckResourceAttr( "aws_redshift_cluster.default", "cluster_type", "single-node"), resource.TestCheckResourceAttr( "aws_redshift_cluster.default", "publicly_accessible", "true"), resource.TestMatchResourceAttr("aws_redshift_cluster.default", "kms_key_id", keyRegex), ), }, }, }) }
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), ), }, }, }) }
func TestAccAWSLambdaFunction_VPC(t *testing.T) { var conf lambda.GetFunctionOutput rName := fmt.Sprintf("tf_test_%s", acctest.RandString(5)) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckLambdaFunctionDestroy, Steps: []resource.TestStep{ resource.TestStep{ Config: testAccAWSLambdaConfigWithVPC(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_test", rName, &conf), testAccCheckAwsLambdaFunctionName(&conf, rName), testAccCheckAwsLambdaFunctionArnHasSuffix(&conf, ":"+rName), testAccCheckAWSLambdaFunctionVersion(&conf, "$LATEST"), resource.TestCheckResourceAttr("aws_lambda_function.lambda_function_test", "vpc_config.#", "1"), resource.TestCheckResourceAttr("aws_lambda_function.lambda_function_test", "vpc_config.0.subnet_ids.#", "1"), resource.TestCheckResourceAttr("aws_lambda_function.lambda_function_test", "vpc_config.0.security_group_ids.#", "1"), resource.TestMatchResourceAttr("aws_lambda_function.lambda_function_test", "vpc_config.0.vpc_id", regexp.MustCompile("^vpc-")), ), }, }, }) }
func TestAccDockerImage_destroy(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: func(s *terraform.State) error { for _, rs := range s.RootModule().Resources { if rs.Type != "docker_image" { continue } client := testAccProvider.Meta().(*dc.Client) _, err := client.InspectImage(rs.Primary.Attributes["latest"]) if err != nil { return err } } return nil }, Steps: []resource.TestStep{ resource.TestStep{ Config: testAccDockerImageKeepLocallyConfig, Check: resource.ComposeTestCheckFunc( resource.TestMatchResourceAttr("docker_image.foobarzoo", "latest", contentDigestRegexp), ), }, }, }) }
func TestAccDataSourceAWSS3BucketObject_basic(t *testing.T) { rInt := acctest.RandInt() resourceOnlyConf, conf := testAccAWSDataSourceS3ObjectConfig_basic(rInt) var rObj s3.GetObjectOutput var dsObj s3.GetObjectOutput resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, PreventPostDestroyRefresh: true, Steps: []resource.TestStep{ resource.TestStep{ Config: resourceOnlyConf, Check: resource.ComposeTestCheckFunc( testAccCheckAWSS3BucketObjectExists("aws_s3_bucket_object.object", &rObj), ), }, resource.TestStep{ Config: conf, Check: resource.ComposeTestCheckFunc( testAccCheckAwsS3ObjectDataSourceExists("data.aws_s3_bucket_object.obj", &dsObj), resource.TestCheckResourceAttr("data.aws_s3_bucket_object.obj", "content_length", "11"), resource.TestCheckResourceAttr("data.aws_s3_bucket_object.obj", "content_type", "binary/octet-stream"), resource.TestCheckResourceAttr("data.aws_s3_bucket_object.obj", "etag", "b10a8db164e0754105b7a99be72e3fe5"), resource.TestMatchResourceAttr("data.aws_s3_bucket_object.obj", "last_modified", regexp.MustCompile("^[a-zA-Z]{3}, [0-9]+ [a-zA-Z]+ [0-9]{4} [0-9:]+ [A-Z]+$")), resource.TestCheckResourceAttr("data.aws_s3_bucket_object.obj", "body", ""), ), }, }, }) }
func TestAccDataSourceAWSS3BucketObject_readableBody(t *testing.T) { rInt := acctest.RandInt() resourceOnlyConf, conf := testAccAWSDataSourceS3ObjectConfig_readableBody(rInt) var rObj s3.GetObjectOutput var dsObj s3.GetObjectOutput resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, PreventPostDestroyRefresh: true, Steps: []resource.TestStep{ resource.TestStep{ Config: resourceOnlyConf, Check: resource.ComposeTestCheckFunc( testAccCheckAWSS3BucketObjectExists("aws_s3_bucket_object.object", &rObj), ), }, resource.TestStep{ Config: conf, Check: resource.ComposeTestCheckFunc( testAccCheckAwsS3ObjectDataSourceExists("data.aws_s3_bucket_object.obj", &dsObj), resource.TestCheckResourceAttr("data.aws_s3_bucket_object.obj", "content_length", "3"), resource.TestCheckResourceAttr("data.aws_s3_bucket_object.obj", "content_type", "text/plain"), resource.TestCheckResourceAttr("data.aws_s3_bucket_object.obj", "etag", "a6105c0a611b41b08f1209506350279e"), resource.TestMatchResourceAttr("data.aws_s3_bucket_object.obj", "last_modified", regexp.MustCompile("^[a-zA-Z]{3}, [0-9]+ [a-zA-Z]+ [0-9]{4} [0-9:]+ [A-Z]+$")), resource.TestCheckResourceAttr("data.aws_s3_bucket_object.obj", "body", "yes"), ), }, }, }) }
func TestAccAWSLambdaPermission_withS3(t *testing.T) { rInt := acctest.RandInt() var statement LambdaPolicyStatement endsWithFuncName := regexp.MustCompile(":function:lambda_function_name_perm_s3$") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAWSLambdaPermissionDestroy, Steps: []resource.TestStep{ resource.TestStep{ Config: fmt.Sprintf(testAccAWSLambdaPermissionConfig_withS3_tpl, rInt), Check: resource.ComposeTestCheckFunc( testAccCheckLambdaPermissionExists("aws_lambda_permission.with_s3", &statement), resource.TestCheckResourceAttr("aws_lambda_permission.with_s3", "action", "lambda:InvokeFunction"), resource.TestCheckResourceAttr("aws_lambda_permission.with_s3", "principal", "s3.amazonaws.com"), resource.TestCheckResourceAttr("aws_lambda_permission.with_s3", "statement_id", "AllowExecutionFromS3"), resource.TestMatchResourceAttr("aws_lambda_permission.with_s3", "function_name", endsWithFuncName), resource.TestCheckResourceAttr("aws_lambda_permission.with_s3", "source_arn", fmt.Sprintf("arn:aws:s3:::tf-acc-towards-lambda-%d", rInt)), ), }, }, }) }
func TestAccAWSCloudFormationStack_dataSource_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ resource.TestStep{ Config: testAccCheckAwsCloudFormationStackDataSourceConfig_basic, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("data.aws_cloudformation_stack.network", "outputs.%", "1"), resource.TestMatchResourceAttr("data.aws_cloudformation_stack.network", "outputs.VPCId", regexp.MustCompile("^vpc-[a-z0-9]{8}$")), resource.TestCheckResourceAttr("data.aws_cloudformation_stack.network", "capabilities.#", "0"), resource.TestCheckResourceAttr("data.aws_cloudformation_stack.network", "disable_rollback", "false"), resource.TestCheckResourceAttr("data.aws_cloudformation_stack.network", "notification_arns.#", "0"), resource.TestCheckResourceAttr("data.aws_cloudformation_stack.network", "parameters.%", "1"), resource.TestCheckResourceAttr("data.aws_cloudformation_stack.network", "parameters.CIDR", "10.10.10.0/24"), resource.TestCheckResourceAttr("data.aws_cloudformation_stack.network", "timeout_in_minutes", "6"), resource.TestCheckResourceAttr("data.aws_cloudformation_stack.network", "tags.%", "2"), resource.TestCheckResourceAttr("data.aws_cloudformation_stack.network", "tags.Name", "Form the Cloud"), resource.TestCheckResourceAttr("data.aws_cloudformation_stack.network", "tags.Second", "meh"), ), }, }, }) }
func TestAccAWSLambdaEventSourceMapping_basic(t *testing.T) { var conf lambda.EventSourceMappingConfiguration resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, Steps: []resource.TestStep{ resource.TestStep{ Config: testAccAWSLambdaEventSourceMappingConfig, Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaEventSourceMappingExists("aws_lambda_event_source_mapping.lambda_event_source_mapping_test", &conf), testAccCheckAWSLambdaEventSourceMappingAttributes(&conf), ), }, resource.TestStep{ Config: testAccAWSLambdaEventSourceMappingConfigUpdate, Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaEventSourceMappingExists("aws_lambda_event_source_mapping.lambda_event_source_mapping_test", &conf), resource.TestCheckResourceAttr("aws_lambda_event_source_mapping.lambda_event_source_mapping_test", "batch_size", strconv.Itoa(200)), resource.TestCheckResourceAttr("aws_lambda_event_source_mapping.lambda_event_source_mapping_test", "enabled", strconv.FormatBool(false)), resource.TestMatchResourceAttr( "aws_lambda_event_source_mapping.lambda_event_source_mapping_test", "function_arn", regexp.MustCompile("example_lambda_name_update$"), ), ), }, }, }) }
func TestAccAWSEFSMountTarget_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckEfsMountTargetDestroy, Steps: []resource.TestStep{ resource.TestStep{ Config: testAccAWSEFSMountTargetConfig, Check: resource.ComposeTestCheckFunc( testAccCheckEfsMountTarget( "aws_efs_mount_target.alpha", ), resource.TestMatchResourceAttr( "aws_efs_mount_target.alpha", "dns_name", regexp.MustCompile("^us-west-2a.[^.]+.efs.us-west-2.amazonaws.com$"), ), ), }, resource.TestStep{ Config: testAccAWSEFSMountTargetConfigModified, Check: resource.ComposeTestCheckFunc( testAccCheckEfsMountTarget( "aws_efs_mount_target.alpha", ), resource.TestMatchResourceAttr( "aws_efs_mount_target.alpha", "dns_name", regexp.MustCompile("^us-west-2a.[^.]+.efs.us-west-2.amazonaws.com$"), ), testAccCheckEfsMountTarget( "aws_efs_mount_target.beta", ), resource.TestMatchResourceAttr( "aws_efs_mount_target.beta", "dns_name", regexp.MustCompile("^us-west-2b.[^.]+.efs.us-west-2.amazonaws.com$"), ), ), }, }, }) }
func TestAccAWSAmiDataSource_natInstance(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckAwsAmiDataSourceConfig, Check: resource.ComposeTestCheckFunc( testAccCheckAwsAmiDataSourceID("data.aws_ami.nat_ami"), // Check attributes. Some attributes are tough to test - any not contained here should not be considered // stable and should not be used in interpolation. Exception to block_device_mappings which should both // show up consistently and break if certain references are not available. However modification of the // snapshot ID which is bound to happen on the NAT AMIs will cause testing to break consistently, so // deep inspection is not included, simply the count is checked. // Tags and product codes may need more testing, but I'm having a hard time finding images with // these attributes set. resource.TestCheckResourceAttr("data.aws_ami.nat_ami", "architecture", "x86_64"), resource.TestCheckResourceAttr("data.aws_ami.nat_ami", "block_device_mappings.#", "1"), resource.TestMatchResourceAttr("data.aws_ami.nat_ami", "creation_date", regexp.MustCompile("^20[0-9]{2}-")), resource.TestMatchResourceAttr("data.aws_ami.nat_ami", "description", regexp.MustCompile("^Amazon Linux AMI")), resource.TestCheckResourceAttr("data.aws_ami.nat_ami", "hypervisor", "xen"), resource.TestMatchResourceAttr("data.aws_ami.nat_ami", "image_id", regexp.MustCompile("^ami-")), resource.TestMatchResourceAttr("data.aws_ami.nat_ami", "image_location", regexp.MustCompile("^amazon/")), resource.TestCheckResourceAttr("data.aws_ami.nat_ami", "image_owner_alias", "amazon"), resource.TestCheckResourceAttr("data.aws_ami.nat_ami", "image_type", "machine"), resource.TestCheckResourceAttr("data.aws_ami.nat_ami", "most_recent", "true"), resource.TestMatchResourceAttr("data.aws_ami.nat_ami", "name", regexp.MustCompile("^amzn-ami-vpc-nat")), resource.TestCheckResourceAttr("data.aws_ami.nat_ami", "owner_id", "137112412989"), resource.TestCheckResourceAttr("data.aws_ami.nat_ami", "public", "true"), resource.TestCheckResourceAttr("data.aws_ami.nat_ami", "product_codes.#", "0"), resource.TestCheckResourceAttr("data.aws_ami.nat_ami", "root_device_name", "/dev/xvda"), resource.TestCheckResourceAttr("data.aws_ami.nat_ami", "root_device_type", "ebs"), resource.TestCheckResourceAttr("data.aws_ami.nat_ami", "sriov_net_support", "simple"), resource.TestCheckResourceAttr("data.aws_ami.nat_ami", "state", "available"), resource.TestCheckResourceAttr("data.aws_ami.nat_ami", "state_reason.code", "UNSET"), resource.TestCheckResourceAttr("data.aws_ami.nat_ami", "state_reason.message", "UNSET"), resource.TestCheckResourceAttr("data.aws_ami.nat_ami", "tags.#", "0"), resource.TestCheckResourceAttr("data.aws_ami.nat_ami", "virtualization_type", "hvm"), ), }, }, }) }
func TestAccDockerImage_private(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ resource.TestStep{ Config: testAddDockerPrivateImageConfig, Check: resource.ComposeTestCheckFunc( resource.TestMatchResourceAttr("docker_image.foobar", "latest", contentDigestRegexp), ), }, }, }) }
func TestAccDockerImage_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ resource.TestStep{ Config: testAccDockerImageConfig, Check: resource.ComposeTestCheckFunc( resource.TestMatchResourceAttr("docker_image.foo", "latest", regexp.MustCompile(`\A[a-f0-9]{64}\z`)), ), }, }, }) }