From 12b191c23ae104f799ee17a09a3b5aefe61001e9 Mon Sep 17 00:00:00 2001 From: Graham Davison Date: Tue, 8 Sep 2020 12:59:51 -0700 Subject: [PATCH 1/8] Updates tflint rules to use "--only" flag --- .github/workflows/acctest-terraform-lint.yml | 9 +- scripts/validate-terraform.sh | 99 ++------------------ 2 files changed, 14 insertions(+), 94 deletions(-) diff --git a/.github/workflows/acctest-terraform-lint.yml b/.github/workflows/acctest-terraform-lint.yml index 8e29e707fe2b..15b73c3a3928 100644 --- a/.github/workflows/acctest-terraform-lint.yml +++ b/.github/workflows/acctest-terraform-lint.yml @@ -12,7 +12,7 @@ on: env: GO_VERSION: "1.14" GO111MODULE: on - TFLINT_VERSION: "v0.19.0" + TFLINT_VERSION: "v0.20.0" # Not yet available jobs: terrafmt: @@ -64,7 +64,12 @@ jobs: git clone --branch tracking-main --single-branch https://github.com/gdavison/terrafmt terrafmt cd terrafmt go install - - run: curl -s https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh | sh + # - run: curl -s https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh | sh + - run: | + git clone --no-checkout https://github.com/terraform-linters/tflint tflint + cd tflint + git checkout --recurse-submodules 5a002e926848899d4bfbb006f95c39285a5e9afa + go install - run: | find ./aws -type f \( \ -name 'resource_aws_a*_test.go' \ diff --git a/scripts/validate-terraform.sh b/scripts/validate-terraform.sh index d4299367a094..8418b5a21bea 100755 --- a/scripts/validate-terraform.sh +++ b/scripts/validate-terraform.sh @@ -16,100 +16,15 @@ exit_code=0 # The *_invalid_* rules disabled here prevent evaluation of expressions. rules=( # Syntax checks - "--enable-rule=terraform_deprecated_interpolation" - "--enable-rule=terraform_deprecated_index" - "--enable-rule=terraform_comment_syntax" + "--only=terraform_deprecated_interpolation" + "--only=terraform_deprecated_index" + "--only=terraform_comment_syntax" # Ensure modern instance types - "--enable-rule=aws_instance_previous_type" - "--enable-rule=aws_db_instance_previous_type" - "--enable-rule=aws_elasticache_cluster_previous_type" + "--only=aws_instance_previous_type" + "--only=aws_db_instance_previous_type" + "--only=aws_elasticache_cluster_previous_type" # Prevent some configuration errors - "--enable-rule=aws_route_specified_multiple_targets" - # Prevent expression evaluation - "--disable-rule=aws_acm_certificate_invalid_certificate_body" - "--disable-rule=aws_acm_certificate_invalid_certificate_chain" - "--disable-rule=aws_acm_certificate_invalid_private_key" - "--disable-rule=aws_acmpca_certificate_authority_invalid_type" - "--disable-rule=aws_appsync_datasource_invalid_name" - "--disable-rule=aws_appsync_function_invalid_name" - "--disable-rule=aws_appsync_graphql_api_invalid_authentication_type" - "--disable-rule=aws_athena_workgroup_invalid_name" - "--disable-rule=aws_athena_workgroup_invalid_state" - "--disable-rule=aws_backup_selection_invalid_name" - "--disable-rule=aws_backup_vault_invalid_name" - "--disable-rule=aws_batch_compute_environment_invalid_state" - "--disable-rule=aws_batch_job_queue_invalid_state" - "--disable-rule=aws_budgets_budget_invalid_account_id" - "--disable-rule=aws_budgets_budget_invalid_budget_type" - "--disable-rule=aws_budgets_budget_invalid_time_unit" - "--disable-rule=aws_cloudformation_stack_set_invalid_execution_role_name" - "--disable-rule=aws_cloudwatch_event_permission_invalid_action" - "--disable-rule=aws_cloudwatch_event_permission_invalid_principal" - "--disable-rule=aws_cloudwatch_event_permission_invalid_statement_id" - "--disable-rule=aws_cloudwatch_log_subscription_filter_invalid_distribution" - "--disable-rule=aws_cloudwatch_event_rule_invalid_name" - "--disable-rule=aws_cloudwatch_event_target_invalid_target_id" - "--disable-rule=aws_cloudwatch_log_group_invalid_name" - "--disable-rule=aws_cloudwatch_log_stream_invalid_name" - "--disable-rule=aws_cloudwatch_log_subscription_filter_invalid_name" - "--disable-rule=aws_codebuild_source_credential_invalid_auth_type" - "--disable-rule=aws_codebuild_source_credential_invalid_server_type" - "--disable-rule=aws_codecommit_repository_invalid_repository_name" - "--disable-rule=aws_codedeploy_app_invalid_compute_platform" - "--disable-rule=aws_codepipeline_invalid_name" - "--disable-rule=aws_codepipeline_webhook_invalid_name" - "--disable-rule=aws_cognito_identity_pool_invalid_identity_pool_name" - "--disable-rule=aws_cognito_resource_server_invalid_name" - "--disable-rule=aws_cognito_user_pool_client_invalid_name" - "--disable-rule=aws_cognito_user_pool_domain_invalid_certificate_arn" - "--disable-rule=aws_cognito_user_pool_domain_invalid_domain" - "--disable-rule=aws_cognito_user_pool_invalid_email_verification_message" - "--disable-rule=aws_cognito_user_pool_invalid_mfa_configuration" - "--disable-rule=aws_cognito_user_pool_invalid_name" - "--disable-rule=aws_cognito_user_pool_invalid_sms_authentication_message" - "--disable-rule=aws_cognito_user_pool_invalid_sms_verification_message" - "--disable-rule=aws_config_aggregate_authorization_invalid_account_id" - "--disable-rule=aws_config_configuration_aggregator_invalid_name" - "--disable-rule=aws_config_organization_custom_rule_invalid_maximum_execution_frequency" - "--disable-rule=aws_config_organization_managed_rule_invalid_maximum_execution_frequency" - "--disable-rule=aws_cur_report_definition_invalid_compression" - "--disable-rule=aws_cur_report_definition_invalid_format" - "--disable-rule=aws_cur_report_definition_invalid_report_name" - "--disable-rule=aws_cur_report_definition_invalid_s3_prefix" - "--disable-rule=aws_datasync_agent_invalid_name" - "--disable-rule=aws_datasync_location_efs_invalid_subdirectory" - "--disable-rule=aws_datasync_location_nfs_invalid_subdirectory" - "--disable-rule=aws_datasync_task_invalid_name" - "--disable-rule=aws_db_instance_default_parameter_group" - "--disable-rule=aws_dlm_lifecycle_policy_invalid_description" - "--disable-rule=aws_dynamodb_global_table_invalid_name" - "--disable-rule=aws_dynamodb_table_invalid_stream_view_type" - "--disable-rule=aws_dynamodb_table_invalid_name" - "--disable-rule=aws_ecr_repository_invalid_name" - "--disable-rule=aws_elasticsearch_domain_invalid_domain_name" - "--disable-rule=aws_iam_group_invalid_name" - "--disable-rule=aws_iam_instance_profile_invalid_name" - "--disable-rule=aws_iam_policy_invalid_name" - "--disable-rule=aws_iam_role_invalid_name" - "--disable-rule=aws_iam_role_policy_invalid_name" - "--disable-rule=aws_iam_saml_provider_invalid_name" - "--disable-rule=aws_iam_saml_provider_invalid_saml_metadata_document" - "--disable-rule=aws_iam_server_certificate_invalid_name" - "--disable-rule=aws_iam_server_certificate_invalid_path" - "--disable-rule=aws_iam_user_invalid_name" - "--disable-rule=aws_iam_user_invalid_path" - "--disable-rule=aws_iam_user_invalid_permissions_boundary" - "--disable-rule=aws_kinesis_firehose_delivery_stream_invalid_name" - "--disable-rule=aws_kinesis_stream_invalid_name" - "--disable-rule=aws_kms_alias_invalid_name" - "--disable-rule=aws_lambda_function_invalid_function_name" - "--disable-rule=aws_lambda_layer_version_invalid_layer_name" - "--disable-rule=aws_launch_template_invalid_name" - "--disable-rule=aws_lb_target_group_invalid_protocol" - "--disable-rule=aws_lb_target_group_invalid_target_type" - "--disable-rule=aws_lightsail_key_pair_invalid_name" - "--disable-rule=aws_ssm_document_invalid_name" - "--disable-rule=aws_ssm_patch_baseline_invalid_name" + "--only=aws_route_specified_multiple_targets" ) while read -r filename ; do echo "$filename" From 5a02ebc22165bb4f531f2e2efb3cc9bae7ee6988 Mon Sep 17 00:00:00 2001 From: Graham Davison Date: Tue, 8 Sep 2020 14:14:57 -0700 Subject: [PATCH 2/8] Updates Terraform configurations in acceptance tests for resource names starting with "e" --- .github/workflows/acctest-terraform-lint.yml | 7 + aws/resource_aws_ebs_volume_test.go | 2 +- ...ce_aws_ec2_availability_zone_group_test.go | 2 +- ..._ec2_client_vpn_authorization_rule_test.go | 6 +- ...ec2_client_vpn_network_association_test.go | 2 +- aws/resource_aws_ec2_client_vpn_route_test.go | 14 +- aws/resource_aws_ec2_fleet_test.go | 14 +- ...urce_aws_ec2_traffic_mirror_target_test.go | 10 +- ...transit_gateway_peering_attachment_test.go | 6 +- ...ec2_transit_gateway_vpc_attachment_test.go | 4 +- ...resource_aws_ecs_capacity_provider_test.go | 18 +- aws/resource_aws_ecs_cluster_test.go | 22 +-- aws/resource_aws_ecs_service_test.go | 10 +- aws/resource_aws_efs_file_system_test.go | 22 +-- aws/resource_aws_eip_association_test.go | 69 +++---- aws/resource_aws_eip_test.go | 44 ++--- aws/resource_aws_eks_fargate_profile_test.go | 12 +- aws/resource_aws_eks_node_group_test.go | 36 ++-- aws/resource_aws_elasticache_cluster_test.go | 132 +++----------- ..._aws_elasticache_replication_group_test.go | 22 +-- ...ource_aws_elasticache_subnet_group_test.go | 4 +- aws/resource_aws_elb_attachment_test.go | 10 +- aws/resource_aws_elb_test.go | 8 +- aws/resource_aws_emr_cluster_test.go | 92 +++++----- aws/resource_aws_emr_instance_fleet_test.go | 172 +++++++++--------- aws/resource_aws_emr_instance_group_test.go | 16 +- ...rce_aws_emr_managed_scaling_policy_test.go | 22 +-- 27 files changed, 342 insertions(+), 436 deletions(-) diff --git a/.github/workflows/acctest-terraform-lint.yml b/.github/workflows/acctest-terraform-lint.yml index 15b73c3a3928..f30f985232e7 100644 --- a/.github/workflows/acctest-terraform-lint.yml +++ b/.github/workflows/acctest-terraform-lint.yml @@ -40,10 +40,13 @@ jobs: -o -name 'resource_aws_b*_test.go' \ -o -name 'resource_aws_c*_test.go' \ -o -name 'resource_aws_d*_test.go' \ + -o -name 'resource_aws_e*_test.go' \ \) \ | sort -u \ | grep -v resource_aws_apigatewayv2_domain_name_test.go \ | grep -v resource_aws_dynamodb_table_test.go \ + | grep -v resource_aws_ecs_capacity_provider_test.go \ + | grep -v resource_aws_efs_file_system_test.go \ | xargs -I {} terrafmt diff --check --quiet --fmtcompat {} validate-terraform: @@ -76,9 +79,13 @@ jobs: -o -name 'resource_aws_b*_test.go' \ -o -name 'resource_aws_c*_test.go' \ -o -name 'resource_aws_d*_test.go' \ + -o -name 'resource_aws_e*_test.go' \ \) \ | sort -u \ | grep -v resource_aws_apigatewayv2_domain_name_test.go \ | grep -v resource_aws_dynamodb_table_test.go \ + | grep -v resource_aws_ecs_capacity_provider_test.go \ + | grep -v resource_aws_efs_file_system_test.go \ + | grep -v resource_aws_elasticache_cluster_test.go \ | ./scripts/validate-terraform.sh diff --git a/aws/resource_aws_ebs_volume_test.go b/aws/resource_aws_ebs_volume_test.go index f86b3e44adea..279c3a7693d1 100644 --- a/aws/resource_aws_ebs_volume_test.go +++ b/aws/resource_aws_ebs_volume_test.go @@ -552,7 +552,7 @@ resource "aws_instance" "test" { } tags = { - Name = "test-terraform" + Name = "test-terraform" } } diff --git a/aws/resource_aws_ec2_availability_zone_group_test.go b/aws/resource_aws_ec2_availability_zone_group_test.go index 908f1a9cc60c..c2e2a2086272 100644 --- a/aws/resource_aws_ec2_availability_zone_group_test.go +++ b/aws/resource_aws_ec2_availability_zone_group_test.go @@ -86,7 +86,7 @@ data "aws_availability_zones" "test" { # Filter to one Availability Zone Group per Region as Local Zones become available # e.g. ensure there are not two us-west-2-XXX when adding to this list filter { - name = "group-name" + name = "group-name" values = [ "us-west-2-lax-1", ] diff --git a/aws/resource_aws_ec2_client_vpn_authorization_rule_test.go b/aws/resource_aws_ec2_client_vpn_authorization_rule_test.go index 0ddb922fd159..ecbbf4e7f567 100644 --- a/aws/resource_aws_ec2_client_vpn_authorization_rule_test.go +++ b/aws/resource_aws_ec2_client_vpn_authorization_rule_test.go @@ -324,12 +324,12 @@ resource "aws_ec2_client_vpn_endpoint" "test" { client_cidr_block = "10.0.0.0/16" authentication_options { - type = "certificate-authentication" - root_certificate_chain_arn = aws_acm_certificate.test.arn + type = "certificate-authentication" + root_certificate_chain_arn = aws_acm_certificate.test.arn } connection_log_options { - enabled = false + enabled = false } }`, rName)) } diff --git a/aws/resource_aws_ec2_client_vpn_network_association_test.go b/aws/resource_aws_ec2_client_vpn_network_association_test.go index 06a94e227812..eaf8647521cf 100644 --- a/aws/resource_aws_ec2_client_vpn_network_association_test.go +++ b/aws/resource_aws_ec2_client_vpn_network_association_test.go @@ -307,7 +307,7 @@ resource "aws_ec2_client_vpn_network_association" "test" { subnet_id = aws_subnet.test.id security_groups = [aws_security_group.test1.id, aws_security_group.test2.id] } - + resource "aws_ec2_client_vpn_endpoint" "test" { description = "terraform-testacc-clientvpn-%[1]s" server_certificate_arn = aws_acm_certificate.test.arn diff --git a/aws/resource_aws_ec2_client_vpn_route_test.go b/aws/resource_aws_ec2_client_vpn_route_test.go index d5858a77e68f..da4246ad3164 100644 --- a/aws/resource_aws_ec2_client_vpn_route_test.go +++ b/aws/resource_aws_ec2_client_vpn_route_test.go @@ -172,12 +172,12 @@ resource "aws_ec2_client_vpn_endpoint" "test" { client_cidr_block = "10.0.0.0/16" authentication_options { - type = "certificate-authentication" - root_certificate_chain_arn = aws_acm_certificate.test.arn + type = "certificate-authentication" + root_certificate_chain_arn = aws_acm_certificate.test.arn } connection_log_options { - enabled = false + enabled = false } } `, rName)) @@ -195,7 +195,7 @@ resource "aws_ec2_client_vpn_route" "test" { description = "test client VPN route" depends_on = [ - aws_ec2_client_vpn_network_association.test, + aws_ec2_client_vpn_network_association.test, ] } @@ -210,12 +210,12 @@ resource "aws_ec2_client_vpn_endpoint" "test" { client_cidr_block = "10.0.0.0/16" authentication_options { - type = "certificate-authentication" - root_certificate_chain_arn = aws_acm_certificate.test.arn + type = "certificate-authentication" + root_certificate_chain_arn = aws_acm_certificate.test.arn } connection_log_options { - enabled = false + enabled = false } } `, rName)) diff --git a/aws/resource_aws_ec2_fleet_test.go b/aws/resource_aws_ec2_fleet_test.go index 375453add60f..2eca076a4f02 100644 --- a/aws/resource_aws_ec2_fleet_test.go +++ b/aws/resource_aws_ec2_fleet_test.go @@ -1385,8 +1385,8 @@ resource "aws_launch_template" "test2" { resource "aws_ec2_fleet" "test" { launch_template_config { launch_template_specification { - launch_template_id = "${%s.id}" - version = "${%s.latest_version}" + launch_template_id = %s.id + version = %s.latest_version } } @@ -1425,8 +1425,8 @@ resource "aws_launch_template" "test2" { resource "aws_ec2_fleet" "test" { launch_template_config { launch_template_specification { - launch_template_name = "${%s.name}" - version = "${%s.latest_version}" + launch_template_name = %s.name + version = %s.latest_version } } @@ -1491,7 +1491,7 @@ resource "aws_ec2_fleet" "test" { } override { - availability_zone = "${data.aws_availability_zones.available.names[%d]}" + availability_zone = data.aws_availability_zones.available.names[%d] } } @@ -1615,7 +1615,7 @@ resource "aws_subnet" "test" { count = 2 cidr_block = "10.1.${count.index}.0/24" - vpc_id = "${aws_vpc.test.id}" + vpc_id = aws_vpc.test.id tags = { Name = var.TestAccNameTag @@ -1630,7 +1630,7 @@ resource "aws_ec2_fleet" "test" { } override { - subnet_id = "${aws_subnet.test.*.id[%d]}" + subnet_id = aws_subnet.test.*.id[%d] } } diff --git a/aws/resource_aws_ec2_traffic_mirror_target_test.go b/aws/resource_aws_ec2_traffic_mirror_target_test.go index 9348a2cf5a52..db8bacd7074c 100644 --- a/aws/resource_aws_ec2_traffic_mirror_target_test.go +++ b/aws/resource_aws_ec2_traffic_mirror_target_test.go @@ -233,7 +233,7 @@ resource "aws_lb" "lb" { load_balancer_type = "network" subnets = [aws_subnet.sub1.id, aws_subnet.sub2.id] - enable_deletion_protection = false + enable_deletion_protection = false tags = { Name = %[1]q @@ -254,12 +254,12 @@ data "aws_ami" "amzn-linux" { most_recent = true filter { - name = "name" + name = "name" values = ["amzn2-ami-hvm-2.0*"] } filter { - name = "architecture" + name = "architecture" values = ["x86_64"] } @@ -291,7 +291,7 @@ resource "aws_lb" "lb" { load_balancer_type = "network" subnets = [aws_subnet.sub1.id, aws_subnet.sub2.id] - enable_deletion_protection = false + enable_deletion_protection = false tags = { Name = %[1]q @@ -318,7 +318,7 @@ resource "aws_lb" "lb" { load_balancer_type = "network" subnets = [aws_subnet.sub1.id, aws_subnet.sub2.id] - enable_deletion_protection = false + enable_deletion_protection = false tags = { Name = %[1]q diff --git a/aws/resource_aws_ec2_transit_gateway_peering_attachment_test.go b/aws/resource_aws_ec2_transit_gateway_peering_attachment_test.go index e7422f9760c0..a17692766d8d 100644 --- a/aws/resource_aws_ec2_transit_gateway_peering_attachment_test.go +++ b/aws/resource_aws_ec2_transit_gateway_peering_attachment_test.go @@ -377,7 +377,8 @@ resource "aws_ec2_transit_gateway_peering_attachment" "test" { transit_gateway_id = aws_ec2_transit_gateway.test.id tags = { - Name = %[2]q + Name = %[2]q + %[3]s = %[4]q } } @@ -392,7 +393,8 @@ resource "aws_ec2_transit_gateway_peering_attachment" "test" { transit_gateway_id = aws_ec2_transit_gateway.test.id tags = { - Name = %[2]q + Name = %[2]q + %[3]s = %[4]q %[5]s = %[6]q } diff --git a/aws/resource_aws_ec2_transit_gateway_vpc_attachment_test.go b/aws/resource_aws_ec2_transit_gateway_vpc_attachment_test.go index d7b8d0562df8..8689b7d70a84 100644 --- a/aws/resource_aws_ec2_transit_gateway_vpc_attachment_test.go +++ b/aws/resource_aws_ec2_transit_gateway_vpc_attachment_test.go @@ -773,7 +773,7 @@ resource "aws_subnet" "test" { resource "aws_ec2_transit_gateway" "test" {} resource "aws_ec2_transit_gateway_vpc_attachment" "test" { - subnet_ids = [aws_subnet.test.0.id] + subnet_ids = [aws_subnet.test[0].id] transit_gateway_id = aws_ec2_transit_gateway.test.id vpc_id = aws_vpc.test.id } @@ -816,7 +816,7 @@ resource "aws_subnet" "test" { resource "aws_ec2_transit_gateway" "test" {} resource "aws_ec2_transit_gateway_vpc_attachment" "test" { - subnet_ids = [aws_subnet.test.0.id, aws_subnet.test.1.id] + subnet_ids = [aws_subnet.test[0].id, aws_subnet.test[1].id] transit_gateway_id = aws_ec2_transit_gateway.test.id vpc_id = aws_vpc.test.id } diff --git a/aws/resource_aws_ecs_capacity_provider_test.go b/aws/resource_aws_ecs_capacity_provider_test.go index e768060fae64..e8d307753072 100644 --- a/aws/resource_aws_ecs_capacity_provider_test.go +++ b/aws/resource_aws_ecs_capacity_provider_test.go @@ -365,13 +365,13 @@ resource "aws_autoscaling_group" "test" { id = aws_launch_template.test.id } - tags = [ - { - key = "foo" - value = "bar" - propagate_at_launch = true - }, - ] + tags = [ + { + key = "foo" + value = "bar" + propagate_at_launch = true + }, + ] } `, rName) } @@ -427,10 +427,10 @@ resource "aws_ecs_capacity_provider" "test" { func testAccAWSEcsCapacityProviderConfigTags1(rName, tag1Key, tag1Value string) string { return testAccAWSEcsCapacityProviderConfigBase(rName) + fmt.Sprintf(` resource "aws_ecs_capacity_provider" "test" { - name = %q + name = %[1]q tags = { - %q = %q, + %[2]q = %[3]q, } auto_scaling_group_provider { diff --git a/aws/resource_aws_ecs_cluster_test.go b/aws/resource_aws_ecs_cluster_test.go index a053a24f12dc..2e3136e95aa2 100644 --- a/aws/resource_aws_ecs_cluster_test.go +++ b/aws/resource_aws_ecs_cluster_test.go @@ -426,11 +426,11 @@ resource "aws_ecs_cluster" "test" { func testAccAWSEcsClusterCapacityProviderConfig(rName string) string { return testAccAWSEcsCapacityProviderConfigBase(rName) + fmt.Sprintf(` resource "aws_ecs_capacity_provider" "test" { - name = %q + name = %q - auto_scaling_group_provider { - auto_scaling_group_arn = aws_autoscaling_group.test.arn - } + auto_scaling_group_provider { + auto_scaling_group_arn = aws_autoscaling_group.test.arn + } } `, rName) } @@ -438,15 +438,15 @@ resource "aws_ecs_capacity_provider" "test" { func testAccAWSEcsClusterSingleCapacityProvider(rName, providerName string) string { return testAccAWSEcsClusterCapacityProviderConfig(providerName) + fmt.Sprintf(` resource "aws_ecs_cluster" "test" { - name = %[1]q + name = %[1]q - capacity_providers = [aws_ecs_capacity_provider.test.name] + capacity_providers = [aws_ecs_capacity_provider.test.name] - default_capacity_provider_strategy { - base = 1 - capacity_provider = aws_ecs_capacity_provider.test.name - weight = 1 - } + default_capacity_provider_strategy { + base = 1 + capacity_provider = aws_ecs_capacity_provider.test.name + weight = 1 + } } `, rName) } diff --git a/aws/resource_aws_ecs_service_test.go b/aws/resource_aws_ecs_service_test.go index accf909a8e15..6d3874e0c57c 100644 --- a/aws/resource_aws_ecs_service_test.go +++ b/aws/resource_aws_ecs_service_test.go @@ -1424,8 +1424,8 @@ resource "aws_ecs_service" "mongo" { capacity_provider_strategy { capacity_provider = aws_ecs_capacity_provider.test.name - weight = %d - base = %d + weight = %d + base = %d } } `, providerName, clusterName, tdName, svcName, weight, base) @@ -1438,7 +1438,7 @@ resource "aws_ecs_service" "mongo" { cluster = aws_ecs_cluster.test.id task_definition = aws_ecs_task_definition.mongo.arn desired_count = 1 - + network_configuration { security_groups = [aws_security_group.allow_all.id] subnets = [aws_subnet.main.id] @@ -1490,8 +1490,8 @@ resource "aws_security_group" "allow_all" { } resource "aws_subnet" "main" { - cidr_block = cidrsubnet(aws_vpc.main.cidr_block, 8, 1) - vpc_id = aws_vpc.main.id + cidr_block = cidrsubnet(aws_vpc.main.cidr_block, 8, 1) + vpc_id = aws_vpc.main.id tags = { Name = "tf-acc-ecs-service-with-multiple-capacity-providers" diff --git a/aws/resource_aws_efs_file_system_test.go b/aws/resource_aws_efs_file_system_test.go index 968832ec9483..3102d906a91b 100644 --- a/aws/resource_aws_efs_file_system_test.go +++ b/aws/resource_aws_efs_file_system_test.go @@ -634,10 +634,10 @@ resource "aws_efs_file_system" "test" { func testAccAWSEFSFileSystemConfigTags1(rName, tagKey1, tagValue1 string) string { return fmt.Sprintf(` resource "aws_efs_file_system" "test" { - creation_token = %[1]q - tags = { - %[2]q = %[3]q - } + creation_token = %[1]q + tags = { + %[2]q = %[3]q + } } `, rName, tagKey1, tagValue1) } @@ -645,11 +645,11 @@ resource "aws_efs_file_system" "test" { func testAccAWSEFSFileSystemConfigTags2(rName, tagKey1, tagValue1, tagKey2, tagValue2 string) string { return fmt.Sprintf(` resource "aws_efs_file_system" "test" { - creation_token = %[1]q - tags = { - %[2]q = %[3]q - %[4]q = %[5]q - } + creation_token = %[1]q + tags = { + %[2]q = %[3]q + %[4]q = %[5]q + } } `, rName, tagKey1, tagValue1, tagKey2, tagValue2) } @@ -735,8 +735,8 @@ resource "aws_efs_file_system" "test" { const testAccAWSEFSFileSystemConfigWithPerformanceMode = ` resource "aws_efs_file_system" "test2" { - creation_token = "supercalifragilisticexpialidocious" - performance_mode = "maxIO" + creation_token = "supercalifragilisticexpialidocious" + performance_mode = "maxIO" } ` diff --git a/aws/resource_aws_eip_association_test.go b/aws/resource_aws_eip_association_test.go index 6b8c49ec2496..95ed70bf5da5 100644 --- a/aws/resource_aws_eip_association_test.go +++ b/aws/resource_aws_eip_association_test.go @@ -24,12 +24,9 @@ func TestAccAWSEIPAssociation_instance(t *testing.T) { { Config: testAccAWSEIPAssociationConfig_instance(), Check: resource.ComposeTestCheckFunc( - testAccCheckAWSEIPExists( - "aws_eip.test", &a), - testAccCheckAWSEIPAssociationExists( - resourceName, &a), - testAccCheckAWSEIPAssociationExists( - resourceName, &a), + testAccCheckAWSEIPExists("aws_eip.test", &a), + testAccCheckAWSEIPAssociationExists(resourceName, &a), + testAccCheckAWSEIPAssociationExists(resourceName, &a), ), }, { @@ -53,10 +50,8 @@ func TestAccAWSEIPAssociation_networkInterface(t *testing.T) { { Config: testAccAWSEIPAssociationConfig_networkInterface, Check: resource.ComposeTestCheckFunc( - testAccCheckAWSEIPExists( - "aws_eip.test", &a), - testAccCheckAWSEIPAssociationExists( - resourceName, &a), + testAccCheckAWSEIPExists("aws_eip.test", &a), + testAccCheckAWSEIPAssociationExists(resourceName, &a), ), }, { @@ -80,18 +75,12 @@ func TestAccAWSEIPAssociation_basic(t *testing.T) { { Config: testAccAWSEIPAssociationConfig, Check: resource.ComposeTestCheckFunc( - testAccCheckAWSEIPExists( - "aws_eip.test.0", &a), - testAccCheckAWSEIPAssociationExists( - "aws_eip_association.by_allocation_id", &a), - testAccCheckAWSEIPExists( - "aws_eip.test.1", &a), - testAccCheckAWSEIPAssociationExists( - "aws_eip_association.by_public_ip", &a), - testAccCheckAWSEIPExists( - "aws_eip.test.2", &a), - testAccCheckAWSEIPAssociationExists( - "aws_eip_association.to_eni", &a), + testAccCheckAWSEIPExists("aws_eip.test.0", &a), + testAccCheckAWSEIPAssociationExists("aws_eip_association.by_allocation_id", &a), + testAccCheckAWSEIPExists("aws_eip.test.1", &a), + testAccCheckAWSEIPAssociationExists("aws_eip_association.by_public_ip", &a), + testAccCheckAWSEIPExists("aws_eip.test.2", &a), + testAccCheckAWSEIPAssociationExists("aws_eip_association.to_eni", &a), ), }, { @@ -303,7 +292,7 @@ data "aws_ami" "amzn-ami-minimal-pv" { owners = ["amazon"] filter { - name = "name" + name = "name" values = ["amzn-ami-minimal-pv-*"] } } @@ -325,9 +314,9 @@ resource "aws_instance" "test" { count = 2 ami = data.aws_ami.amzn-ami-minimal-pv.id availability_zone = data.aws_availability_zones.available.names[0] - instance_type = "m1.small" + instance_type = "t2.small" subnet_id = aws_subnet.test.id - private_ip = "192.168.0.${count.index+10}" + private_ip = "192.168.0.${count.index + 10}" } resource "aws_eip" "test" { @@ -336,19 +325,19 @@ resource "aws_eip" "test" { } resource "aws_eip_association" "by_allocation_id" { - allocation_id = aws_eip.test.0.id - instance_id = aws_instance.test.0.id + allocation_id = aws_eip.test[0].id + instance_id = aws_instance.test[0].id depends_on = [aws_instance.test] } resource "aws_eip_association" "by_public_ip" { - public_ip = aws_eip.test.1.public_ip - instance_id = aws_instance.test.1.id + public_ip = aws_eip.test[1].public_ip + instance_id = aws_instance.test[1].id depends_on = [aws_instance.test] } resource "aws_eip_association" "to_eni" { - allocation_id = aws_eip.test.2.id + allocation_id = aws_eip.test[2].id network_interface_id = aws_network_interface.test.id } @@ -358,7 +347,7 @@ resource "aws_network_interface" "test" { depends_on = [aws_instance.test] attachment { - instance = aws_instance.test.0.id + instance = aws_instance.test[0].id device_index = 1 } } @@ -379,7 +368,7 @@ data "aws_ami" "amzn-ami-minimal-pv" { owners = ["amazon"] filter { - name = "name" + name = "name" values = ["amzn-ami-minimal-pv-*"] } } @@ -407,7 +396,7 @@ resource "aws_internet_gateway" "igw" { resource "aws_instance" "foo" { ami = data.aws_ami.amzn-ami-minimal-pv.id availability_zone = data.aws_availability_zones.available.names[0] - instance_type = "m1.small" + instance_type = "t2.small" subnet_id = aws_subnet.sub.id } @@ -456,7 +445,7 @@ data "aws_ami" "ubuntu" { resource "aws_instance" "test" { ami = data.aws_ami.ubuntu.id availability_zone = data.aws_availability_zones.available.names[0] - instance_type = "t1.micro" + instance_type = "t2.micro" } resource "aws_eip_association" "test" { @@ -466,24 +455,22 @@ resource "aws_eip_association" "test" { ` func testAccAWSEIPAssociationConfig_spotInstance(rInt int) string { - return fmt.Sprintf(` -%s - -resource "aws_eip" "test" { -} + return composeConfig( + testAccAWSSpotInstanceRequestConfig(rInt), ` +resource "aws_eip" "test" {} resource "aws_eip_association" "test" { allocation_id = aws_eip.test.id instance_id = aws_spot_instance_request.test.spot_instance_id } -`, testAccAWSSpotInstanceRequestConfig(rInt)) +`) } func testAccAWSEIPAssociationConfig_instance() string { return testAccLatestAmazonLinuxHvmEbsAmiConfig() + fmt.Sprintf(` resource "aws_instance" "test" { ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id - instance_type = "m1.small" + instance_type = "t2.small" } resource "aws_eip" "test" {} diff --git a/aws/resource_aws_eip_test.go b/aws/resource_aws_eip_test.go index f2b540eb91b9..f2aa81b18f2b 100644 --- a/aws/resource_aws_eip_test.go +++ b/aws/resource_aws_eip_test.go @@ -682,7 +682,7 @@ resource "aws_eip" "test" { const testAccAWSEIPConfig_PublicIpv4Pool_default = ` resource "aws_eip" "test" { - vpc = true + vpc = true } ` @@ -697,7 +697,7 @@ resource "aws_eip" "test" { const testAccAWSEIPInstanceEc2Classic = ` provider "aws" { - region = "us-east-1" + region = "us-east-1" } data "aws_ami" "amzn-ami-minimal-pv" { @@ -705,18 +705,18 @@ data "aws_ami" "amzn-ami-minimal-pv" { owners = ["amazon"] filter { - name = "name" + name = "name" values = ["amzn-ami-minimal-pv-*"] } filter { - name = "root-device-type" + name = "root-device-type" values = ["instance-store"] } } resource "aws_instance" "test" { ami = data.aws_ami.amzn-ami-minimal-pv.id - instance_type = "m1.small" + instance_type = "t2.small" tags = { Name = "testAccAWSEIPInstanceEc2Classic" } @@ -733,18 +733,18 @@ data "aws_ami" "amzn-ami-minimal-pv" { owners = ["amazon"] filter { - name = "name" + name = "name" values = ["amzn-ami-minimal-pv-*"] } filter { - name = "root-device-type" + name = "root-device-type" values = ["instance-store"] } } resource "aws_instance" "test" { ami = data.aws_ami.amzn-ami-minimal-pv.id - instance_type = "m1.small" + instance_type = "t2.small" } resource "aws_eip" "test" { @@ -758,18 +758,18 @@ data "aws_ami" "amzn-ami-minimal-pv" { owners = ["amazon"] filter { - name = "name" + name = "name" values = ["amzn-ami-minimal-pv-*"] } filter { - name = "root-device-type" + name = "root-device-type" values = ["instance-store"] } } resource "aws_instance" "test" { ami = data.aws_ami.amzn-ami-minimal-pv.id - instance_type = "m1.small" + instance_type = "t2.small" } resource "aws_eip" "test" { @@ -783,11 +783,11 @@ data "aws_ami" "amzn-ami-minimal-hvm" { owners = ["amazon"] filter { - name = "name" + name = "name" values = ["amzn-ami-minimal-hvm-*"] } filter { - name = "root-device-type" + name = "root-device-type" values = ["ebs"] } } @@ -859,11 +859,11 @@ data "aws_ami" "amzn-ami-minimal-hvm" { owners = ["amazon"] filter { - name = "name" + name = "name" values = ["amzn-ami-minimal-hvm-*"] } filter { - name = "root-device-type" + name = "root-device-type" values = ["ebs"] } } @@ -1104,18 +1104,18 @@ data "aws_ami" "amzn-ami-minimal-pv" { owners = ["amazon"] filter { - name = "name" + name = "name" values = ["amzn-ami-minimal-pv-*"] } filter { - name = "root-device-type" + name = "root-device-type" values = ["instance-store"] } } resource "aws_instance" "test" { ami = data.aws_ami.amzn-ami-minimal-pv.id - instance_type = "m1.small" + instance_type = "t2.small" } resource "aws_eip" "test" { @@ -1128,22 +1128,22 @@ data "aws_ami" "amzn-ami-minimal-pv" { owners = ["amazon"] filter { - name = "name" + name = "name" values = ["amzn-ami-minimal-pv-*"] } filter { - name = "root-device-type" + name = "root-device-type" values = ["instance-store"] } } resource "aws_instance" "test" { ami = data.aws_ami.amzn-ami-minimal-pv.id - instance_type = "m1.small" + instance_type = "t2.small" } resource "aws_eip" "test" { - instance = aws_instance.test.id + instance = aws_instance.test.id } ` diff --git a/aws/resource_aws_eks_fargate_profile_test.go b/aws/resource_aws_eks_fargate_profile_test.go index fdc4b0d5ef42..b7fac06638e8 100644 --- a/aws/resource_aws_eks_fargate_profile_test.go +++ b/aws/resource_aws_eks_fargate_profile_test.go @@ -366,8 +366,8 @@ resource "aws_iam_role" "cluster" { assume_role_policy = jsonencode({ Statement = [{ - Action = "sts:AssumeRole" - Effect = "Allow" + Action = "sts:AssumeRole" + Effect = "Allow" Principal = { Service = "eks.${data.aws_partition.current.dns_suffix}" } @@ -383,11 +383,11 @@ resource "aws_iam_role_policy_attachment" "cluster-AmazonEKSClusterPolicy" { resource "aws_iam_role" "pod" { name = "%[1]s-pod" - + assume_role_policy = jsonencode({ Statement = [{ - Action = "sts:AssumeRole" - Effect = "Allow" + Action = "sts:AssumeRole" + Effect = "Allow" Principal = { Service = "eks-fargate-pods.${data.aws_partition.current.dns_suffix}" } @@ -434,7 +434,7 @@ resource "aws_subnet" "private" { count = 2 availability_zone = data.aws_availability_zones.available.names[count.index] - cidr_block = cidrsubnet(aws_vpc.test.cidr_block, 8, count.index+2) + cidr_block = cidrsubnet(aws_vpc.test.cidr_block, 8, count.index + 2) vpc_id = aws_vpc.test.id tags = { diff --git a/aws/resource_aws_eks_node_group_test.go b/aws/resource_aws_eks_node_group_test.go index c828c1bd3f1d..01db6d401eeb 100644 --- a/aws/resource_aws_eks_node_group_test.go +++ b/aws/resource_aws_eks_node_group_test.go @@ -853,8 +853,8 @@ resource "aws_iam_role" "cluster" { assume_role_policy = jsonencode({ Statement = [{ - Action = "sts:AssumeRole" - Effect = "Allow" + Action = "sts:AssumeRole" + Effect = "Allow" Principal = { Service = [ "eks.${data.aws_partition.current.dns_suffix}", @@ -873,14 +873,14 @@ resource "aws_iam_role_policy_attachment" "cluster-AmazonEKSClusterPolicy" { resource "aws_iam_role" "node" { name = "%[1]s-node" - + assume_role_policy = jsonencode({ Statement = [{ - Action = "sts:AssumeRole" - Effect = "Allow" - Principal = { - Service = "ec2.${data.aws_partition.current.dns_suffix}" - } + Action = "sts:AssumeRole" + Effect = "Allow" + Principal = { + Service = "ec2.${data.aws_partition.current.dns_suffix}" + } }] Version = "2012-10-17" }) @@ -1193,14 +1193,14 @@ resource "aws_launch_template" "test1" { image_id = data.aws_ssm_parameter.test.value instance_type = "t3.medium" name = "%[1]s-1" - user_data = base64encode(templatefile("testdata/service/eks/node-group-launch-template-user-data.sh.tmpl", {cluster_name = aws_eks_cluster.test.name})) + user_data = base64encode(templatefile("testdata/service/eks/node-group-launch-template-user-data.sh.tmpl", { cluster_name = aws_eks_cluster.test.name })) } resource "aws_launch_template" "test2" { image_id = data.aws_ssm_parameter.test.value instance_type = "t3.medium" name = "%[1]s-2" - user_data = base64encode(templatefile("testdata/service/eks/node-group-launch-template-user-data.sh.tmpl", {cluster_name = aws_eks_cluster.test.name})) + user_data = base64encode(templatefile("testdata/service/eks/node-group-launch-template-user-data.sh.tmpl", { cluster_name = aws_eks_cluster.test.name })) } resource "aws_eks_node_group" "test" { @@ -1241,14 +1241,14 @@ resource "aws_launch_template" "test1" { image_id = data.aws_ssm_parameter.test.value instance_type = "t3.medium" name = "%[1]s-1" - user_data = base64encode(templatefile("testdata/service/eks/node-group-launch-template-user-data.sh.tmpl", {cluster_name = aws_eks_cluster.test.name})) + user_data = base64encode(templatefile("testdata/service/eks/node-group-launch-template-user-data.sh.tmpl", { cluster_name = aws_eks_cluster.test.name })) } resource "aws_launch_template" "test2" { image_id = data.aws_ssm_parameter.test.value instance_type = "t3.medium" name = "%[1]s-2" - user_data = base64encode(templatefile("testdata/service/eks/node-group-launch-template-user-data.sh.tmpl", {cluster_name = aws_eks_cluster.test.name})) + user_data = base64encode(templatefile("testdata/service/eks/node-group-launch-template-user-data.sh.tmpl", { cluster_name = aws_eks_cluster.test.name })) } resource "aws_eks_node_group" "test" { @@ -1289,14 +1289,14 @@ resource "aws_launch_template" "test1" { image_id = data.aws_ssm_parameter.test.value instance_type = "t3.medium" name = "%[1]s-1" - user_data = base64encode(templatefile("testdata/service/eks/node-group-launch-template-user-data.sh.tmpl", {cluster_name = aws_eks_cluster.test.name})) + user_data = base64encode(templatefile("testdata/service/eks/node-group-launch-template-user-data.sh.tmpl", { cluster_name = aws_eks_cluster.test.name })) } resource "aws_launch_template" "test2" { image_id = data.aws_ssm_parameter.test.value instance_type = "t3.medium" name = "%[1]s-2" - user_data = base64encode(templatefile("testdata/service/eks/node-group-launch-template-user-data.sh.tmpl", {cluster_name = aws_eks_cluster.test.name})) + user_data = base64encode(templatefile("testdata/service/eks/node-group-launch-template-user-data.sh.tmpl", { cluster_name = aws_eks_cluster.test.name })) } resource "aws_eks_node_group" "test" { @@ -1337,14 +1337,14 @@ resource "aws_launch_template" "test1" { image_id = data.aws_ssm_parameter.test.value instance_type = "t3.medium" name = "%[1]s-1" - user_data = base64encode(templatefile("testdata/service/eks/node-group-launch-template-user-data.sh.tmpl", {cluster_name = aws_eks_cluster.test.name})) + user_data = base64encode(templatefile("testdata/service/eks/node-group-launch-template-user-data.sh.tmpl", { cluster_name = aws_eks_cluster.test.name })) } resource "aws_launch_template" "test2" { image_id = data.aws_ssm_parameter.test.value instance_type = "t3.medium" name = "%[1]s-2" - user_data = base64encode(templatefile("testdata/service/eks/node-group-launch-template-user-data.sh.tmpl", {cluster_name = aws_eks_cluster.test.name})) + user_data = base64encode(templatefile("testdata/service/eks/node-group-launch-template-user-data.sh.tmpl", { cluster_name = aws_eks_cluster.test.name })) } resource "aws_eks_node_group" "test" { @@ -1386,7 +1386,7 @@ resource "aws_launch_template" "test" { instance_type = "t3.medium" name = %[1]q update_default_version = true - user_data = base64encode(templatefile("testdata/service/eks/node-group-launch-template-user-data.sh.tmpl", {cluster_name = aws_eks_cluster.test.name})) + user_data = base64encode(templatefile("testdata/service/eks/node-group-launch-template-user-data.sh.tmpl", { cluster_name = aws_eks_cluster.test.name })) } resource "aws_eks_node_group" "test" { @@ -1428,7 +1428,7 @@ resource "aws_launch_template" "test" { instance_type = "t3.large" name = %[1]q update_default_version = true - user_data = base64encode(templatefile("testdata/service/eks/node-group-launch-template-user-data.sh.tmpl", {cluster_name = aws_eks_cluster.test.name})) + user_data = base64encode(templatefile("testdata/service/eks/node-group-launch-template-user-data.sh.tmpl", { cluster_name = aws_eks_cluster.test.name })) } resource "aws_eks_node_group" "test" { diff --git a/aws/resource_aws_elasticache_cluster_test.go b/aws/resource_aws_elasticache_cluster_test.go index fb2bb29c70db..2c1ffde05508 100644 --- a/aws/resource_aws_elasticache_cluster_test.go +++ b/aws/resource_aws_elasticache_cluster_test.go @@ -542,18 +542,18 @@ func TestAccAWSElasticacheCluster_NodeTypeResize_Memcached(t *testing.T) { CheckDestroy: testAccCheckAWSElasticacheClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSElasticacheClusterConfig_NodeType_Memcached(rName, "cache.m3.medium"), + Config: testAccAWSElasticacheClusterConfig_NodeType_Memcached(rName, "cache.t2.medium"), Check: resource.ComposeTestCheckFunc( testAccCheckAWSElasticacheClusterExists(resourceName, &pre), - resource.TestCheckResourceAttr(resourceName, "node_type", "cache.m3.medium"), + resource.TestCheckResourceAttr(resourceName, "node_type", "cache.t2.medium"), ), }, { - Config: testAccAWSElasticacheClusterConfig_NodeType_Memcached(rName, "cache.m3.large"), + Config: testAccAWSElasticacheClusterConfig_NodeType_Memcached(rName, "cache.t2.large"), Check: resource.ComposeTestCheckFunc( testAccCheckAWSElasticacheClusterExists(resourceName, &post), testAccCheckAWSElasticacheClusterRecreated(&pre, &post), - resource.TestCheckResourceAttr(resourceName, "node_type", "cache.m3.large"), + resource.TestCheckResourceAttr(resourceName, "node_type", "cache.t2.large"), ), }, }, @@ -571,18 +571,18 @@ func TestAccAWSElasticacheCluster_NodeTypeResize_Redis(t *testing.T) { CheckDestroy: testAccCheckAWSElasticacheClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSElasticacheClusterConfig_NodeType_Redis(rName, "cache.m3.medium"), + Config: testAccAWSElasticacheClusterConfig_NodeType_Redis(rName, "cache.t2.medium"), Check: resource.ComposeTestCheckFunc( testAccCheckAWSElasticacheClusterExists(resourceName, &pre), - resource.TestCheckResourceAttr(resourceName, "node_type", "cache.m3.medium"), + resource.TestCheckResourceAttr(resourceName, "node_type", "cache.t2.medium"), ), }, { - Config: testAccAWSElasticacheClusterConfig_NodeType_Redis(rName, "cache.m3.large"), + Config: testAccAWSElasticacheClusterConfig_NodeType_Redis(rName, "cache.t2.large"), Check: resource.ComposeTestCheckFunc( testAccCheckAWSElasticacheClusterExists(resourceName, &post), testAccCheckAWSElasticacheClusterNotRecreated(&pre, &post), - resource.TestCheckResourceAttr(resourceName, "node_type", "cache.m3.large"), + resource.TestCheckResourceAttr(resourceName, "node_type", "cache.t2.large"), ), }, }, @@ -605,82 +605,6 @@ func TestAccAWSElasticacheCluster_NumCacheNodes_Redis(t *testing.T) { }) } -func TestAccAWSElasticacheCluster_ReplicationGroupID_InvalidAttributes(t *testing.T) { - rName := acctest.RandomWithPrefix("tf-acc-test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAWSElasticacheClusterDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAWSElasticacheClusterConfig_ReplicationGroupID_InvalidAttribute(rName, "az_mode", "single-az"), - ExpectError: regexp.MustCompile(`"replication_group_id": conflicts with az_mode`), - }, - { - Config: testAccAWSElasticacheClusterConfig_ReplicationGroupID_InvalidAttribute(rName, "engine_version", "3.2.10"), - ExpectError: regexp.MustCompile(`"replication_group_id": conflicts with engine_version`), - }, - { - Config: testAccAWSElasticacheClusterConfig_ReplicationGroupID_InvalidAttribute(rName, "engine", "redis"), - ExpectError: regexp.MustCompile(`"replication_group_id": conflicts with engine`), - }, - { - Config: testAccAWSElasticacheClusterConfig_ReplicationGroupID_InvalidAttribute(rName, "maintenance_window", "sun:05:00-sun:09:00"), - ExpectError: regexp.MustCompile(`"replication_group_id": conflicts with maintenance_window`), - }, - { - Config: testAccAWSElasticacheClusterConfig_ReplicationGroupID_InvalidAttribute(rName, "node_type", "cache.m3.medium"), - ExpectError: regexp.MustCompile(`"replication_group_id": conflicts with node_type`), - }, - { - Config: testAccAWSElasticacheClusterConfig_ReplicationGroupID_InvalidAttribute(rName, "notification_topic_arn", "arn:aws:sns:us-east-1:123456789012:topic/non-existent"), - ExpectError: regexp.MustCompile(`"replication_group_id": conflicts with notification_topic_arn`), - }, - { - Config: testAccAWSElasticacheClusterConfig_ReplicationGroupID_InvalidAttribute(rName, "num_cache_nodes", "1"), - ExpectError: regexp.MustCompile(`"replication_group_id": conflicts with num_cache_nodes`), - }, - { - Config: testAccAWSElasticacheClusterConfig_ReplicationGroupID_InvalidAttribute(rName, "parameter_group_name", "non-existent"), - ExpectError: regexp.MustCompile(`"replication_group_id": conflicts with parameter_group_name`), - }, - { - Config: testAccAWSElasticacheClusterConfig_ReplicationGroupID_InvalidAttribute(rName, "port", "6379"), - ExpectError: regexp.MustCompile(`"replication_group_id": conflicts with port`), - }, - { - Config: testAccAWSElasticacheClusterConfig_ReplicationGroupID_InvalidAttribute(rName, "security_group_ids", "${list(\"sg-12345678\", \"sg-87654321\")}"), - ExpectError: regexp.MustCompile(`"replication_group_id": conflicts with security_group_ids`), - }, - { - Config: testAccAWSElasticacheClusterConfig_ReplicationGroupID_InvalidAttribute(rName, "security_group_names", "${list(\"group1\", \"group2\")}"), - ExpectError: regexp.MustCompile(`"replication_group_id": conflicts with security_group_names`), - }, - { - Config: testAccAWSElasticacheClusterConfig_ReplicationGroupID_InvalidAttribute(rName, "snapshot_arns", "${list(\"arn:aws:s3:::my_bucket/snapshot1.rdb\")}"), - ExpectError: regexp.MustCompile(`"replication_group_id": conflicts with snapshot_arns`), - }, - { - Config: testAccAWSElasticacheClusterConfig_ReplicationGroupID_InvalidAttribute(rName, "snapshot_name", "arn:aws:s3:::my_bucket/snapshot1.rdb"), - ExpectError: regexp.MustCompile(`"replication_group_id": conflicts with snapshot_name`), - }, - { - Config: testAccAWSElasticacheClusterConfig_ReplicationGroupID_InvalidAttribute(rName, "snapshot_retention_limit", "0"), - ExpectError: regexp.MustCompile(`"replication_group_id": conflicts with snapshot_retention_limit`), - }, - { - Config: testAccAWSElasticacheClusterConfig_ReplicationGroupID_InvalidAttribute(rName, "snapshot_window", "05:00-09:00"), - ExpectError: regexp.MustCompile(`"replication_group_id": conflicts with snapshot_window`), - }, - { - Config: testAccAWSElasticacheClusterConfig_ReplicationGroupID_InvalidAttribute(rName, "subnet_group_name", "group1"), - ExpectError: regexp.MustCompile(`"replication_group_id": conflicts with subnet_group_name`), - }, - }, - }) -} - func TestAccAWSElasticacheCluster_ReplicationGroupID_AvailabilityZone(t *testing.T) { var cluster elasticache.CacheCluster var replicationGroup elasticache.ReplicationGroup @@ -724,7 +648,7 @@ func TestAccAWSElasticacheCluster_ReplicationGroupID_SingleReplica(t *testing.T) testAccCheckAWSElasticacheClusterExists(clusterResourceName, &cluster), testAccCheckAWSElasticacheClusterReplicationGroupIDAttribute(&cluster, &replicationGroup), resource.TestCheckResourceAttr(clusterResourceName, "engine", "redis"), - resource.TestCheckResourceAttr(clusterResourceName, "node_type", "cache.m3.medium"), + resource.TestCheckResourceAttr(clusterResourceName, "node_type", "cache.t2.medium"), resource.TestCheckResourceAttr(clusterResourceName, "port", "6379"), ), }, @@ -754,10 +678,10 @@ func TestAccAWSElasticacheCluster_ReplicationGroupID_MultipleReplica(t *testing. testAccCheckAWSElasticacheClusterReplicationGroupIDAttribute(&cluster1, &replicationGroup), testAccCheckAWSElasticacheClusterReplicationGroupIDAttribute(&cluster2, &replicationGroup), resource.TestCheckResourceAttr(clusterResourceName1, "engine", "redis"), - resource.TestCheckResourceAttr(clusterResourceName1, "node_type", "cache.m3.medium"), + resource.TestCheckResourceAttr(clusterResourceName1, "node_type", "cache.t2.medium"), resource.TestCheckResourceAttr(clusterResourceName1, "port", "6379"), resource.TestCheckResourceAttr(clusterResourceName2, "engine", "redis"), - resource.TestCheckResourceAttr(clusterResourceName2, "node_type", "cache.m3.medium"), + resource.TestCheckResourceAttr(clusterResourceName2, "node_type", "cache.t2.medium"), resource.TestCheckResourceAttr(clusterResourceName2, "port", "6379"), ), }, @@ -939,7 +863,7 @@ resource "aws_elasticache_security_group" "test" { resource "aws_elasticache_cluster" "test" { cluster_id = "tf-%s" engine = "memcached" - node_type = "cache.m3.medium" + node_type = "cache.t2.medium" num_cache_nodes = 1 port = 11211 security_group_names = [aws_elasticache_security_group.test.name] @@ -1079,7 +1003,7 @@ resource "aws_elasticache_cluster" "test" { } resource "aws_sns_topic" "test" { - name = "tf-ecache-cluster-test" + name = "tf-ecache-cluster-test" } `, acctest.RandInt(), acctest.RandInt(), acctest.RandString(10)) @@ -1117,14 +1041,14 @@ resource "aws_subnet" "test2" { availability_zone = data.aws_availability_zones.available.names[1] tags = { - Name = "tf-acc-elasticache-cluster-multi-az-in-vpc-bar" - } + Name = "tf-acc-elasticache-cluster-multi-az-in-vpc-bar" + } } resource "aws_elasticache_subnet_group" "test" { name = "tf-test-cache-subnet-%03d" description = "tf-test-cache-subnet-group-descr" - subnet_ids = [ + subnet_ids = [ aws_subnet.test1.id, aws_subnet.test2.id, ] @@ -1191,7 +1115,7 @@ resource "aws_elasticache_cluster" "test" { az_mode = "%[2]s" cluster_id = "%[1]s" engine = "memcached" - node_type = "cache.m3.medium" + node_type = "cache.t2.medium" num_cache_nodes = 1 port = 11211 } @@ -1205,7 +1129,7 @@ resource "aws_elasticache_cluster" "test" { az_mode = "%[2]s" cluster_id = "%[1]s" engine = "redis" - node_type = "cache.m3.medium" + node_type = "cache.t2.medium" num_cache_nodes = 1 port = 6379 } @@ -1219,7 +1143,7 @@ resource "aws_elasticache_cluster" "test" { cluster_id = "%[1]s" engine = "memcached" engine_version = "%[2]s" - node_type = "cache.m3.medium" + node_type = "cache.t2.medium" num_cache_nodes = 1 port = 11211 } @@ -1233,7 +1157,7 @@ resource "aws_elasticache_cluster" "test" { cluster_id = "%[1]s" engine = "redis" engine_version = "%[2]s" - node_type = "cache.m3.medium" + node_type = "cache.t2.medium" num_cache_nodes = 1 port = 6379 } @@ -1272,23 +1196,13 @@ resource "aws_elasticache_cluster" "test" { apply_immediately = true cluster_id = "%[1]s" engine = "redis" - node_type = "cache.m3.medium" + node_type = "cache.t2.medium" num_cache_nodes = %[2]d port = 6379 } `, rName, numCacheNodes) } -func testAccAWSElasticacheClusterConfig_ReplicationGroupID_InvalidAttribute(rName, attrName, attrValue string) string { - return fmt.Sprintf(` -resource "aws_elasticache_cluster" "test" { - cluster_id = "%[1]s" - replication_group_id = "non-existent-id" - %[2]s = "%[3]s" -} -`, rName, attrName, attrValue) -} - func testAccAWSElasticacheClusterConfig_ReplicationGroupID_AvailabilityZone(rName string) string { return fmt.Sprintf(` data "aws_availability_zones" "available" { @@ -1303,7 +1217,7 @@ data "aws_availability_zones" "available" { resource "aws_elasticache_replication_group" "test" { replication_group_description = "Terraform Acceptance Testing" replication_group_id = "%[1]s" - node_type = "cache.m3.medium" + node_type = "cache.t2.medium" number_cache_clusters = 1 port = 6379 @@ -1325,7 +1239,7 @@ func testAccAWSElasticacheClusterConfig_ReplicationGroupID_Replica(rName string, resource "aws_elasticache_replication_group" "test" { replication_group_description = "Terraform Acceptance Testing" replication_group_id = "%[1]s" - node_type = "cache.m3.medium" + node_type = "cache.t2.medium" number_cache_clusters = 1 port = 6379 diff --git a/aws/resource_aws_elasticache_replication_group_test.go b/aws/resource_aws_elasticache_replication_group_test.go index f91b1a147449..ce2a4b509167 100644 --- a/aws/resource_aws_elasticache_replication_group_test.go +++ b/aws/resource_aws_elasticache_replication_group_test.go @@ -977,7 +977,7 @@ resource "aws_elasticache_replication_group" "test" { apply_immediately = true node_type = "cache.t3.small" number_cache_clusters = 2 - parameter_group_name = "${aws_elasticache_parameter_group.test.*.name[%[2]d]}" + parameter_group_name = aws_elasticache_parameter_group.test.*.name[%[2]d] replication_group_description = "test description" replication_group_id = %[1]q } @@ -1128,7 +1128,7 @@ resource "aws_subnet" "test2" { resource "aws_elasticache_subnet_group" "test" { name = "tf-test-cache-subnet-%03d" description = "tf-test-cache-subnet-group-descr" - subnet_ids = [ + subnet_ids = [ aws_subnet.test.id, aws_subnet.test2.id, ] @@ -1164,9 +1164,7 @@ resource "aws_elasticache_replication_group" "test" { var testAccAWSElasticacheReplicationGroupRedisClusterInVPCConfig = fmt.Sprintf(` data "aws_availability_zones" "available" { - # InvalidParameterValue: Specified node type cache.m3.medium is not available in AZ us-east-1b. - exclude_zone_ids = ["use1-az1"] - state = "available" + state = "available" filter { name = "opt-in-status" @@ -1193,8 +1191,8 @@ resource "aws_subnet" "test" { } resource "aws_subnet" "test2" { - vpc_id = aws_vpc.test.id - cidr_block = "192.168.16.0/20" + vpc_id = aws_vpc.test.id + cidr_block = "192.168.16.0/20" availability_zone = data.aws_availability_zones.available.names[1] tags = { @@ -1205,7 +1203,7 @@ resource "aws_subnet" "test2" { resource "aws_elasticache_subnet_group" "test" { name = "tf-test-cache-subnet-%03d" description = "tf-test-cache-subnet-group-descr" - subnet_ids = [ + subnet_ids = [ aws_subnet.test.id, aws_subnet.test2.id, ] @@ -1227,7 +1225,7 @@ resource "aws_security_group" "test" { resource "aws_elasticache_replication_group" "test" { replication_group_id = "tf-%s" replication_group_description = "test description" - node_type = "cache.m3.medium" + node_type = "cache.t3.medium" number_cache_clusters = "2" port = 6379 subnet_group_name = aws_elasticache_subnet_group.test.name @@ -1611,9 +1609,7 @@ resource "aws_elasticache_replication_group" "test" { func testAccAWSElasticacheReplicationGroupConfig_NumberCacheClusters(rName string, numberCacheClusters int, autoFailover bool) string { return fmt.Sprintf(` data "aws_availability_zones" "available" { - # InvalidParameterValue: Specified node type cache.m3.medium is not available in AZ us-east-1b. - exclude_zone_ids = ["use1-az1"] - state = "available" + state = "available" filter { name = "opt-in-status" @@ -1649,7 +1645,7 @@ resource "aws_elasticache_subnet_group" "test" { resource "aws_elasticache_replication_group" "test" { # InvalidParameterCombination: Automatic failover is not supported for T1 and T2 cache node types. automatic_failover_enabled = %[2]t - node_type = "cache.m3.medium" + node_type = "cache.t3.medium" number_cache_clusters = %[3]d replication_group_id = "%[1]s" replication_group_description = "Terraform Acceptance Testing - number_cache_clusters" diff --git a/aws/resource_aws_elasticache_subnet_group_test.go b/aws/resource_aws_elasticache_subnet_group_test.go index 46e9bb654560..bec50af3c3d4 100644 --- a/aws/resource_aws_elasticache_subnet_group_test.go +++ b/aws/resource_aws_elasticache_subnet_group_test.go @@ -212,7 +212,7 @@ resource "aws_vpc" "foo" { cidr_block = "10.0.0.0/16" tags = { - Name = "terraform-testacc-elasticache-subnet-group-update" + Name = "terraform-testacc-elasticache-subnet-group-update" } } @@ -239,7 +239,7 @@ resource "aws_subnet" "test" { resource "aws_elasticache_subnet_group" "test" { name = "tf-test-cache-subnet-%03d" description = "tf-test-cache-subnet-group-descr-edited" - subnet_ids = [ + subnet_ids = [ aws_subnet.foo.id, aws_subnet.test.id, ] diff --git a/aws/resource_aws_elb_attachment_test.go b/aws/resource_aws_elb_attachment_test.go index 34f63a87ca0b..fc08f91a3661 100644 --- a/aws/resource_aws_elb_attachment_test.go +++ b/aws/resource_aws_elb_attachment_test.go @@ -149,7 +149,7 @@ resource "aws_elb" "bar" { resource "aws_instance" "foo1" { ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id - instance_type = "t1.micro" + instance_type = "t2.micro" } resource "aws_elb_attachment" "foo1" { @@ -188,12 +188,12 @@ resource "aws_elb" "bar" { resource "aws_instance" "foo1" { ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id - instance_type = "t1.micro" + instance_type = "t2.micro" } resource "aws_instance" "foo2" { ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id - instance_type = "t1.micro" + instance_type = "t2.micro" } resource "aws_elb_attachment" "foo1" { @@ -237,12 +237,12 @@ resource "aws_elb" "bar" { resource "aws_instance" "foo1" { ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id - instance_type = "t1.micro" + instance_type = "t2.micro" } resource "aws_instance" "foo2" { ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id - instance_type = "t1.micro" + instance_type = "t2.micro" } resource "aws_elb_attachment" "foo1" { diff --git a/aws/resource_aws_elb_test.go b/aws/resource_aws_elb_test.go index 18e20e44b5c4..227c61a09076 100644 --- a/aws/resource_aws_elb_test.go +++ b/aws/resource_aws_elb_test.go @@ -1217,7 +1217,7 @@ data "aws_availability_zones" "available" { } resource "aws_elb" "test" { - name = "%s" + name = "%s" availability_zones = [data.aws_availability_zones.available.names[0], data.aws_availability_zones.available.names[1], data.aws_availability_zones.available.names[2]] listener { @@ -1355,7 +1355,7 @@ data "aws_availability_zones" "available" { } resource "aws_elb" "test" { - name_prefix = "test-" + name_prefix = "test-" availability_zones = [data.aws_availability_zones.available.names[0], data.aws_availability_zones.available.names[1], data.aws_availability_zones.available.names[2]] listener { @@ -1662,7 +1662,7 @@ resource "aws_elb" "test" { lb_protocol = "http" } - connection_draining = true + connection_draining = true connection_draining_timeout = 400 } ` @@ -1687,7 +1687,7 @@ resource "aws_elb" "test" { lb_protocol = "http" } - connection_draining = true + connection_draining = true connection_draining_timeout = 600 } ` diff --git a/aws/resource_aws_emr_cluster_test.go b/aws/resource_aws_emr_cluster_test.go index aa935c68c695..b396f929d48f 100644 --- a/aws/resource_aws_emr_cluster_test.go +++ b/aws/resource_aws_emr_cluster_test.go @@ -1650,10 +1650,10 @@ func testAccAWSEmrClusterConfig_bootstrap(r string) string { testAccAWSEmrClusterConfigBootstrapActionBucket(r), fmt.Sprintf(` resource "aws_emr_cluster" "test" { - name = "%[1]s" - release_label = "emr-5.0.0" - applications = ["Hadoop", "Hive"] - log_uri = "s3n://terraform/testlog/" + name = "%[1]s" + release_label = "emr-5.0.0" + applications = ["Hadoop", "Hive"] + log_uri = "s3n://terraform/testlog/" master_instance_group { instance_type = "c4.large" @@ -1665,7 +1665,7 @@ resource "aws_emr_cluster" "test" { } service_role = aws_iam_role.emr_service.arn - depends_on = [ + depends_on = [ aws_route_table_association.test, aws_iam_role_policy_attachment.emr_service, aws_iam_role_policy_attachment.emr_instance_profile, @@ -1712,10 +1712,10 @@ func testAccAWSEmrClusterConfig_bootstrapAdd(r string) string { testAccAWSEmrClusterConfigBootstrapActionBucket(r), fmt.Sprintf(` resource "aws_emr_cluster" "test" { - name = "%[1]s" - release_label = "emr-5.0.0" - applications = ["Hadoop", "Hive"] - log_uri = "s3n://terraform/testlog/" + name = "%[1]s" + release_label = "emr-5.0.0" + applications = ["Hadoop", "Hive"] + log_uri = "s3n://terraform/testlog/" master_instance_group { instance_type = "c4.large" @@ -1727,7 +1727,7 @@ resource "aws_emr_cluster" "test" { } service_role = aws_iam_role.emr_service.arn - depends_on = [ + depends_on = [ aws_route_table_association.test, aws_iam_role_policy_attachment.emr_service, aws_iam_role_policy_attachment.emr_instance_profile, @@ -1780,10 +1780,10 @@ func testAccAWSEmrClusterConfig_bootstrapReorder(r string) string { testAccAWSEmrClusterConfigBootstrapActionBucket(r), fmt.Sprintf(` resource "aws_emr_cluster" "test" { - name = "%[1]s" - release_label = "emr-5.0.0" - applications = ["Hadoop", "Hive"] - log_uri = "s3n://terraform/testlog/" + name = "%[1]s" + release_label = "emr-5.0.0" + applications = ["Hadoop", "Hive"] + log_uri = "s3n://terraform/testlog/" master_instance_group { instance_type = "c4.large" @@ -1795,7 +1795,7 @@ resource "aws_emr_cluster" "test" { } service_role = aws_iam_role.emr_service.arn - depends_on = [ + depends_on = [ aws_route_table_association.test, aws_iam_role_policy_attachment.emr_service, aws_iam_role_policy_attachment.emr_instance_profile, @@ -3424,16 +3424,16 @@ resource "aws_emr_cluster" "tf-test-cluster" { master_instance_group { instance_type = "m4.large" - ebs_config { + ebs_config { size = 32 type = "gp2" volumes_per_instance = %[2]d } - ebs_config { - size = 50 - type = "gp2" - volumes_per_instance = %[2]d - } + ebs_config { + size = 50 + type = "gp2" + volumes_per_instance = %[2]d + } } core_instance_group { instance_count = 1 @@ -3458,18 +3458,18 @@ func testAccAWSEmrClusterConfigInstanceFleets(r string) string { testAccAWSEmrClusterConfigBootstrapActionBucket(r), fmt.Sprintf(` resource "aws_emr_cluster" "tf-test-cluster" { - name = "%[1]s" - release_label = "emr-5.30.1" - applications = ["Hadoop", "Hive"] - log_uri = "s3n://terraform/testlog/" - - master_instance_fleet { - instance_type_configs { - instance_type = "m3.xlarge" - } - - target_on_demand_capacity = 1 + name = "%[1]s" + release_label = "emr-5.30.1" + applications = ["Hadoop", "Hive"] + log_uri = "s3n://terraform/testlog/" + + master_instance_fleet { + instance_type_configs { + instance_type = "m3.xlarge" } + + target_on_demand_capacity = 1 + } core_instance_fleet { instance_type_configs { bid_price_as_percentage_of_on_demand_price = 80 @@ -3503,7 +3503,7 @@ resource "aws_emr_cluster" "tf-test-cluster" { } launch_specifications { spot_specification { - allocation_strategy = "capacity-optimized" + allocation_strategy = "capacity-optimized" block_duration_minutes = 0 timeout_action = "SWITCH_TO_ON_DEMAND" timeout_duration_minutes = 10 @@ -3514,7 +3514,7 @@ resource "aws_emr_cluster" "tf-test-cluster" { target_spot_capacity = 2 } service_role = aws_iam_role.emr_service.arn - depends_on = [ + depends_on = [ aws_route_table_association.test, aws_iam_role_policy_attachment.emr_service, aws_iam_role_policy_attachment.emr_instance_profile, @@ -3544,20 +3544,20 @@ func testAccAWSEmrClusterConfigInstanceFleetsMasterOnly(r string) string { testAccAWSEmrClusterConfigBootstrapActionBucket(r), fmt.Sprintf(` resource "aws_emr_cluster" "tf-test-cluster" { - name = "%[1]s" - release_label = "emr-5.30.1" - applications = ["Hadoop", "Hive"] - log_uri = "s3n://terraform/testlog/" - - master_instance_fleet { - instance_type_configs { - instance_type = "m3.xlarge" - } - - target_on_demand_capacity = 1 + name = "%[1]s" + release_label = "emr-5.30.1" + applications = ["Hadoop", "Hive"] + log_uri = "s3n://terraform/testlog/" + + master_instance_fleet { + instance_type_configs { + instance_type = "m3.xlarge" } + + target_on_demand_capacity = 1 + } service_role = aws_iam_role.emr_service.arn - depends_on = [ + depends_on = [ aws_route_table_association.test, aws_iam_role_policy_attachment.emr_service, aws_iam_role_policy_attachment.emr_instance_profile, diff --git a/aws/resource_aws_emr_instance_fleet_test.go b/aws/resource_aws_emr_instance_fleet_test.go index 8086c88a49dc..c192dbe0e464 100644 --- a/aws/resource_aws_emr_instance_fleet_test.go +++ b/aws/resource_aws_emr_instance_fleet_test.go @@ -412,113 +412,113 @@ resource "aws_emr_cluster" "test" { func testAccAWSEmrInstanceFleetConfig(r string) string { return fmt.Sprintf(testAccAWSEmrInstanceFleetBase+` resource "aws_emr_instance_fleet" "task" { - cluster_id = aws_emr_cluster.test.id - instance_type_configs { - instance_type = "m3.xlarge" - weighted_capacity = 1 - } - launch_specifications { - on_demand_specification { - allocation_strategy = "lowest-price" - } - } - name = "emr_instance_fleet_%[1]s" - target_on_demand_capacity = 1 - target_spot_capacity = 0 + cluster_id = aws_emr_cluster.test.id + instance_type_configs { + instance_type = "m3.xlarge" + weighted_capacity = 1 + } + launch_specifications { + on_demand_specification { + allocation_strategy = "lowest-price" } + } + name = "emr_instance_fleet_%[1]s" + target_on_demand_capacity = 1 + target_spot_capacity = 0 +} `, r) } func testAccAWSEmrInstanceFleetConfigZeroCount(r string) string { return fmt.Sprintf(testAccAWSEmrInstanceFleetBase+` resource "aws_emr_instance_fleet" "task" { - cluster_id = aws_emr_cluster.test.id - instance_type_configs { - instance_type = "m3.xlarge" - weighted_capacity = 1 - } - launch_specifications { - on_demand_specification { - allocation_strategy = "lowest-price" - } - } - name = "emr_instance_fleet_%[1]s" - target_on_demand_capacity = 0 - target_spot_capacity = 0 + cluster_id = aws_emr_cluster.test.id + instance_type_configs { + instance_type = "m3.xlarge" + weighted_capacity = 1 + } + launch_specifications { + on_demand_specification { + allocation_strategy = "lowest-price" } + } + name = "emr_instance_fleet_%[1]s" + target_on_demand_capacity = 0 + target_spot_capacity = 0 +} `, r) } func testAccAWSEmrInstanceFleetConfigEbsBasic(r string) string { return fmt.Sprintf(testAccAWSEmrInstanceFleetBase+` resource "aws_emr_instance_fleet" "task" { - cluster_id = aws_emr_cluster.test.id - instance_type_configs { - bid_price_as_percentage_of_on_demand_price = 100 - ebs_config { - size = 10 - type = "gp2" - volumes_per_instance = 1 - } - instance_type = "m4.xlarge" - weighted_capacity = 1 - } - launch_specifications { - spot_specification { - allocation_strategy = "capacity-optimized" - block_duration_minutes = 0 - timeout_action = "SWITCH_TO_ON_DEMAND" - timeout_duration_minutes = 10 - } - } - name = "emr_instance_fleet_%[1]s" - target_on_demand_capacity = 0 - target_spot_capacity = 1 + cluster_id = aws_emr_cluster.test.id + instance_type_configs { + bid_price_as_percentage_of_on_demand_price = 100 + ebs_config { + size = 10 + type = "gp2" + volumes_per_instance = 1 + } + instance_type = "m4.xlarge" + weighted_capacity = 1 + } + launch_specifications { + spot_specification { + allocation_strategy = "capacity-optimized" + block_duration_minutes = 0 + timeout_action = "SWITCH_TO_ON_DEMAND" + timeout_duration_minutes = 10 } + } + name = "emr_instance_fleet_%[1]s" + target_on_demand_capacity = 0 + target_spot_capacity = 1 +} `, r) } func testAccAWSEmrInstanceFleetConfigFull(r string) string { return fmt.Sprintf(testAccAWSEmrInstanceFleetBase+` resource "aws_emr_instance_fleet" "task" { - cluster_id = aws_emr_cluster.test.id - instance_type_configs { - bid_price_as_percentage_of_on_demand_price = 100 - ebs_config { - size = 10 - type = "gp2" - volumes_per_instance = 1 - } - ebs_config { - size = 20 - type = "gp2" - volumes_per_instance = 2 - } - instance_type = "m4.xlarge" - weighted_capacity = 1 - } - instance_type_configs { - bid_price_as_percentage_of_on_demand_price = 80 - ebs_config { - size = 10 - type = "gp2" - volumes_per_instance = 1 - } - instance_type = "m4.2xlarge" - weighted_capacity = 2 - } - launch_specifications { - spot_specification { - allocation_strategy = "capacity-optimized" - block_duration_minutes = 0 - timeout_action = "SWITCH_TO_ON_DEMAND" - timeout_duration_minutes = 10 - } - } - - name = "emr_instance_fleet_%[1]s" - target_on_demand_capacity = 2 - target_spot_capacity = 2 + cluster_id = aws_emr_cluster.test.id + instance_type_configs { + bid_price_as_percentage_of_on_demand_price = 100 + ebs_config { + size = 10 + type = "gp2" + volumes_per_instance = 1 + } + ebs_config { + size = 20 + type = "gp2" + volumes_per_instance = 2 } + instance_type = "m4.xlarge" + weighted_capacity = 1 + } + instance_type_configs { + bid_price_as_percentage_of_on_demand_price = 80 + ebs_config { + size = 10 + type = "gp2" + volumes_per_instance = 1 + } + instance_type = "m4.2xlarge" + weighted_capacity = 2 + } + launch_specifications { + spot_specification { + allocation_strategy = "capacity-optimized" + block_duration_minutes = 0 + timeout_action = "SWITCH_TO_ON_DEMAND" + timeout_duration_minutes = 10 + } + } + + name = "emr_instance_fleet_%[1]s" + target_on_demand_capacity = 2 + target_spot_capacity = 2 +} `, r) } diff --git a/aws/resource_aws_emr_instance_group_test.go b/aws/resource_aws_emr_instance_group_test.go index 74191166d3f4..8d014faf611c 100644 --- a/aws/resource_aws_emr_instance_group_test.go +++ b/aws/resource_aws_emr_instance_group_test.go @@ -361,10 +361,10 @@ resource "aws_security_group" "allow_all" { vpc_id = aws_vpc.main.id ingress { - from_port = 0 - to_port = 0 - protocol = "-1" - self = true + from_port = 0 + to_port = 0 + protocol = "-1" + self = true } egress { @@ -432,7 +432,7 @@ resource "aws_emr_cluster" "tf-test-cluster" { } core_instance_group { - instance_type = "c4.large" + instance_type = "c4.large" instance_count = 2 } @@ -559,7 +559,7 @@ EOT } resource "aws_iam_instance_profile" "emr_profile" { - name = "emr_profile_%[1]d" + name = "emr_profile_%[1]d" role = aws_iam_role.iam_emr_profile_role.name } @@ -618,7 +618,7 @@ data "aws_iam_policy_document" "emr-autoscaling-role-policy" { actions = ["sts:AssumeRole"] principals { type = "Service" - identifiers = ["elasticmapreduce.${data.aws_partition.current.dns_suffix}","application-autoscaling.${data.aws_partition.current.dns_suffix}"] + identifiers = ["elasticmapreduce.${data.aws_partition.current.dns_suffix}", "application-autoscaling.${data.aws_partition.current.dns_suffix}"] } } } @@ -656,7 +656,7 @@ resource "aws_emr_instance_group" "task" { cluster_id = aws_emr_cluster.tf-test-cluster.id instance_count = 1 instance_type = "c4.large" - configurations_json = < Date: Tue, 8 Sep 2020 14:55:42 -0700 Subject: [PATCH 3/8] Updates Terraform configurations in acceptance tests for resource names starting with "f" and "g" --- .github/workflows/acctest-terraform-lint.yml | 6 ++++- aws/resource_aws_flow_log_test.go | 1 + ..._aws_globalaccelerator_accelerator_test.go | 3 ++- ...s_globalaccelerator_endpoint_group_test.go | 20 +++++++------- aws/resource_aws_glue_connection_test.go | 6 ++--- ...rce_aws_glue_user_defined_function_test.go | 12 ++++----- ...s_guardduty_publishing_destination_test.go | 26 +++++++++---------- 7 files changed, 40 insertions(+), 34 deletions(-) diff --git a/.github/workflows/acctest-terraform-lint.yml b/.github/workflows/acctest-terraform-lint.yml index f30f985232e7..36066a720d2e 100644 --- a/.github/workflows/acctest-terraform-lint.yml +++ b/.github/workflows/acctest-terraform-lint.yml @@ -7,7 +7,7 @@ on: pull_request: paths: - .github/workflows/acctest-terraform-lint.yml - - aws/resource_aws_[a-d]*_test.go + - aws/resource_aws_[a-g]*_test.go env: GO_VERSION: "1.14" @@ -41,6 +41,8 @@ jobs: -o -name 'resource_aws_c*_test.go' \ -o -name 'resource_aws_d*_test.go' \ -o -name 'resource_aws_e*_test.go' \ + -o -name 'resource_aws_f*_test.go' \ + -o -name 'resource_aws_g*_test.go' \ \) \ | sort -u \ | grep -v resource_aws_apigatewayv2_domain_name_test.go \ @@ -80,6 +82,8 @@ jobs: -o -name 'resource_aws_c*_test.go' \ -o -name 'resource_aws_d*_test.go' \ -o -name 'resource_aws_e*_test.go' \ + -o -name 'resource_aws_f*_test.go' \ + -o -name 'resource_aws_g*_test.go' \ \) \ | sort -u \ | grep -v resource_aws_apigatewayv2_domain_name_test.go \ diff --git a/aws/resource_aws_flow_log_test.go b/aws/resource_aws_flow_log_test.go index 5b2f858e79f5..6a0526c4ad55 100644 --- a/aws/resource_aws_flow_log_test.go +++ b/aws/resource_aws_flow_log_test.go @@ -591,6 +591,7 @@ EOF resource "aws_cloudwatch_log_group" "test" { name = %[1]q } + resource "aws_s3_bucket" "test" { bucket = %[1]q force_destroy = true diff --git a/aws/resource_aws_globalaccelerator_accelerator_test.go b/aws/resource_aws_globalaccelerator_accelerator_test.go index f5c499803d02..4545a9183caf 100644 --- a/aws/resource_aws_globalaccelerator_accelerator_test.go +++ b/aws/resource_aws_globalaccelerator_accelerator_test.go @@ -401,7 +401,8 @@ resource "aws_globalaccelerator_accelerator" "example" { enabled = %t tags = { - Name = "%[1]s" + Name = "%[1]s" + %[3]s = "%[4]s" } } diff --git a/aws/resource_aws_globalaccelerator_endpoint_group_test.go b/aws/resource_aws_globalaccelerator_endpoint_group_test.go index 078359cd62b5..9c81b7ac6f7c 100644 --- a/aws/resource_aws_globalaccelerator_endpoint_group_test.go +++ b/aws/resource_aws_globalaccelerator_endpoint_group_test.go @@ -483,9 +483,9 @@ resource "aws_internet_gateway" "test" { } resource "aws_instance" "test" { - ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id - instance_type = data.aws_ec2_instance_type_offering.available.instance_type - subnet_id = aws_subnet.test.id + ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id + instance_type = data.aws_ec2_instance_type_offering.available.instance_type + subnet_id = aws_subnet.test.id tags = { Name = %[1]q @@ -513,7 +513,7 @@ resource "aws_globalaccelerator_endpoint_group" "test" { endpoint_configuration { endpoint_id = aws_instance.test.id - weight = 20 + weight = 20 client_ip_preservation_enabled = true } @@ -574,11 +574,11 @@ func testAccGlobalAcceleratorEndpointGroup_tcp(rInt int) string { resource "aws_globalaccelerator_accelerator" "example" { name = "tf-%d" ip_address_type = "IPV4" - enabled = false + enabled = false } resource "aws_globalaccelerator_listener" "example" { - accelerator_arn = "${aws_globalaccelerator_accelerator.example.id}" + accelerator_arn = aws_globalaccelerator_accelerator.example.id protocol = "TCP" port_range { @@ -592,14 +592,14 @@ data "aws_region" "current" {} resource "aws_eip" "example" {} resource "aws_globalaccelerator_endpoint_group" "example" { - listener_arn = "${aws_globalaccelerator_listener.example.id}" + listener_arn = aws_globalaccelerator_listener.example.id endpoint_configuration { - endpoint_id = "${aws_eip.example.id}" - weight = 10 + endpoint_id = aws_eip.example.id + weight = 10 } - endpoint_group_region = "${data.aws_region.current.name}" + endpoint_group_region = data.aws_region.current.name health_check_interval_seconds = 30 health_check_port = 1234 health_check_protocol = "TCP" diff --git a/aws/resource_aws_glue_connection_test.go b/aws/resource_aws_glue_connection_test.go index 46feea4a189f..17f9170e88d4 100644 --- a/aws/resource_aws_glue_connection_test.go +++ b/aws/resource_aws_glue_connection_test.go @@ -451,7 +451,7 @@ resource "aws_subnet" "test" { resource "aws_db_subnet_group" "test" { name = "%[1]s" - subnet_ids = [aws_subnet.test.0.id, aws_subnet.test.1.id] + subnet_ids = aws_subnet.test[*].id } resource "aws_rds_cluster" "test" { @@ -483,9 +483,9 @@ resource "aws_glue_connection" "test" { name = "%[1]s" physical_connection_requirements { - availability_zone = aws_subnet.test.0.availability_zone + availability_zone = aws_subnet.test[0].availability_zone security_group_id_list = [aws_security_group.test.id] - subnet_id = aws_subnet.test.0.id + subnet_id = aws_subnet.test[0].id } } `, rName) diff --git a/aws/resource_aws_glue_user_defined_function_test.go b/aws/resource_aws_glue_user_defined_function_test.go index 4b1e58963704..c9e83ce8b836 100644 --- a/aws/resource_aws_glue_user_defined_function_test.go +++ b/aws/resource_aws_glue_user_defined_function_test.go @@ -214,8 +214,8 @@ resource "aws_glue_user_defined_function" "test" { owner_type = "GROUP" resource_uris { - resource_type = "ARCHIVE" - uri = %[1]q + resource_type = "ARCHIVE" + uri = %[1]q } } `, rName) @@ -236,13 +236,13 @@ resource "aws_glue_user_defined_function" "test" { owner_type = "GROUP" resource_uris { - resource_type = "ARCHIVE" - uri = %[1]q + resource_type = "ARCHIVE" + uri = %[1]q } resource_uris { - resource_type = "JAR" - uri = %[1]q + resource_type = "JAR" + uri = %[1]q } } `, rName) diff --git a/aws/resource_aws_guardduty_publishing_destination_test.go b/aws/resource_aws_guardduty_publishing_destination_test.go index c012f1864893..559b17f3fe25 100644 --- a/aws/resource_aws_guardduty_publishing_destination_test.go +++ b/aws/resource_aws_guardduty_publishing_destination_test.go @@ -156,7 +156,7 @@ data "aws_iam_policy_document" "bucket_pol" { statement { sid = "Allow GetBucketLocation" actions = [ - "s3:GetBucketLocation" + "s3:GetBucketLocation" ] resources = [ @@ -200,7 +200,7 @@ data "aws_iam_policy_document" "kms_pol" { principals { type = "AWS" - identifiers = [ "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root" ] + identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"] } } @@ -211,8 +211,8 @@ resource "aws_guardduty_detector" "test_gd" { } resource "aws_s3_bucket" "gd_bucket" { - bucket = %[1]q - acl = "private" + bucket = %[1]q + acl = "private" force_destroy = true } @@ -222,19 +222,19 @@ resource "aws_s3_bucket_policy" "gd_bucket_policy" { } resource "aws_kms_key" "gd_key" { - description = "Temporary key for AccTest of TF" + description = "Temporary key for AccTest of TF" deletion_window_in_days = 7 - policy = data.aws_iam_policy_document.kms_pol.json + policy = data.aws_iam_policy_document.kms_pol.json } resource "aws_guardduty_publishing_destination" "test" { - detector_id = aws_guardduty_detector.test_gd.id - destination_arn = aws_s3_bucket.gd_bucket.arn - kms_key_arn = aws_kms_key.gd_key.arn - - depends_on = [ - aws_s3_bucket_policy.gd_bucket_policy, - ] + detector_id = aws_guardduty_detector.test_gd.id + destination_arn = aws_s3_bucket.gd_bucket.arn + kms_key_arn = aws_kms_key.gd_key.arn + + depends_on = [ + aws_s3_bucket_policy.gd_bucket_policy, + ] }`, bucketName) } From 170f2e12c5e3dcb34988c715e692d7f7e415c03f Mon Sep 17 00:00:00 2001 From: Graham Davison Date: Wed, 9 Sep 2020 15:22:13 -0700 Subject: [PATCH 4/8] Fixes EIP tests and returns error when setting tags on EIP in EC2 Classic --- aws/data_source_aws_outposts_outposts_test.go | 2 +- aws/resource_aws_eip.go | 32 ++- aws/resource_aws_eip_test.go | 262 +++++++----------- aws/resource_aws_instance_test.go | 22 ++ website/docs/r/eip.html.markdown | 3 +- 5 files changed, 139 insertions(+), 182 deletions(-) diff --git a/aws/data_source_aws_outposts_outposts_test.go b/aws/data_source_aws_outposts_outposts_test.go index ee9920c2a1ac..8c64f4dd36e4 100644 --- a/aws/data_source_aws_outposts_outposts_test.go +++ b/aws/data_source_aws_outposts_outposts_test.go @@ -63,7 +63,7 @@ func testAccPreCheckAWSOutpostsOutposts(t *testing.T) { // Ensure there is at least one Outpost if output == nil || len(output.Outposts) == 0 { - t.Skip("skipping since no Outposts Outpost found") + t.Skip("skipping since no Outposts found") } } diff --git a/aws/resource_aws_eip.go b/aws/resource_aws_eip.go index db52419b99a6..837f05a559e8 100644 --- a/aws/resource_aws_eip.go +++ b/aws/resource_aws_eip.go @@ -119,7 +119,7 @@ func resourceAwsEipCreate(d *schema.ResourceData, meta interface{}) error { // By default, we're not in a VPC domainOpt := "" if v := d.Get("vpc"); v != nil && v.(bool) { - domainOpt = "vpc" + domainOpt = ec2.DomainTypeVpc } allocOpts := &ec2.AllocateAddressInput{ @@ -148,7 +148,7 @@ func resourceAwsEipCreate(d *schema.ResourceData, meta interface{}) error { // if we're in a VPC we need to save the ID as such, otherwise // it defaults to using the public IP log.Printf("[DEBUG] EIP Allocate: %#v", allocResp) - if d.Get("domain").(string) == "vpc" { + if d.Get("domain").(string) == ec2.DomainTypeVpc { d.SetId(*allocResp.AllocationId) } else { d.SetId(*allocResp.PublicIp) @@ -157,6 +157,9 @@ func resourceAwsEipCreate(d *schema.ResourceData, meta interface{}) error { log.Printf("[INFO] EIP ID: %s (domain: %v)", d.Id(), *allocResp.Domain) if v := d.Get("tags").(map[string]interface{}); len(v) > 0 { + if d.Get("domain").(string) == ec2.DomainTypeStandard { + return fmt.Errorf("tags can not be set for an EIP in EC2 Classic") + } if err := keyvaluetags.Ec2CreateTags(ec2conn, d.Id(), v); err != nil { return fmt.Errorf("error adding tags: %s", err) } @@ -174,7 +177,7 @@ func resourceAwsEipRead(d *schema.ResourceData, meta interface{}) error { req := &ec2.DescribeAddressesInput{} - if domain == "vpc" { + if domain == ec2.DomainTypeVpc { req.AllocationIds = []*string{aws.String(id)} } else { req.PublicIps = []*string{aws.String(id)} @@ -226,7 +229,7 @@ func resourceAwsEipRead(d *schema.ResourceData, meta interface{}) error { // In the case that AWS returns more EIPs than we intend it to, we loop // over the returned addresses to see if it's in the list of results for _, addr := range describeAddresses.Addresses { - if (domain == "vpc" && aws.StringValue(addr.AllocationId) == id) || aws.StringValue(addr.PublicIp) == id { + if (domain == ec2.DomainTypeVpc && aws.StringValue(addr.AllocationId) == id) || aws.StringValue(addr.PublicIp) == id { address = addr break } @@ -278,14 +281,14 @@ func resourceAwsEipRead(d *schema.ResourceData, meta interface{}) error { // On import (domain never set, which it must've been if we created), // set the 'vpc' attribute depending on if we're in a VPC. if address.Domain != nil { - d.Set("vpc", *address.Domain == "vpc") + d.Set("vpc", *address.Domain == ec2.DomainTypeVpc) } d.Set("domain", address.Domain) // Force ID to be an Allocation ID if we're on a VPC // This allows users to import the EIP based on the IP if they are in a VPC - if *address.Domain == "vpc" && net.ParseIP(id) != nil { + if *address.Domain == ec2.DomainTypeVpc && net.ParseIP(id) != nil { log.Printf("[DEBUG] Re-assigning EIP ID (%s) to it's Allocation ID (%s)", d.Id(), *address.AllocationId) d.SetId(*address.AllocationId) } @@ -338,7 +341,7 @@ func resourceAwsEipUpdate(d *schema.ResourceData, meta interface{}) error { } // more unique ID conditionals - if domain == "vpc" { + if domain == ec2.DomainTypeVpc { var privateIpAddress *string if v := d.Get("associate_with_private_ip").(string); v != "" { privateIpAddress = aws.String(v) @@ -376,6 +379,9 @@ func resourceAwsEipUpdate(d *schema.ResourceData, meta interface{}) error { } if d.HasChange("tags") && !d.IsNewResource() { + if d.Get("domain").(string) == ec2.DomainTypeStandard { + return fmt.Errorf("tags can not be set for an EIP in EC2 Classic") + } o, n := d.GetChange("tags") if err := keyvaluetags.Ec2UpdateTags(ec2conn, d.Id(), o, n); err != nil { return fmt.Errorf("error updating EIP (%s) tags: %s", d.Id(), err) @@ -407,12 +413,12 @@ func resourceAwsEipDelete(d *schema.ResourceData, meta interface{}) error { var input *ec2.ReleaseAddressInput switch domain { - case "vpc": + case ec2.DomainTypeVpc: log.Printf("[DEBUG] EIP release (destroy) address allocation: %v", d.Id()) input = &ec2.ReleaseAddressInput{ AllocationId: aws.String(d.Id()), } - case "standard": + case ec2.DomainTypeStandard: log.Printf("[DEBUG] EIP release (destroy) address: %v", d.Id()) input = &ec2.ReleaseAddressInput{ PublicIp: aws.String(d.Id()), @@ -447,10 +453,10 @@ func resourceAwsEipDomain(d *schema.ResourceData) string { } else if strings.Contains(d.Id(), "eipalloc") { // We have to do this for backwards compatibility since TF 0.1 // didn't have the "domain" computed attribute. - return "vpc" + return ec2.DomainTypeVpc } - return "standard" + return ec2.DomainTypeStandard } func disassociateEip(d *schema.ResourceData, meta interface{}) error { @@ -458,7 +464,7 @@ func disassociateEip(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Disassociating EIP: %s", d.Id()) var err error switch resourceAwsEipDomain(d) { - case "vpc": + case ec2.DomainTypeVpc: associationID := d.Get("association_id").(string) if associationID == "" { // If assiciationID is empty, it means there's no association. @@ -468,7 +474,7 @@ func disassociateEip(d *schema.ResourceData, meta interface{}) error { _, err = ec2conn.DisassociateAddress(&ec2.DisassociateAddressInput{ AssociationId: aws.String(associationID), }) - case "standard": + case ec2.DomainTypeStandard: _, err = ec2conn.DisassociateAddress(&ec2.DisassociateAddressInput{ PublicIp: aws.String(d.Get("public_ip").(string)), }) diff --git a/aws/resource_aws_eip_test.go b/aws/resource_aws_eip_test.go index f2aa81b18f2b..75c76d237cce 100644 --- a/aws/resource_aws_eip_test.go +++ b/aws/resource_aws_eip_test.go @@ -16,7 +16,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) -// Implement a test sweeper for EIPs. // This will currently skip EIPs with associations, // although we depend on aws_vpc to potentially have // the majority of those associations removed. @@ -94,17 +93,18 @@ func TestAccAWSEIP_Ec2Classic(t *testing.T) { resourceName := "aws_eip.test" var conf ec2.Address - resource.ParallelTest(t, resource.TestCase{ + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t); testAccEC2ClassicPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAWSEIPDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSEIPInstanceEc2Classic, + Config: testAccAWSEIPInstanceEc2Classic(), Check: resource.ComposeTestCheckFunc( testAccCheckAWSEIPExists(resourceName, &conf), testAccCheckAWSEIPAttributes(&conf), testAccCheckAWSEIPPublicDNS(resourceName), + resource.TestCheckResourceAttr(resourceName, "domain", ec2.DomainTypeStandard), ), }, { @@ -132,6 +132,7 @@ func TestAccAWSEIP_basic(t *testing.T) { testAccCheckAWSEIPExists(resourceName, &conf), testAccCheckAWSEIPAttributes(&conf), testAccCheckAWSEIPPublicDNS(resourceName), + resource.TestCheckResourceAttr(resourceName, "domain", ec2.DomainTypeVpc), ), }, { @@ -154,7 +155,7 @@ func TestAccAWSEIP_instance(t *testing.T) { CheckDestroy: testAccCheckAWSEIPDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSEIPInstanceConfig, + Config: testAccAWSEIPInstanceConfig(), Check: resource.ComposeTestCheckFunc( testAccCheckAWSEIPExists(resourceName, &conf), testAccCheckAWSEIPAttributes(&conf), @@ -165,13 +166,6 @@ func TestAccAWSEIP_instance(t *testing.T) { ImportState: true, ImportStateVerify: true, }, - { - Config: testAccAWSEIPInstanceConfig2, - Check: resource.ComposeTestCheckFunc( - testAccCheckAWSEIPExists(resourceName, &conf), - testAccCheckAWSEIPAttributes(&conf), - ), - }, }, }) } @@ -193,6 +187,7 @@ func TestAccAWSEIP_networkInterface(t *testing.T) { testAccCheckAWSEIPAttributes(&conf), testAccCheckAWSEIPAssociated(&conf), testAccCheckAWSEIPPrivateDNS(resourceName), + resource.TestCheckResourceAttr(resourceName, "domain", ec2.DomainTypeVpc), ), }, { @@ -221,9 +216,12 @@ func TestAccAWSEIP_twoEIPsOneNetworkInterface(t *testing.T) { testAccCheckAWSEIPExists(resourceName, &one), testAccCheckAWSEIPAttributes(&one), testAccCheckAWSEIPAssociated(&one), + resource.TestCheckResourceAttr(resourceName, "domain", ec2.DomainTypeVpc), + testAccCheckAWSEIPExists(resourceName2, &two), testAccCheckAWSEIPAttributes(&two), testAccCheckAWSEIPAssociated(&two), + resource.TestCheckResourceAttr(resourceName2, "domain", ec2.DomainTypeVpc), ), }, { @@ -249,11 +247,12 @@ func TestAccAWSEIP_associated_user_private_ip(t *testing.T) { CheckDestroy: testAccCheckAWSEIPDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSEIPInstanceConfig_associated, + Config: testAccAWSEIPInstanceConfig_associated(), Check: resource.ComposeTestCheckFunc( testAccCheckAWSEIPExists(resourceName, &one), testAccCheckAWSEIPAttributes(&one), testAccCheckAWSEIPAssociated(&one), + resource.TestCheckResourceAttr(resourceName, "domain", ec2.DomainTypeVpc), ), }, { @@ -263,11 +262,12 @@ func TestAccAWSEIP_associated_user_private_ip(t *testing.T) { ImportStateVerifyIgnore: []string{"associate_with_private_ip"}, }, { - Config: testAccAWSEIPInstanceConfig_associated_switch, + Config: testAccAWSEIPInstanceConfig_associated_switch(), Check: resource.ComposeTestCheckFunc( testAccCheckAWSEIPExists(resourceName, &one), testAccCheckAWSEIPAttributes(&one), testAccCheckAWSEIPAssociated(&one), + resource.TestCheckResourceAttr(resourceName, "domain", ec2.DomainTypeVpc), ), }, }, @@ -316,7 +316,7 @@ func TestAccAWSEIP_disappears(t *testing.T) { Config: testAccAWSEIPConfig, Check: resource.ComposeTestCheckFunc( testAccCheckAWSEIPExists(resourceName, &conf), - testAccCheckAWSEIPDisappears(&conf), + testAccCheckResourceDisappears(testAccProvider, resourceAwsEip(), resourceName), ), ExpectNonEmptyPlan: true, }, @@ -324,7 +324,7 @@ func TestAccAWSEIP_disappears(t *testing.T) { }) } -func TestAccAWSEIPAssociate_notAssociated(t *testing.T) { +func TestAccAWSEIP_notAssociated(t *testing.T) { var conf ec2.Address resourceName := "aws_eip.test" @@ -335,7 +335,7 @@ func TestAccAWSEIPAssociate_notAssociated(t *testing.T) { CheckDestroy: testAccCheckAWSEIPDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSEIPAssociate_not_associated, + Config: testAccAWSEIPAssociate_not_associated(), Check: resource.ComposeTestCheckFunc( testAccCheckAWSEIPExists(resourceName, &conf), testAccCheckAWSEIPAttributes(&conf), @@ -347,7 +347,7 @@ func TestAccAWSEIPAssociate_notAssociated(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccAWSEIPAssociate_associated, + Config: testAccAWSEIPAssociate_associated(), Check: resource.ComposeTestCheckFunc( testAccCheckAWSEIPExists(resourceName, &conf), testAccCheckAWSEIPAttributes(&conf), @@ -358,23 +358,23 @@ func TestAccAWSEIPAssociate_notAssociated(t *testing.T) { }) } -func TestAccAWSEIP_tags(t *testing.T) { +func TestAccAWSEIP_tags_Vpc(t *testing.T) { var conf ec2.Address resourceName := "aws_eip.test" rName1 := fmt.Sprintf("%s-%d", t.Name(), acctest.RandInt()) rName2 := fmt.Sprintf("%s-%d", t.Name(), acctest.RandInt()) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - IDRefreshName: resourceName, - Providers: testAccProviders, - CheckDestroy: testAccCheckAWSEIPDestroy, + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSEIPDestroy, Steps: []resource.TestStep{ { Config: testAccAWSEIPConfig_tags(rName1, t.Name()), Check: resource.ComposeTestCheckFunc( testAccCheckAWSEIPExists(resourceName, &conf), testAccCheckAWSEIPAttributes(&conf), + resource.TestCheckResourceAttr(resourceName, "domain", ec2.DomainTypeVpc), resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), resource.TestCheckResourceAttr(resourceName, "tags.RandomName", rName1), resource.TestCheckResourceAttr(resourceName, "tags.TestName", t.Name()), @@ -399,6 +399,26 @@ func TestAccAWSEIP_tags(t *testing.T) { }) } +func TestAccAWSEIP_tags_Ec2Classic(t *testing.T) { + oldvar := os.Getenv("AWS_DEFAULT_REGION") + os.Setenv("AWS_DEFAULT_REGION", "us-east-1") + defer os.Setenv("AWS_DEFAULT_REGION", oldvar) + + rName1 := fmt.Sprintf("%s-%d", t.Name(), acctest.RandInt()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccEC2ClassicPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSEIPDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSEIPConfig_tags_Ec2Classic(rName1, t.Name()), + ExpectError: regexp.MustCompile(`tags can not be set for an EIP in EC2 Classic`), + }, + }, + }) +} + func TestAccAWSEIP_PublicIpv4Pool_default(t *testing.T) { var conf ec2.Address resourceName := "aws_eip.test" @@ -415,6 +435,7 @@ func TestAccAWSEIP_PublicIpv4Pool_default(t *testing.T) { testAccCheckAWSEIPExists(resourceName, &conf), testAccCheckAWSEIPAttributes(&conf), resource.TestCheckResourceAttr(resourceName, "public_ipv4_pool", "amazon"), + resource.TestCheckResourceAttr(resourceName, "domain", ec2.DomainTypeVpc), ), }, { @@ -448,6 +469,7 @@ func TestAccAWSEIP_PublicIpv4Pool_custom(t *testing.T) { testAccCheckAWSEIPExists(resourceName, &conf), testAccCheckAWSEIPAttributes(&conf), resource.TestCheckResourceAttr(resourceName, "public_ipv4_pool", poolName), + resource.TestCheckResourceAttr(resourceName, "domain", ec2.DomainTypeStandard), ), }, { @@ -459,24 +481,6 @@ func TestAccAWSEIP_PublicIpv4Pool_custom(t *testing.T) { }) } -func testAccCheckAWSEIPDisappears(v *ec2.Address) resource.TestCheckFunc { - return func(s *terraform.State) error { - conn := testAccProvider.Meta().(*AWSClient).ec2conn - - for _, rs := range s.RootModule().Resources { - if rs.Type != "aws_eip" { - continue - } - - _, err := conn.ReleaseAddress(&ec2.ReleaseAddressInput{ - AllocationId: aws.String(rs.Primary.ID), - }) - return err - } - return nil - } -} - func testAccCheckAWSEIPDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).ec2conn @@ -680,6 +684,21 @@ resource "aws_eip" "test" { `, rName, testName) } +func testAccAWSEIPConfig_tags_Ec2Classic(rName, testName string) string { + return fmt.Sprintf(` +provider "aws" { + region = "us-east-1" +} + +resource "aws_eip" "test" { + tags = { + RandomName = "%[1]s" + TestName = "%[2]s" + } +} +`, rName, testName) +} + const testAccAWSEIPConfig_PublicIpv4Pool_default = ` resource "aws_eip" "test" { vpc = true @@ -695,103 +714,43 @@ resource "aws_eip" "test" { `, poolName) } -const testAccAWSEIPInstanceEc2Classic = ` +func testAccAWSEIPInstanceEc2Classic() string { + return composeConfig( + testAccLatestAmazonLinuxPvInstanceStoreAmiConfig(), ` provider "aws" { region = "us-east-1" } -data "aws_ami" "amzn-ami-minimal-pv" { - most_recent = true - owners = ["amazon"] - - filter { - name = "name" - values = ["amzn-ami-minimal-pv-*"] - } - filter { - name = "root-device-type" - values = ["instance-store"] - } -} - resource "aws_instance" "test" { - ami = data.aws_ami.amzn-ami-minimal-pv.id - instance_type = "t2.small" - tags = { - Name = "testAccAWSEIPInstanceEc2Classic" - } -} - -resource "aws_eip" "test" { - instance = aws_instance.test.id -} -` + ami = data.aws_ami.amzn-ami-minimal-pv-instance-store.id -const testAccAWSEIPInstanceConfig = ` -data "aws_ami" "amzn-ami-minimal-pv" { - most_recent = true - owners = ["amazon"] - - filter { - name = "name" - values = ["amzn-ami-minimal-pv-*"] - } - filter { - name = "root-device-type" - values = ["instance-store"] - } -} - -resource "aws_instance" "test" { - ami = data.aws_ami.amzn-ami-minimal-pv.id - instance_type = "t2.small" + # tflint-ignore: aws_instance_previous_type + instance_type = "m1.small" } resource "aws_eip" "test" { instance = aws_instance.test.id } -` - -const testAccAWSEIPInstanceConfig2 = ` -data "aws_ami" "amzn-ami-minimal-pv" { - most_recent = true - owners = ["amazon"] - - filter { - name = "name" - values = ["amzn-ami-minimal-pv-*"] - } - filter { - name = "root-device-type" - values = ["instance-store"] - } +`) } +func testAccAWSEIPInstanceConfig() string { + return composeConfig( + testAccLatestAmazonLinuxHvmEbsAmiConfig(), ` resource "aws_instance" "test" { - ami = data.aws_ami.amzn-ami-minimal-pv.id + ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id instance_type = "t2.small" } resource "aws_eip" "test" { instance = aws_instance.test.id } -` - -const testAccAWSEIPInstanceConfig_associated = ` -data "aws_ami" "amzn-ami-minimal-hvm" { - most_recent = true - owners = ["amazon"] - - filter { - name = "name" - values = ["amzn-ami-minimal-hvm-*"] - } - filter { - name = "root-device-type" - values = ["ebs"] - } +`) } +func testAccAWSEIPInstanceConfig_associated() string { + return composeConfig( + testAccLatestAmazonLinuxHvmEbsAmiConfig(), ` resource "aws_vpc" "default" { cidr_block = "10.0.0.0/16" enable_dns_hostnames = true @@ -822,7 +781,7 @@ resource "aws_subnet" "tf_test_subnet" { } resource "aws_instance" "test" { - ami = data.aws_ami.amzn-ami-minimal-hvm.id + ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id instance_type = "t2.micro" private_ip = "10.0.0.12" @@ -834,7 +793,7 @@ resource "aws_instance" "test" { } resource "aws_instance" "test2" { - ami = data.aws_ami.amzn-ami-minimal-hvm.id + ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id instance_type = "t2.micro" @@ -852,22 +811,12 @@ resource "aws_eip" "test" { instance = aws_instance.test2.id associate_with_private_ip = "10.0.0.19" } -` -const testAccAWSEIPInstanceConfig_associated_switch = ` -data "aws_ami" "amzn-ami-minimal-hvm" { - most_recent = true - owners = ["amazon"] - - filter { - name = "name" - values = ["amzn-ami-minimal-hvm-*"] - } - filter { - name = "root-device-type" - values = ["ebs"] - } +`) } +func testAccAWSEIPInstanceConfig_associated_switch() string { + return composeConfig( + testAccLatestAmazonLinuxHvmEbsAmiConfig(), ` resource "aws_vpc" "default" { cidr_block = "10.0.0.0/16" enable_dns_hostnames = true @@ -898,7 +847,7 @@ resource "aws_subnet" "tf_test_subnet" { } resource "aws_instance" "test" { - ami = data.aws_ami.amzn-ami-minimal-hvm.id + ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id instance_type = "t2.micro" private_ip = "10.0.0.12" @@ -910,7 +859,7 @@ resource "aws_instance" "test" { } resource "aws_instance" "test2" { - ami = data.aws_ami.amzn-ami-minimal-hvm.id + ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id instance_type = "t2.micro" @@ -928,7 +877,8 @@ resource "aws_eip" "test" { instance = aws_instance.test.id associate_with_private_ip = "10.0.0.12" } -` +`) +} const testAccAWSEIPNetworkInterfaceConfig = ` data "aws_availability_zones" "available" { @@ -1098,54 +1048,32 @@ resource "aws_route_table_association" "test" { `, rName)) } -const testAccAWSEIPAssociate_not_associated = ` -data "aws_ami" "amzn-ami-minimal-pv" { - most_recent = true - owners = ["amazon"] - - filter { - name = "name" - values = ["amzn-ami-minimal-pv-*"] - } - filter { - name = "root-device-type" - values = ["instance-store"] - } -} - +func testAccAWSEIPAssociate_not_associated() string { + return composeConfig( + testAccLatestAmazonLinuxPvInstanceStoreAmiConfig(), ` resource "aws_instance" "test" { - ami = data.aws_ami.amzn-ami-minimal-pv.id + ami = data.aws_ami.amzn-ami-minimal-pv-instance-store.id instance_type = "t2.small" } resource "aws_eip" "test" { } -` - -const testAccAWSEIPAssociate_associated = ` -data "aws_ami" "amzn-ami-minimal-pv" { - most_recent = true - owners = ["amazon"] - - filter { - name = "name" - values = ["amzn-ami-minimal-pv-*"] - } - filter { - name = "root-device-type" - values = ["instance-store"] - } +`) } +func testAccAWSEIPAssociate_associated() string { + return composeConfig( + testAccLatestAmazonLinuxPvInstanceStoreAmiConfig(), ` resource "aws_instance" "test" { - ami = data.aws_ami.amzn-ami-minimal-pv.id + ami = data.aws_ami.amzn-ami-minimal-pv-instance-store.id instance_type = "t2.small" } resource "aws_eip" "test" { instance = aws_instance.test.id } -` +`) +} func testAccAWSEIPConfigCustomerOwnedIpv4Pool() string { return ` diff --git a/aws/resource_aws_instance_test.go b/aws/resource_aws_instance_test.go index 96ea177645ec..2b8f3d69c6d9 100644 --- a/aws/resource_aws_instance_test.go +++ b/aws/resource_aws_instance_test.go @@ -4942,6 +4942,28 @@ data "aws_ami" "amzn-ami-minimal-pv-ebs" { `) } +// testAccLatestAmazonLinuxPvInstanceStoreAmiConfig returns the configuration for a data source that +// describes the latest Amazon Linux AMI using PV virtualization and an instance store root device. +// The data source is named 'amzn-ami-minimal-pv-ebs'. +func testAccLatestAmazonLinuxPvInstanceStoreAmiConfig() string { + return fmt.Sprintf(` +data "aws_ami" "amzn-ami-minimal-pv-instance-store" { + most_recent = true + owners = ["amazon"] + + filter { + name = "name" + values = ["amzn-ami-minimal-pv-*"] + } + + filter { + name = "root-device-type" + values = ["instance-store"] + } +} +`) +} + // testAccLatestWindowsServer2016CoreAmiConfig returns the configuration for a data source that // describes the latest Microsoft Windows Server 2016 Core AMI. // The data source is named 'win2016core-ami'. diff --git a/website/docs/r/eip.html.markdown b/website/docs/r/eip.html.markdown index a3ec7785df10..0c85179afe29 100644 --- a/website/docs/r/eip.html.markdown +++ b/website/docs/r/eip.html.markdown @@ -103,7 +103,7 @@ The following arguments are supported: * `associate_with_private_ip` - (Optional) A user specified primary or secondary private IP address to associate with the Elastic IP address. If no private IP address is specified, the Elastic IP address is associated with the primary private IP address. -* `tags` - (Optional) A map of tags to assign to the resource. +* `tags` - (Optional) A map of tags to assign to the resource. Tags can only be applied to EIPs in a VPC. * `public_ipv4_pool` - (Optional) EC2 IPv4 address pool identifier or `amazon`. This option is only available for VPC EIPs. * `customer_owned_ipv4_pool` - The ID of a customer-owned address pool. For more on customer owned IP addressed check out [Customer-owned IP addresses guide](https://docs.aws.amazon.com/outposts/latest/userguide/outposts-networking-components.html#ip-addressing) @@ -128,6 +128,7 @@ In addition to all arguments above, the following attributes are exported: * `public_ipv4_pool` - EC2 IPv4 address pool identifier (if in VPC). * `customer_owned_ipv4_pool` - The ID of a customer-owned address pool. For more on customer owned IP addressed check out [Customer-owned IP addresses guide](https://docs.aws.amazon.com/outposts/latest/userguide/outposts-networking-components.html#ip-addressing) * `customer_owned_ip` - Customer owned IP. +* `domain` - Indicates if this EIP is for use in VPC (`vpc`) or EC2 Classic (`standard`). ~> **Note:** The resource computes the `public_dns` and `private_dns` attributes according to the [VPC DNS Guide](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-dns.html#vpc-dns-hostnames) as they are not available with the EC2 API. From 8d11fb3697a077587b8a6c8a82aa69393adb74d9 Mon Sep 17 00:00:00 2001 From: Graham Davison Date: Wed, 9 Sep 2020 16:22:41 -0700 Subject: [PATCH 5/8] More fixes to EIP acceptance tests --- aws/resource_aws_eip_test.go | 40 ++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/aws/resource_aws_eip_test.go b/aws/resource_aws_eip_test.go index 75c76d237cce..6a46ddc8b1b9 100644 --- a/aws/resource_aws_eip_test.go +++ b/aws/resource_aws_eip_test.go @@ -750,7 +750,8 @@ resource "aws_eip" "test" { func testAccAWSEIPInstanceConfig_associated() string { return composeConfig( - testAccLatestAmazonLinuxHvmEbsAmiConfig(), ` + testAccLatestAmazonLinuxHvmEbsAmiConfig(), + testAccAvailableEc2InstanceTypeForAvailabilityZone("aws_subnet.test.availability_zone", "t3.micro", "t2.micro"), ` resource "aws_vpc" "default" { cidr_block = "10.0.0.0/16" enable_dns_hostnames = true @@ -768,8 +769,9 @@ resource "aws_internet_gateway" "gw" { } } -resource "aws_subnet" "tf_test_subnet" { +resource "aws_subnet" "test" { vpc_id = aws_vpc.default.id + availability_zone = data.aws_availability_zones.available.names[0] cidr_block = "10.0.0.0/24" map_public_ip_on_launch = true @@ -782,10 +784,10 @@ resource "aws_subnet" "tf_test_subnet" { resource "aws_instance" "test" { ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id - instance_type = "t2.micro" + instance_type = data.aws_ec2_instance_type_offering.available.instance_type private_ip = "10.0.0.12" - subnet_id = aws_subnet.tf_test_subnet.id + subnet_id = aws_subnet.test.id tags = { Name = "test instance" @@ -793,12 +795,11 @@ resource "aws_instance" "test" { } resource "aws_instance" "test2" { - ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id - - instance_type = "t2.micro" + ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id + instance_type = data.aws_ec2_instance_type_offering.available.instance_type private_ip = "10.0.0.19" - subnet_id = aws_subnet.tf_test_subnet.id + subnet_id = aws_subnet.test.id tags = { Name = "test2 instance" @@ -811,6 +812,15 @@ resource "aws_eip" "test" { instance = aws_instance.test2.id associate_with_private_ip = "10.0.0.19" } + +data "aws_availability_zones" "available" { + state = "available" + + filter { + name = "opt-in-status" + values = ["opt-in-not-required"] + } +} `) } @@ -834,7 +844,7 @@ resource "aws_internet_gateway" "gw" { } } -resource "aws_subnet" "tf_test_subnet" { +resource "aws_subnet" "test" { vpc_id = aws_vpc.default.id cidr_block = "10.0.0.0/24" map_public_ip_on_launch = true @@ -851,7 +861,7 @@ resource "aws_instance" "test" { instance_type = "t2.micro" private_ip = "10.0.0.12" - subnet_id = aws_subnet.tf_test_subnet.id + subnet_id = aws_subnet.test.id tags = { Name = "test instance" @@ -864,7 +874,7 @@ resource "aws_instance" "test2" { instance_type = "t2.micro" private_ip = "10.0.0.19" - subnet_id = aws_subnet.tf_test_subnet.id + subnet_id = aws_subnet.test.id tags = { Name = "test2 instance" @@ -1050,9 +1060,9 @@ resource "aws_route_table_association" "test" { func testAccAWSEIPAssociate_not_associated() string { return composeConfig( - testAccLatestAmazonLinuxPvInstanceStoreAmiConfig(), ` + testAccLatestAmazonLinuxHvmEbsAmiConfig(), ` resource "aws_instance" "test" { - ami = data.aws_ami.amzn-ami-minimal-pv-instance-store.id + ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id instance_type = "t2.small" } @@ -1063,9 +1073,9 @@ resource "aws_eip" "test" { func testAccAWSEIPAssociate_associated() string { return composeConfig( - testAccLatestAmazonLinuxPvInstanceStoreAmiConfig(), ` + testAccLatestAmazonLinuxHvmEbsAmiConfig(), ` resource "aws_instance" "test" { - ami = data.aws_ami.amzn-ami-minimal-pv-instance-store.id + ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id instance_type = "t2.small" } From 140fb434aa911b68031bebcf455278aa4fb16032 Mon Sep 17 00:00:00 2001 From: Graham Davison Date: Wed, 9 Sep 2020 16:38:47 -0700 Subject: [PATCH 6/8] Fixes EIP Association acceptance tests --- aws/resource_aws_eip_association_test.go | 91 ++++++++++-------------- 1 file changed, 36 insertions(+), 55 deletions(-) diff --git a/aws/resource_aws_eip_association_test.go b/aws/resource_aws_eip_association_test.go index 95ed70bf5da5..b235541af851 100644 --- a/aws/resource_aws_eip_association_test.go +++ b/aws/resource_aws_eip_association_test.go @@ -26,7 +26,6 @@ func TestAccAWSEIPAssociation_instance(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckAWSEIPExists("aws_eip.test", &a), testAccCheckAWSEIPAssociationExists(resourceName, &a), - testAccCheckAWSEIPAssociationExists(resourceName, &a), ), }, { @@ -73,7 +72,7 @@ func TestAccAWSEIPAssociation_basic(t *testing.T) { CheckDestroy: testAccCheckAWSEIPAssociationDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSEIPAssociationConfig, + Config: testAccAWSEIPAssociationConfig(), Check: resource.ComposeTestCheckFunc( testAccCheckAWSEIPExists("aws_eip.test.0", &a), testAccCheckAWSEIPAssociationExists("aws_eip_association.by_allocation_id", &a), @@ -100,7 +99,8 @@ func TestAccAWSEIPAssociation_ec2Classic(t *testing.T) { os.Setenv("AWS_DEFAULT_REGION", "us-east-1") defer os.Setenv("AWS_DEFAULT_REGION", oldvar) - resource.ParallelTest(t, resource.TestCase{ + // This test cannot run in parallel with the other EIP Association tests + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t); testAccEC2ClassicPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAWSEIPAssociationDestroy, @@ -155,19 +155,19 @@ func TestAccAWSEIPAssociation_spotInstance(t *testing.T) { func TestAccAWSEIPAssociation_disappears(t *testing.T) { var a ec2.Address + resourceName := "aws_eip_association.test" + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAWSEIPAssociationDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSEIPAssociationConfigDisappears, + Config: testAccAWSEIPAssociationConfigDisappears(), Check: resource.ComposeTestCheckFunc( - testAccCheckAWSEIPExists( - "aws_eip.bar", &a), - testAccCheckAWSEIPAssociationExists( - "aws_eip_association.by_allocation_id", &a), - testAccCheckEIPAssociationDisappears(&a), + testAccCheckAWSEIPExists("aws_eip.test", &a), + testAccCheckAWSEIPAssociationExists(resourceName, &a), + testAccCheckResourceDisappears(testAccProvider, resourceAwsEipAssociation(), resourceName), ), ExpectNonEmptyPlan: true, }, @@ -175,17 +175,6 @@ func TestAccAWSEIPAssociation_disappears(t *testing.T) { }) } -func testAccCheckEIPAssociationDisappears(address *ec2.Address) resource.TestCheckFunc { - return func(s *terraform.State) error { - conn := testAccProvider.Meta().(*AWSClient).ec2conn - opts := &ec2.DisassociateAddressInput{ - AssociationId: address.AssociationId, - } - _, err := conn.DisassociateAddress(opts) - return err - } -} - func testAccCheckAWSEIPAssociationExists(name string, res *ec2.Address) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] @@ -270,7 +259,9 @@ func testAccCheckAWSEIPAssociationDestroy(s *terraform.State) error { return nil } -const testAccAWSEIPAssociationConfig = ` +func testAccAWSEIPAssociationConfig() string { + return composeConfig( + testAccLatestAmazonLinuxHvmEbsAmiConfig(), ` data "aws_availability_zones" "available" { state = "available" @@ -287,16 +278,6 @@ resource "aws_vpc" "test" { } } -data "aws_ami" "amzn-ami-minimal-pv" { - most_recent = true - owners = ["amazon"] - - filter { - name = "name" - values = ["amzn-ami-minimal-pv-*"] - } -} - resource "aws_subnet" "test" { vpc_id = aws_vpc.test.id cidr_block = "192.168.0.0/25" @@ -312,7 +293,7 @@ resource "aws_internet_gateway" "test" { resource "aws_instance" "test" { count = 2 - ami = data.aws_ami.amzn-ami-minimal-pv.id + ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id availability_zone = data.aws_availability_zones.available.names[0] instance_type = "t2.small" subnet_id = aws_subnet.test.id @@ -351,9 +332,12 @@ resource "aws_network_interface" "test" { device_index = 1 } } -` +`) +} -const testAccAWSEIPAssociationConfigDisappears = ` +func testAccAWSEIPAssociationConfigDisappears() string { + return composeConfig( + testAccLatestAmazonLinuxHvmEbsAmiConfig(), ` data "aws_availability_zones" "available" { state = "available" @@ -363,16 +347,6 @@ data "aws_availability_zones" "available" { } } -data "aws_ami" "amzn-ami-minimal-pv" { - most_recent = true - owners = ["amazon"] - - filter { - name = "name" - values = ["amzn-ami-minimal-pv-*"] - } -} - resource "aws_vpc" "main" { cidr_block = "192.168.0.0/24" tags = { @@ -393,22 +367,23 @@ resource "aws_internet_gateway" "igw" { vpc_id = aws_vpc.main.id } -resource "aws_instance" "foo" { - ami = data.aws_ami.amzn-ami-minimal-pv.id +resource "aws_instance" "test" { + ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id availability_zone = data.aws_availability_zones.available.names[0] instance_type = "t2.small" subnet_id = aws_subnet.sub.id } -resource "aws_eip" "bar" { +resource "aws_eip" "test" { vpc = true } -resource "aws_eip_association" "by_allocation_id" { - allocation_id = aws_eip.bar.id - instance_id = aws_instance.foo.id +resource "aws_eip_association" "test" { + allocation_id = aws_eip.test.id + instance_id = aws_instance.test.id +} +`) } -` const testAccAWSEIPAssociationConfig_ec2Classic = ` provider "aws" { @@ -445,7 +420,9 @@ data "aws_ami" "ubuntu" { resource "aws_instance" "test" { ami = data.aws_ami.ubuntu.id availability_zone = data.aws_availability_zones.available.names[0] - instance_type = "t2.micro" + + # tflint-ignore: aws_instance_previous_type + instance_type = "t1.micro" } resource "aws_eip_association" "test" { @@ -457,7 +434,9 @@ resource "aws_eip_association" "test" { func testAccAWSEIPAssociationConfig_spotInstance(rInt int) string { return composeConfig( testAccAWSSpotInstanceRequestConfig(rInt), ` -resource "aws_eip" "test" {} +resource "aws_eip" "test" { + vpc = true +} resource "aws_eip_association" "test" { allocation_id = aws_eip.test.id @@ -467,7 +446,9 @@ resource "aws_eip_association" "test" { } func testAccAWSEIPAssociationConfig_instance() string { - return testAccLatestAmazonLinuxHvmEbsAmiConfig() + fmt.Sprintf(` + return composeConfig( + testAccLatestAmazonLinuxHvmEbsAmiConfig(), + fmt.Sprintf(` resource "aws_instance" "test" { ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id instance_type = "t2.small" @@ -479,7 +460,7 @@ resource "aws_eip_association" "test" { allocation_id = aws_eip.test.id instance_id = aws_instance.test.id } -`) +`)) } const testAccAWSEIPAssociationConfig_networkInterface = ` From c2aa3046ff9416531ac2e4bb7c6fe76c0aa631a1 Mon Sep 17 00:00:00 2001 From: Graham Davison Date: Thu, 10 Sep 2020 13:40:29 -0700 Subject: [PATCH 7/8] Fixes Elasticache cluster acceptance tests --- aws/resource_aws_elasticache_cluster_test.go | 71 +++++++++++--------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/aws/resource_aws_elasticache_cluster_test.go b/aws/resource_aws_elasticache_cluster_test.go index 2c1ffde05508..aad64a1813ec 100644 --- a/aws/resource_aws_elasticache_cluster_test.go +++ b/aws/resource_aws_elasticache_cluster_test.go @@ -215,25 +215,28 @@ func TestAccAWSElasticacheCluster_Port(t *testing.T) { }) } -func TestAccAWSElasticacheCluster_SecurityGroup(t *testing.T) { +func TestAccAWSElasticacheCluster_SecurityGroup_Ec2Classic(t *testing.T) { oldvar := os.Getenv("AWS_DEFAULT_REGION") os.Setenv("AWS_DEFAULT_REGION", "us-east-1") defer os.Setenv("AWS_DEFAULT_REGION", oldvar) var ec elasticache.CacheCluster - resource.ParallelTest(t, resource.TestCase{ + resourceName := "aws_elasticache_cluster.test" + resourceSecurityGroupName := "aws_elasticache_security_group.test" + + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t); testAccEC2ClassicPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAWSElasticacheClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSElasticacheClusterConfig_SecurityGroup, + Config: testAccAWSElasticacheClusterConfig_SecurityGroup_Ec2Classic, Check: resource.ComposeTestCheckFunc( - testAccCheckAWSElasticacheSecurityGroupExists("aws_elasticache_security_group.test"), - testAccCheckAWSElasticacheClusterExists("aws_elasticache_cluster.test", &ec), - resource.TestCheckResourceAttr("aws_elasticache_cluster.test", "cache_nodes.0.id", "0001"), - resource.TestCheckResourceAttrSet("aws_elasticache_cluster.test", "configuration_endpoint"), - resource.TestCheckResourceAttrSet("aws_elasticache_cluster.test", "cluster_address"), + testAccCheckAWSElasticacheSecurityGroupExists(resourceSecurityGroupName), + testAccCheckAWSElasticacheClusterExists(resourceName, &ec), + resource.TestCheckResourceAttr(resourceName, "cache_nodes.0.id", "0001"), + resource.TestCheckResourceAttrSet(resourceName, "configuration_endpoint"), + resource.TestCheckResourceAttrSet(resourceName, "cluster_address"), ), }, }, @@ -542,18 +545,18 @@ func TestAccAWSElasticacheCluster_NodeTypeResize_Memcached(t *testing.T) { CheckDestroy: testAccCheckAWSElasticacheClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSElasticacheClusterConfig_NodeType_Memcached(rName, "cache.t2.medium"), + Config: testAccAWSElasticacheClusterConfig_NodeType_Memcached(rName, "cache.t3.small"), Check: resource.ComposeTestCheckFunc( testAccCheckAWSElasticacheClusterExists(resourceName, &pre), - resource.TestCheckResourceAttr(resourceName, "node_type", "cache.t2.medium"), + resource.TestCheckResourceAttr(resourceName, "node_type", "cache.t3.small"), ), }, { - Config: testAccAWSElasticacheClusterConfig_NodeType_Memcached(rName, "cache.t2.large"), + Config: testAccAWSElasticacheClusterConfig_NodeType_Memcached(rName, "cache.t3.medium"), Check: resource.ComposeTestCheckFunc( testAccCheckAWSElasticacheClusterExists(resourceName, &post), testAccCheckAWSElasticacheClusterRecreated(&pre, &post), - resource.TestCheckResourceAttr(resourceName, "node_type", "cache.t2.large"), + resource.TestCheckResourceAttr(resourceName, "node_type", "cache.t3.medium"), ), }, }, @@ -571,18 +574,18 @@ func TestAccAWSElasticacheCluster_NodeTypeResize_Redis(t *testing.T) { CheckDestroy: testAccCheckAWSElasticacheClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSElasticacheClusterConfig_NodeType_Redis(rName, "cache.t2.medium"), + Config: testAccAWSElasticacheClusterConfig_NodeType_Redis(rName, "cache.t3.small"), Check: resource.ComposeTestCheckFunc( testAccCheckAWSElasticacheClusterExists(resourceName, &pre), - resource.TestCheckResourceAttr(resourceName, "node_type", "cache.t2.medium"), + resource.TestCheckResourceAttr(resourceName, "node_type", "cache.t3.small"), ), }, { - Config: testAccAWSElasticacheClusterConfig_NodeType_Redis(rName, "cache.t2.large"), + Config: testAccAWSElasticacheClusterConfig_NodeType_Redis(rName, "cache.t3.medium"), Check: resource.ComposeTestCheckFunc( testAccCheckAWSElasticacheClusterExists(resourceName, &post), testAccCheckAWSElasticacheClusterNotRecreated(&pre, &post), - resource.TestCheckResourceAttr(resourceName, "node_type", "cache.t2.large"), + resource.TestCheckResourceAttr(resourceName, "node_type", "cache.t3.medium"), ), }, }, @@ -648,7 +651,7 @@ func TestAccAWSElasticacheCluster_ReplicationGroupID_SingleReplica(t *testing.T) testAccCheckAWSElasticacheClusterExists(clusterResourceName, &cluster), testAccCheckAWSElasticacheClusterReplicationGroupIDAttribute(&cluster, &replicationGroup), resource.TestCheckResourceAttr(clusterResourceName, "engine", "redis"), - resource.TestCheckResourceAttr(clusterResourceName, "node_type", "cache.t2.medium"), + resource.TestCheckResourceAttr(clusterResourceName, "node_type", "cache.t3.medium"), resource.TestCheckResourceAttr(clusterResourceName, "port", "6379"), ), }, @@ -673,15 +676,17 @@ func TestAccAWSElasticacheCluster_ReplicationGroupID_MultipleReplica(t *testing. Config: testAccAWSElasticacheClusterConfig_ReplicationGroupID_Replica(rName, 2), Check: resource.ComposeTestCheckFunc( testAccCheckAWSElasticacheReplicationGroupExists(replicationGroupResourceName, &replicationGroup), + testAccCheckAWSElasticacheClusterExists(clusterResourceName1, &cluster1), - testAccCheckAWSElasticacheClusterExists(clusterResourceName2, &cluster2), testAccCheckAWSElasticacheClusterReplicationGroupIDAttribute(&cluster1, &replicationGroup), - testAccCheckAWSElasticacheClusterReplicationGroupIDAttribute(&cluster2, &replicationGroup), resource.TestCheckResourceAttr(clusterResourceName1, "engine", "redis"), - resource.TestCheckResourceAttr(clusterResourceName1, "node_type", "cache.t2.medium"), + resource.TestCheckResourceAttr(clusterResourceName1, "node_type", "cache.t3.medium"), resource.TestCheckResourceAttr(clusterResourceName1, "port", "6379"), + + testAccCheckAWSElasticacheClusterExists(clusterResourceName2, &cluster2), + testAccCheckAWSElasticacheClusterReplicationGroupIDAttribute(&cluster2, &replicationGroup), resource.TestCheckResourceAttr(clusterResourceName2, "engine", "redis"), - resource.TestCheckResourceAttr(clusterResourceName2, "node_type", "cache.t2.medium"), + resource.TestCheckResourceAttr(clusterResourceName2, "node_type", "cache.t3.medium"), resource.TestCheckResourceAttr(clusterResourceName2, "port", "6379"), ), }, @@ -837,7 +842,7 @@ resource "aws_elasticache_cluster" "test" { `, rName, port) } -var testAccAWSElasticacheClusterConfig_SecurityGroup = fmt.Sprintf(` +var testAccAWSElasticacheClusterConfig_SecurityGroup_Ec2Classic = fmt.Sprintf(` resource "aws_security_group" "test" { name = "tf-test-security-group-%03d" description = "tf-test-security-group-descr" @@ -861,9 +866,11 @@ resource "aws_elasticache_security_group" "test" { } resource "aws_elasticache_cluster" "test" { - cluster_id = "tf-%s" - engine = "memcached" - node_type = "cache.t2.medium" + cluster_id = "tf-%s" + engine = "memcached" + + # tflint-ignore: aws_elasticache_cluster_previous_type + node_type = "cache.m3.medium" num_cache_nodes = 1 port = 11211 security_group_names = [aws_elasticache_security_group.test.name] @@ -1115,7 +1122,7 @@ resource "aws_elasticache_cluster" "test" { az_mode = "%[2]s" cluster_id = "%[1]s" engine = "memcached" - node_type = "cache.t2.medium" + node_type = "cache.t3.medium" num_cache_nodes = 1 port = 11211 } @@ -1129,7 +1136,7 @@ resource "aws_elasticache_cluster" "test" { az_mode = "%[2]s" cluster_id = "%[1]s" engine = "redis" - node_type = "cache.t2.medium" + node_type = "cache.t3.medium" num_cache_nodes = 1 port = 6379 } @@ -1143,7 +1150,7 @@ resource "aws_elasticache_cluster" "test" { cluster_id = "%[1]s" engine = "memcached" engine_version = "%[2]s" - node_type = "cache.t2.medium" + node_type = "cache.t3.medium" num_cache_nodes = 1 port = 11211 } @@ -1157,7 +1164,7 @@ resource "aws_elasticache_cluster" "test" { cluster_id = "%[1]s" engine = "redis" engine_version = "%[2]s" - node_type = "cache.t2.medium" + node_type = "cache.t3.medium" num_cache_nodes = 1 port = 6379 } @@ -1196,7 +1203,7 @@ resource "aws_elasticache_cluster" "test" { apply_immediately = true cluster_id = "%[1]s" engine = "redis" - node_type = "cache.t2.medium" + node_type = "cache.t3.medium" num_cache_nodes = %[2]d port = 6379 } @@ -1217,7 +1224,7 @@ data "aws_availability_zones" "available" { resource "aws_elasticache_replication_group" "test" { replication_group_description = "Terraform Acceptance Testing" replication_group_id = "%[1]s" - node_type = "cache.t2.medium" + node_type = "cache.t3.medium" number_cache_clusters = 1 port = 6379 @@ -1239,7 +1246,7 @@ func testAccAWSElasticacheClusterConfig_ReplicationGroupID_Replica(rName string, resource "aws_elasticache_replication_group" "test" { replication_group_description = "Terraform Acceptance Testing" replication_group_id = "%[1]s" - node_type = "cache.t2.medium" + node_type = "cache.t3.medium" number_cache_clusters = 1 port = 6379 From 0064ac7b1b917e780185e1e06b7517508acfbab7 Mon Sep 17 00:00:00 2001 From: Graham Davison Date: Fri, 11 Sep 2020 11:29:55 -0700 Subject: [PATCH 8/8] Clean up ELB attachment tests --- aws/resource_aws_elb_attachment_test.go | 103 +++++++++--------------- 1 file changed, 38 insertions(+), 65 deletions(-) diff --git a/aws/resource_aws_elb_attachment_test.go b/aws/resource_aws_elb_attachment_test.go index fc08f91a3661..01ab322824d3 100644 --- a/aws/resource_aws_elb_attachment_test.go +++ b/aws/resource_aws_elb_attachment_test.go @@ -12,51 +12,40 @@ import ( func TestAccAWSELBAttachment_basic(t *testing.T) { var conf elb.LoadBalancerDescription - - testCheckInstanceAttached := func(count int) resource.TestCheckFunc { - return func(*terraform.State) error { - if len(conf.Instances) != count { - return fmt.Errorf("instance count does not match") - } - return nil - } - } + resourceName := "aws_elb.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - IDRefreshName: "aws_elb.bar", + IDRefreshName: resourceName, Providers: testAccProviders, CheckDestroy: testAccCheckAWSELBDestroy, Steps: []resource.TestStep{ { Config: testAccAWSELBAttachmentConfig1(), Check: resource.ComposeTestCheckFunc( - testAccCheckAWSELBExists("aws_elb.bar", &conf), - testCheckInstanceAttached(1), + testAccCheckAWSELBExists(resourceName, &conf), + testAccAWSELBAttachmentCheckInstanceCount(&conf, 1), ), }, - { Config: testAccAWSELBAttachmentConfig2(), Check: resource.ComposeTestCheckFunc( - testAccCheckAWSELBExists("aws_elb.bar", &conf), - testCheckInstanceAttached(2), + testAccCheckAWSELBExists(resourceName, &conf), + testAccAWSELBAttachmentCheckInstanceCount(&conf, 2), ), }, - { Config: testAccAWSELBAttachmentConfig3(), Check: resource.ComposeTestCheckFunc( - testAccCheckAWSELBExists("aws_elb.bar", &conf), - testCheckInstanceAttached(2), + testAccCheckAWSELBExists(resourceName, &conf), + testAccAWSELBAttachmentCheckInstanceCount(&conf, 2), ), }, - { Config: testAccAWSELBAttachmentConfig4(), Check: resource.ComposeTestCheckFunc( - testAccCheckAWSELBExists("aws_elb.bar", &conf), - testCheckInstanceAttached(0), + testAccCheckAWSELBExists(resourceName, &conf), + testAccAWSELBAttachmentCheckInstanceCount(&conf, 0), ), }, }, @@ -66,6 +55,7 @@ func TestAccAWSELBAttachment_basic(t *testing.T) { // remove and instance and check that it's correctly re-attached. func TestAccAWSELBAttachment_drift(t *testing.T) { var conf elb.LoadBalancerDescription + resourceName := "aws_elb.test" deregInstance := func() { conn := testAccProvider.Meta().(*AWSClient).elbconn @@ -84,42 +74,41 @@ func TestAccAWSELBAttachment_drift(t *testing.T) { } - testCheckInstanceAttached := func(count int) resource.TestCheckFunc { - return func(*terraform.State) error { - if len(conf.Instances) != count { - return fmt.Errorf("instance count does not match") - } - return nil - } - } - resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - IDRefreshName: "aws_elb.bar", + IDRefreshName: resourceName, Providers: testAccProviders, CheckDestroy: testAccCheckAWSELBDestroy, Steps: []resource.TestStep{ { Config: testAccAWSELBAttachmentConfig1(), Check: resource.ComposeTestCheckFunc( - testAccCheckAWSELBExists("aws_elb.bar", &conf), - testCheckInstanceAttached(1), + testAccCheckAWSELBExists(resourceName, &conf), + testAccAWSELBAttachmentCheckInstanceCount(&conf, 1), ), }, - // remove an instance from the ELB, and make sure it gets re-added { Config: testAccAWSELBAttachmentConfig1(), PreConfig: deregInstance, Check: resource.ComposeTestCheckFunc( - testAccCheckAWSELBExists("aws_elb.bar", &conf), - testCheckInstanceAttached(1), + testAccCheckAWSELBExists(resourceName, &conf), + testAccAWSELBAttachmentCheckInstanceCount(&conf, 1), ), }, }, }) } +func testAccAWSELBAttachmentCheckInstanceCount(conf *elb.LoadBalancerDescription, expected int) resource.TestCheckFunc { + return func(*terraform.State) error { + if actual := len(conf.Instances); actual != expected { + return fmt.Errorf("instance count does not match: expected %d, got %d", expected, actual) + } + return nil + } +} + // add one attachment func testAccAWSELBAttachmentConfig1() string { return testAccLatestAmazonLinuxHvmEbsAmiConfig() + fmt.Sprintf(` @@ -132,12 +121,8 @@ data "aws_availability_zones" "available" { } } -resource "aws_elb" "bar" { - availability_zones = [ - data.aws_availability_zones.available.names[0], - data.aws_availability_zones.available.names[1], - data.aws_availability_zones.available.names[2] - ] +resource "aws_elb" "test" { + availability_zones = data.aws_availability_zones.available.names listener { instance_port = 8000 @@ -153,7 +138,7 @@ resource "aws_instance" "foo1" { } resource "aws_elb_attachment" "foo1" { - elb = aws_elb.bar.id + elb = aws_elb.test.id instance = aws_instance.foo1.id } `) @@ -171,12 +156,8 @@ data "aws_availability_zones" "available" { } } -resource "aws_elb" "bar" { - availability_zones = [ - data.aws_availability_zones.available.names[0], - data.aws_availability_zones.available.names[1], - data.aws_availability_zones.available.names[2] - ] +resource "aws_elb" "test" { + availability_zones = data.aws_availability_zones.available.names listener { instance_port = 8000 @@ -197,12 +178,12 @@ resource "aws_instance" "foo2" { } resource "aws_elb_attachment" "foo1" { - elb = aws_elb.bar.id + elb = aws_elb.test.id instance = aws_instance.foo1.id } resource "aws_elb_attachment" "foo2" { - elb = aws_elb.bar.id + elb = aws_elb.test.id instance = aws_instance.foo2.id } `) @@ -220,12 +201,8 @@ data "aws_availability_zones" "available" { } } -resource "aws_elb" "bar" { - availability_zones = [ - data.aws_availability_zones.available.names[0], - data.aws_availability_zones.available.names[1], - data.aws_availability_zones.available.names[2] - ] +resource "aws_elb" "test" { + availability_zones = data.aws_availability_zones.available.names listener { instance_port = 8000 @@ -246,12 +223,12 @@ resource "aws_instance" "foo2" { } resource "aws_elb_attachment" "foo1" { - elb = aws_elb.bar.id + elb = aws_elb.test.id instance = aws_instance.foo2.id } resource "aws_elb_attachment" "foo2" { - elb = aws_elb.bar.id + elb = aws_elb.test.id instance = aws_instance.foo1.id } `) @@ -269,12 +246,8 @@ data "aws_availability_zones" "available" { } } -resource "aws_elb" "bar" { - availability_zones = [ - data.aws_availability_zones.available.names[0], - data.aws_availability_zones.available.names[1], - data.aws_availability_zones.available.names[2] - ] +resource "aws_elb" "test" { + availability_zones = data.aws_availability_zones.available.names listener { instance_port = 8000