From 00b679ff01e80027ceeef8a67434775632138fd6 Mon Sep 17 00:00:00 2001 From: Simon Davis Date: Fri, 27 Nov 2020 08:14:01 -0800 Subject: [PATCH 1/3] remove last references to tfawsresrouce --- aws/data_source_aws_eks_cluster_test.go | 5 +- ..._source_aws_route53_resolver_rules_test.go | 3 +- ...sapplicationrepository_application_test.go | 5 +- ...esource_aws_api_gateway_usage_plan_test.go | 15 ++--- ...rce_aws_lambda_code_signing_config_test.go | 11 ++-- ...e_aws_msk_scram_secret_association_test.go | 13 ++-- ...ws_networkfirewall_firewall_policy_test.go | 55 ++++++++-------- ...ource_aws_networkfirewall_firewall_test.go | 15 ++--- ...workfirewall_logging_configuration_test.go | 51 +++++++-------- ...rce_aws_networkfirewall_rule_group_test.go | 65 +++++++++---------- ...ionrepository_cloudformation_stack_test.go | 17 +++-- 11 files changed, 122 insertions(+), 133 deletions(-) diff --git a/aws/data_source_aws_eks_cluster_test.go b/aws/data_source_aws_eks_cluster_test.go index c72469d6ef8..7ad78414379 100644 --- a/aws/data_source_aws_eks_cluster_test.go +++ b/aws/data_source_aws_eks_cluster_test.go @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/terraform-providers/terraform-provider-aws/aws/internal/tfawsresource" ) func TestAccAWSEksClusterDataSource_basic(t *testing.T) { @@ -28,8 +27,8 @@ func TestAccAWSEksClusterDataSource_basic(t *testing.T) { resource.TestCheckResourceAttrPair(resourceName, "certificate_authority.0.data", dataSourceResourceName, "certificate_authority.0.data"), resource.TestCheckResourceAttrPair(resourceName, "created_at", dataSourceResourceName, "created_at"), resource.TestCheckResourceAttr(dataSourceResourceName, "enabled_cluster_log_types.#", "2"), - tfawsresource.TestCheckTypeSetElemAttr(dataSourceResourceName, "enabled_cluster_log_types.*", "api"), - tfawsresource.TestCheckTypeSetElemAttr(dataSourceResourceName, "enabled_cluster_log_types.*", "audit"), + resource.TestCheckTypeSetElemAttr(dataSourceResourceName, "enabled_cluster_log_types.*", "api"), + resource.TestCheckTypeSetElemAttr(dataSourceResourceName, "enabled_cluster_log_types.*", "audit"), resource.TestCheckResourceAttrPair(resourceName, "endpoint", dataSourceResourceName, "endpoint"), resource.TestCheckResourceAttrPair(resourceName, "identity.#", dataSourceResourceName, "identity.#"), resource.TestCheckResourceAttrPair(resourceName, "identity.0.oidc.#", dataSourceResourceName, "identity.0.oidc.#"), diff --git a/aws/data_source_aws_route53_resolver_rules_test.go b/aws/data_source_aws_route53_resolver_rules_test.go index f0617f8049a..788582b0d58 100644 --- a/aws/data_source_aws_route53_resolver_rules_test.go +++ b/aws/data_source_aws_route53_resolver_rules_test.go @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/terraform-providers/terraform-provider-aws/aws/internal/tfawsresource" ) func TestAccDataSourceAwsRoute53ResolverRules_basic(t *testing.T) { @@ -20,7 +19,7 @@ func TestAccDataSourceAwsRoute53ResolverRules_basic(t *testing.T) { Config: testAccDataSourceAwsRoute53ResolverRules_basic, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dsResourceName, "resolver_rule_ids.#", "1"), - tfawsresource.TestCheckTypeSetElemAttr(dsResourceName, "resolver_rule_ids.*", "rslvr-autodefined-rr-internet-resolver"), + resource.TestCheckTypeSetElemAttr(dsResourceName, "resolver_rule_ids.*", "rslvr-autodefined-rr-internet-resolver"), ), }, }, diff --git a/aws/data_source_aws_serverlessapplicationrepository_application_test.go b/aws/data_source_aws_serverlessapplicationrepository_application_test.go index 930545879f7..9cff7bd4251 100644 --- a/aws/data_source_aws_serverlessapplicationrepository_application_test.go +++ b/aws/data_source_aws_serverlessapplicationrepository_application_test.go @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - "github.com/terraform-providers/terraform-provider-aws/aws/internal/tfawsresource" ) func TestAccDataSourceAwsServerlessApplicationRepositoryApplication_Basic(t *testing.T) { @@ -67,8 +66,8 @@ func TestAccDataSourceAwsServerlessApplicationRepositoryApplication_Versioned(t resource.TestCheckResourceAttrSet(datasourceName, "source_code_url"), resource.TestCheckResourceAttrSet(datasourceName, "template_url"), resource.TestCheckResourceAttr(datasourceName, "required_capabilities.#", "2"), - tfawsresource.TestCheckTypeSetElemAttr(datasourceName, "required_capabilities.*", "CAPABILITY_IAM"), - tfawsresource.TestCheckTypeSetElemAttr(datasourceName, "required_capabilities.*", "CAPABILITY_RESOURCE_POLICY"), + resource.TestCheckTypeSetElemAttr(datasourceName, "required_capabilities.*", "CAPABILITY_IAM"), + resource.TestCheckTypeSetElemAttr(datasourceName, "required_capabilities.*", "CAPABILITY_RESOURCE_POLICY"), ), }, { diff --git a/aws/resource_aws_api_gateway_usage_plan_test.go b/aws/resource_aws_api_gateway_usage_plan_test.go index 2442457ce71..400eca31391 100644 --- a/aws/resource_aws_api_gateway_usage_plan_test.go +++ b/aws/resource_aws_api_gateway_usage_plan_test.go @@ -10,7 +10,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - "github.com/terraform-providers/terraform-provider-aws/aws/internal/tfawsresource" ) func TestAccAWSAPIGatewayUsagePlan_basic(t *testing.T) { @@ -351,7 +350,7 @@ func TestAccAWSAPIGatewayUsagePlan_apiStages(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckAWSAPIGatewayUsagePlanExists(resourceName, &conf), resource.TestCheckResourceAttr(resourceName, "name", rName), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "api_stages.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "api_stages.*", map[string]string{ "stage": "test", }), ), @@ -376,7 +375,7 @@ func TestAccAWSAPIGatewayUsagePlan_apiStages(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckAWSAPIGatewayUsagePlanExists(resourceName, &conf), resource.TestCheckResourceAttr(resourceName, "name", rName), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "api_stages.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "api_stages.*", map[string]string{ "stage": "test", }), ), @@ -387,10 +386,10 @@ func TestAccAWSAPIGatewayUsagePlan_apiStages(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckAWSAPIGatewayUsagePlanExists(resourceName, &conf), resource.TestCheckResourceAttr(resourceName, "name", rName), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "api_stages.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "api_stages.*", map[string]string{ "stage": "foo", }), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "api_stages.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "api_stages.*", map[string]string{ "stage": "test", }), ), @@ -400,7 +399,7 @@ func TestAccAWSAPIGatewayUsagePlan_apiStages(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckAWSAPIGatewayUsagePlanExists(resourceName, &conf), resource.TestCheckResourceAttr(resourceName, "name", rName), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "api_stages.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "api_stages.*", map[string]string{ "stage": "foo", }), ), @@ -432,10 +431,10 @@ func TestAccAWSAPIGatewayUsagePlan_apiStages_multiple(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckAWSAPIGatewayUsagePlanExists(resourceName, &conf), resource.TestCheckResourceAttr(resourceName, "name", rName), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "api_stages.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "api_stages.*", map[string]string{ "stage": "foo", }), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "api_stages.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "api_stages.*", map[string]string{ "stage": "test", }), ), diff --git a/aws/resource_aws_lambda_code_signing_config_test.go b/aws/resource_aws_lambda_code_signing_config_test.go index df40ae6000a..49ca6ed7eeb 100644 --- a/aws/resource_aws_lambda_code_signing_config_test.go +++ b/aws/resource_aws_lambda_code_signing_config_test.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/aws-sdk-go-base/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - "github.com/terraform-providers/terraform-provider-aws/aws/internal/tfawsresource" ) func TestAccAWSLambdaCodeSigningConfig_basic(t *testing.T) { @@ -29,8 +28,8 @@ func TestAccAWSLambdaCodeSigningConfig_basic(t *testing.T) { testAccCheckAwsCodeSigningConfigExists(resourceName, &conf), resource.TestCheckResourceAttr(resourceName, "description", "Code Signing Config for test account"), resource.TestCheckResourceAttr(resourceName, "allowed_publishers.0.signing_profile_version_arns.#", "2"), - tfawsresource.TestCheckTypeSetElemAttrPair(resourceName, "allowed_publishers.0.signing_profile_version_arns.*", signingProfile1, "version_arn"), - tfawsresource.TestCheckTypeSetElemAttrPair(resourceName, "allowed_publishers.0.signing_profile_version_arns.*", signingProfile2, "version_arn"), + resource.TestCheckTypeSetElemAttrPair(resourceName, "allowed_publishers.0.signing_profile_version_arns.*", signingProfile1, "version_arn"), + resource.TestCheckTypeSetElemAttrPair(resourceName, "allowed_publishers.0.signing_profile_version_arns.*", signingProfile2, "version_arn"), resource.TestCheckResourceAttr(resourceName, "policies.0.untrusted_artifact_on_deployment", "Warn"), ), }, @@ -93,8 +92,8 @@ func TestAccAWSLambdaCodeSigningConfig_UpdatePublishers(t *testing.T) { testAccCheckAwsCodeSigningConfigExists(resourceName, &conf), resource.TestCheckResourceAttr(resourceName, "description", "Code Signing Config for test account"), resource.TestCheckResourceAttr(resourceName, "allowed_publishers.0.signing_profile_version_arns.#", "2"), - tfawsresource.TestCheckTypeSetElemAttrPair(resourceName, "allowed_publishers.0.signing_profile_version_arns.*", signingProfile1, "version_arn"), - tfawsresource.TestCheckTypeSetElemAttrPair(resourceName, "allowed_publishers.0.signing_profile_version_arns.*", signingProfile2, "version_arn"), + resource.TestCheckTypeSetElemAttrPair(resourceName, "allowed_publishers.0.signing_profile_version_arns.*", signingProfile1, "version_arn"), + resource.TestCheckTypeSetElemAttrPair(resourceName, "allowed_publishers.0.signing_profile_version_arns.*", signingProfile2, "version_arn"), ), }, { @@ -102,7 +101,7 @@ func TestAccAWSLambdaCodeSigningConfig_UpdatePublishers(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckAwsCodeSigningConfigExists(resourceName, &conf), resource.TestCheckResourceAttr(resourceName, "allowed_publishers.0.signing_profile_version_arns.#", "1"), - tfawsresource.TestCheckTypeSetElemAttrPair(resourceName, "allowed_publishers.0.signing_profile_version_arns.*", signingProfile1, "version_arn"), + resource.TestCheckTypeSetElemAttrPair(resourceName, "allowed_publishers.0.signing_profile_version_arns.*", signingProfile1, "version_arn"), ), }, { diff --git a/aws/resource_aws_msk_scram_secret_association_test.go b/aws/resource_aws_msk_scram_secret_association_test.go index cf0462e000d..e73e5d2047a 100644 --- a/aws/resource_aws_msk_scram_secret_association_test.go +++ b/aws/resource_aws_msk_scram_secret_association_test.go @@ -11,7 +11,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/msk/finder" - "github.com/terraform-providers/terraform-provider-aws/aws/internal/tfawsresource" ) func TestAccAwsMskScramSecretAssociation_basic(t *testing.T) { @@ -31,7 +30,7 @@ func TestAccAwsMskScramSecretAssociation_basic(t *testing.T) { testAccCheckMskScramSecretAssociationExists(resourceName), resource.TestCheckResourceAttrPair(resourceName, "cluster_arn", clusterResourceName, "arn"), resource.TestCheckResourceAttr(resourceName, "secret_arn_list.#", "1"), - tfawsresource.TestCheckTypeSetElemAttrPair(resourceName, "secret_arn_list.*", secretResourceName, "arn"), + resource.TestCheckTypeSetElemAttrPair(resourceName, "secret_arn_list.*", secretResourceName, "arn"), ), }, { @@ -66,9 +65,9 @@ func TestAccAwsMskScramSecretAssociation_update(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckMskScramSecretAssociationExists(resourceName), resource.TestCheckResourceAttr(resourceName, "secret_arn_list.#", "3"), - tfawsresource.TestCheckTypeSetElemAttrPair(resourceName, "secret_arn_list.*", secretResourceName, "arn"), - tfawsresource.TestCheckTypeSetElemAttrPair(resourceName, "secret_arn_list.*", secretResourceName2, "arn"), - tfawsresource.TestCheckTypeSetElemAttrPair(resourceName, "secret_arn_list.*", secretResourceName3, "arn"), + resource.TestCheckTypeSetElemAttrPair(resourceName, "secret_arn_list.*", secretResourceName, "arn"), + resource.TestCheckTypeSetElemAttrPair(resourceName, "secret_arn_list.*", secretResourceName2, "arn"), + resource.TestCheckTypeSetElemAttrPair(resourceName, "secret_arn_list.*", secretResourceName3, "arn"), ), }, { @@ -76,8 +75,8 @@ func TestAccAwsMskScramSecretAssociation_update(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckMskScramSecretAssociationExists(resourceName), resource.TestCheckResourceAttr(resourceName, "secret_arn_list.#", "2"), - tfawsresource.TestCheckTypeSetElemAttrPair(resourceName, "secret_arn_list.*", secretResourceName, "arn"), - tfawsresource.TestCheckTypeSetElemAttrPair(resourceName, "secret_arn_list.*", secretResourceName2, "arn"), + resource.TestCheckTypeSetElemAttrPair(resourceName, "secret_arn_list.*", secretResourceName, "arn"), + resource.TestCheckTypeSetElemAttrPair(resourceName, "secret_arn_list.*", secretResourceName2, "arn"), ), }, { diff --git a/aws/resource_aws_networkfirewall_firewall_policy_test.go b/aws/resource_aws_networkfirewall_firewall_policy_test.go index 458c85951c5..fda74cfc675 100644 --- a/aws/resource_aws_networkfirewall_firewall_policy_test.go +++ b/aws/resource_aws_networkfirewall_firewall_policy_test.go @@ -15,7 +15,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/networkfirewall/finder" - "github.com/terraform-providers/terraform-provider-aws/aws/internal/tfawsresource" ) func init() { @@ -95,9 +94,9 @@ func TestAccAwsNetworkFirewallFirewallPolicy_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "description", ""), resource.TestCheckResourceAttr(resourceName, "firewall_policy.#", "1"), resource.TestCheckResourceAttr(resourceName, "firewall_policy.0.stateless_fragment_default_actions.#", "1"), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "firewall_policy.0.stateless_fragment_default_actions.*", "aws:drop"), + resource.TestCheckTypeSetElemAttr(resourceName, "firewall_policy.0.stateless_fragment_default_actions.*", "aws:drop"), resource.TestCheckResourceAttr(resourceName, "firewall_policy.0.stateless_default_actions.#", "1"), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "firewall_policy.0.stateless_default_actions.*", "aws:pass"), + resource.TestCheckTypeSetElemAttr(resourceName, "firewall_policy.0.stateless_default_actions.*", "aws:pass"), resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), ), @@ -127,7 +126,7 @@ func TestAccAwsNetworkFirewallFirewallPolicy_statefulRuleGroupReference(t *testi testAccCheckAwsNetworkFirewallFirewallPolicyExists(resourceName), resource.TestCheckResourceAttr(resourceName, "firewall_policy.#", "1"), resource.TestCheckResourceAttr(resourceName, "firewall_policy.0.stateful_rule_group_reference.#", "1"), - tfawsresource.TestCheckTypeSetElemAttrPair(resourceName, "firewall_policy.0.stateful_rule_group_reference.*.resource_arn", ruleGroupResourceName, "arn"), + resource.TestCheckTypeSetElemAttrPair(resourceName, "firewall_policy.0.stateful_rule_group_reference.*.resource_arn", ruleGroupResourceName, "arn"), ), }, { @@ -161,7 +160,7 @@ func TestAccAwsNetworkFirewallFirewallPolicy_updateStatefulRuleGroupReference(t testAccCheckAwsNetworkFirewallFirewallPolicyExists(resourceName), resource.TestCheckResourceAttr(resourceName, "firewall_policy.#", "1"), resource.TestCheckResourceAttr(resourceName, "firewall_policy.0.stateful_rule_group_reference.#", "1"), - tfawsresource.TestCheckTypeSetElemAttrPair(resourceName, "firewall_policy.0.stateful_rule_group_reference.*.resource_arn", ruleGroupResourceName, "arn"), + resource.TestCheckTypeSetElemAttrPair(resourceName, "firewall_policy.0.stateful_rule_group_reference.*.resource_arn", ruleGroupResourceName, "arn"), ), }, { @@ -196,8 +195,8 @@ func TestAccAwsNetworkFirewallFirewallPolicy_multipleStatefulRuleGroupReferences testAccCheckAwsNetworkFirewallFirewallPolicyExists(resourceName), resource.TestCheckResourceAttr(resourceName, "firewall_policy.#", "1"), resource.TestCheckResourceAttr(resourceName, "firewall_policy.0.stateful_rule_group_reference.#", "2"), - tfawsresource.TestCheckTypeSetElemAttrPair(resourceName, "firewall_policy.0.stateful_rule_group_reference.*.resource_arn", ruleGroupResourceName1, "arn"), - tfawsresource.TestCheckTypeSetElemAttrPair(resourceName, "firewall_policy.0.stateful_rule_group_reference.*.resource_arn", ruleGroupResourceName2, "arn"), + resource.TestCheckTypeSetElemAttrPair(resourceName, "firewall_policy.0.stateful_rule_group_reference.*.resource_arn", ruleGroupResourceName1, "arn"), + resource.TestCheckTypeSetElemAttrPair(resourceName, "firewall_policy.0.stateful_rule_group_reference.*.resource_arn", ruleGroupResourceName2, "arn"), ), }, { @@ -206,7 +205,7 @@ func TestAccAwsNetworkFirewallFirewallPolicy_multipleStatefulRuleGroupReferences testAccCheckAwsNetworkFirewallFirewallPolicyExists(resourceName), resource.TestCheckResourceAttr(resourceName, "firewall_policy.#", "1"), resource.TestCheckResourceAttr(resourceName, "firewall_policy.0.stateful_rule_group_reference.#", "1"), - tfawsresource.TestCheckTypeSetElemAttrPair(resourceName, "firewall_policy.0.stateful_rule_group_reference.*.resource_arn", ruleGroupResourceName1, "arn"), + resource.TestCheckTypeSetElemAttrPair(resourceName, "firewall_policy.0.stateful_rule_group_reference.*.resource_arn", ruleGroupResourceName1, "arn"), ), }, { @@ -234,8 +233,8 @@ func TestAccAwsNetworkFirewallFirewallPolicy_statelessRuleGroupReference(t *test testAccCheckAwsNetworkFirewallFirewallPolicyExists(resourceName), resource.TestCheckResourceAttr(resourceName, "firewall_policy.#", "1"), resource.TestCheckResourceAttr(resourceName, "firewall_policy.0.stateless_rule_group_reference.#", "1"), - tfawsresource.TestCheckTypeSetElemAttrPair(resourceName, "firewall_policy.0.stateless_rule_group_reference.*.resource_arn", ruleGroupResourceName, "arn"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "firewall_policy.0.stateless_rule_group_reference.*", map[string]string{ + resource.TestCheckTypeSetElemAttrPair(resourceName, "firewall_policy.0.stateless_rule_group_reference.*.resource_arn", ruleGroupResourceName, "arn"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "firewall_policy.0.stateless_rule_group_reference.*", map[string]string{ "priority": "20", }), ), @@ -246,7 +245,7 @@ func TestAccAwsNetworkFirewallFirewallPolicy_statelessRuleGroupReference(t *test testAccCheckAwsNetworkFirewallFirewallPolicyExists(resourceName), resource.TestCheckResourceAttr(resourceName, "firewall_policy.#", "1"), resource.TestCheckResourceAttr(resourceName, "firewall_policy.0.stateless_rule_group_reference.#", "1"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "firewall_policy.0.stateless_rule_group_reference.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "firewall_policy.0.stateless_rule_group_reference.*", map[string]string{ "priority": "1", }), ), @@ -281,8 +280,8 @@ func TestAccAwsNetworkFirewallFirewallPolicy_updateStatelessRuleGroupReference(t Check: resource.ComposeTestCheckFunc( testAccCheckAwsNetworkFirewallFirewallPolicyExists(resourceName), resource.TestCheckResourceAttr(resourceName, "firewall_policy.#", "1"), - tfawsresource.TestCheckTypeSetElemAttrPair(resourceName, "firewall_policy.0.stateless_rule_group_reference.*.resource_arn", ruleGroupResourceName, "arn"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "firewall_policy.0.stateless_rule_group_reference.*", map[string]string{ + resource.TestCheckTypeSetElemAttrPair(resourceName, "firewall_policy.0.stateless_rule_group_reference.*.resource_arn", ruleGroupResourceName, "arn"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "firewall_policy.0.stateless_rule_group_reference.*", map[string]string{ "priority": "20", }), ), @@ -321,12 +320,12 @@ func TestAccAwsNetworkFirewallFirewallPolicy_multipleStatelessRuleGroupReference testAccCheckAwsNetworkFirewallFirewallPolicyExists(resourceName), resource.TestCheckResourceAttr(resourceName, "firewall_policy.#", "1"), resource.TestCheckResourceAttr(resourceName, "firewall_policy.0.stateless_rule_group_reference.#", "2"), - tfawsresource.TestCheckTypeSetElemAttrPair(resourceName, "firewall_policy.0.stateless_rule_group_reference.*.resource_arn", ruleGroupResourceName1, "arn"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "firewall_policy.0.stateless_rule_group_reference.*", map[string]string{ + resource.TestCheckTypeSetElemAttrPair(resourceName, "firewall_policy.0.stateless_rule_group_reference.*.resource_arn", ruleGroupResourceName1, "arn"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "firewall_policy.0.stateless_rule_group_reference.*", map[string]string{ "priority": "1", }), - tfawsresource.TestCheckTypeSetElemAttrPair(resourceName, "firewall_policy.0.stateless_rule_group_reference.*.resource_arn", ruleGroupResourceName2, "arn"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "firewall_policy.0.stateless_rule_group_reference.*", map[string]string{ + resource.TestCheckTypeSetElemAttrPair(resourceName, "firewall_policy.0.stateless_rule_group_reference.*.resource_arn", ruleGroupResourceName2, "arn"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "firewall_policy.0.stateless_rule_group_reference.*", map[string]string{ "priority": "2", }), ), @@ -337,10 +336,10 @@ func TestAccAwsNetworkFirewallFirewallPolicy_multipleStatelessRuleGroupReference testAccCheckAwsNetworkFirewallFirewallPolicyExists(resourceName), resource.TestCheckResourceAttr(resourceName, "firewall_policy.#", "1"), resource.TestCheckResourceAttr(resourceName, "firewall_policy.0.stateless_rule_group_reference.#", "1"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "firewall_policy.0.stateless_rule_group_reference.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "firewall_policy.0.stateless_rule_group_reference.*", map[string]string{ "priority": "1", }), - tfawsresource.TestCheckTypeSetElemAttrPair(resourceName, "firewall_policy.0.stateless_rule_group_reference.*.resource_arn", ruleGroupResourceName1, "arn"), + resource.TestCheckTypeSetElemAttrPair(resourceName, "firewall_policy.0.stateless_rule_group_reference.*.resource_arn", ruleGroupResourceName1, "arn"), ), }, { @@ -367,7 +366,7 @@ func TestAccAwsNetworkFirewallFirewallPolicy_statelessCustomAction(t *testing.T) testAccCheckAwsNetworkFirewallFirewallPolicyExists(resourceName), resource.TestCheckResourceAttr(resourceName, "firewall_policy.#", "1"), resource.TestCheckResourceAttr(resourceName, "firewall_policy.0.stateless_custom_action.#", "1"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "firewall_policy.0.stateless_custom_action.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "firewall_policy.0.stateless_custom_action.*", map[string]string{ "action_definition.#": "1", "action_definition.0.publish_metric_action.#": "1", "action_definition.0.publish_metric_action.0.dimension.#": "1", @@ -405,7 +404,7 @@ func TestAccAwsNetworkFirewallFirewallPolicy_updateStatelessCustomAction(t *test testAccCheckAwsNetworkFirewallFirewallPolicyExists(resourceName), resource.TestCheckResourceAttr(resourceName, "firewall_policy.#", "1"), resource.TestCheckResourceAttr(resourceName, "firewall_policy.0.stateless_custom_action.#", "1"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "firewall_policy.0.stateless_custom_action.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "firewall_policy.0.stateless_custom_action.*", map[string]string{ "action_name": "CustomAction", "action_definition.#": "1", "action_definition.0.publish_metric_action.#": "1", @@ -419,7 +418,7 @@ func TestAccAwsNetworkFirewallFirewallPolicy_updateStatelessCustomAction(t *test testAccCheckAwsNetworkFirewallFirewallPolicyExists(resourceName), resource.TestCheckResourceAttr(resourceName, "firewall_policy.#", "1"), resource.TestCheckResourceAttr(resourceName, "firewall_policy.0.stateless_custom_action.#", "1"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "firewall_policy.0.stateless_custom_action.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "firewall_policy.0.stateless_custom_action.*", map[string]string{ "action_name": "updated", "action_definition.#": "1", "action_definition.0.publish_metric_action.#": "1", @@ -458,13 +457,13 @@ func TestAccAwsNetworkFirewallFirewallPolicy_multipleStatelessCustomActions(t *t testAccCheckAwsNetworkFirewallFirewallPolicyExists(resourceName), resource.TestCheckResourceAttr(resourceName, "firewall_policy.#", "1"), resource.TestCheckResourceAttr(resourceName, "firewall_policy.0.stateless_custom_action.#", "2"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "firewall_policy.0.stateless_custom_action.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "firewall_policy.0.stateless_custom_action.*", map[string]string{ "action_name": "CustomAction", "action_definition.#": "1", "action_definition.0.publish_metric_action.#": "1", "action_definition.0.publish_metric_action.0.dimension.#": "1", }), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "firewall_policy.0.stateless_custom_action.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "firewall_policy.0.stateless_custom_action.*", map[string]string{ "action_name": "CustomAction2", "action_definition.#": "1", "action_definition.0.publish_metric_action.#": "1", @@ -478,7 +477,7 @@ func TestAccAwsNetworkFirewallFirewallPolicy_multipleStatelessCustomActions(t *t testAccCheckAwsNetworkFirewallFirewallPolicyExists(resourceName), resource.TestCheckResourceAttr(resourceName, "firewall_policy.#", "1"), resource.TestCheckResourceAttr(resourceName, "firewall_policy.0.stateless_custom_action.#", "1"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "firewall_policy.0.stateless_custom_action.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "firewall_policy.0.stateless_custom_action.*", map[string]string{ "action_name": "CustomAction", "action_definition.#": "1", "action_definition.0.publish_metric_action.#": "1", @@ -511,8 +510,8 @@ func TestAccAwsNetworkFirewallFirewallPolicy_statefulRuleGroupReferenceAndCustom testAccCheckAwsNetworkFirewallFirewallPolicyExists(resourceName), resource.TestCheckResourceAttr(resourceName, "firewall_policy.#", "1"), resource.TestCheckResourceAttr(resourceName, "firewall_policy.0.stateful_rule_group_reference.#", "1"), - tfawsresource.TestCheckTypeSetElemAttrPair(resourceName, "firewall_policy.0.stateful_rule_group_reference.*.resource_arn", ruleGroupResourceName, "arn"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "firewall_policy.0.stateless_custom_action.*", map[string]string{ + resource.TestCheckTypeSetElemAttrPair(resourceName, "firewall_policy.0.stateful_rule_group_reference.*.resource_arn", ruleGroupResourceName, "arn"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "firewall_policy.0.stateless_custom_action.*", map[string]string{ "action_name": "CustomAction", "action_definition.#": "1", "action_definition.0.publish_metric_action.#": "1", @@ -526,7 +525,7 @@ func TestAccAwsNetworkFirewallFirewallPolicy_statefulRuleGroupReferenceAndCustom testAccCheckAwsNetworkFirewallFirewallPolicyExists(resourceName), resource.TestCheckResourceAttr(resourceName, "firewall_policy.#", "1"), resource.TestCheckResourceAttr(resourceName, "firewall_policy.0.stateful_rule_group_reference.#", "1"), - tfawsresource.TestCheckTypeSetElemAttrPair(resourceName, "firewall_policy.0.stateful_rule_group_reference.*.resource_arn", ruleGroupResourceName, "arn"), + resource.TestCheckTypeSetElemAttrPair(resourceName, "firewall_policy.0.stateful_rule_group_reference.*.resource_arn", ruleGroupResourceName, "arn"), ), }, { diff --git a/aws/resource_aws_networkfirewall_firewall_test.go b/aws/resource_aws_networkfirewall_firewall_test.go index 97db1dd6dc9..e32f099cbfd 100644 --- a/aws/resource_aws_networkfirewall_firewall_test.go +++ b/aws/resource_aws_networkfirewall_firewall_test.go @@ -16,7 +16,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/networkfirewall/finder" - "github.com/terraform-providers/terraform-provider-aws/aws/internal/tfawsresource" ) func init() { @@ -108,7 +107,7 @@ func TestAccAwsNetworkFirewallFirewall_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttrPair(resourceName, "vpc_id", vpcResourceName, "id"), resource.TestCheckResourceAttr(resourceName, "subnet_mapping.#", "1"), - tfawsresource.TestCheckTypeSetElemAttrPair(resourceName, "subnet_mapping.*.subnet_id", subnetResourceName, "id"), + resource.TestCheckTypeSetElemAttrPair(resourceName, "subnet_mapping.*.subnet_id", subnetResourceName, "id"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttrSet(resourceName, "update_token"), ), @@ -218,7 +217,7 @@ func TestAccAwsNetworkFirewallFirewall_subnetMappings_updateSubnet(t *testing.T) Check: resource.ComposeTestCheckFunc( testAccCheckAwsNetworkFirewallFirewallExists(resourceName), resource.TestCheckResourceAttr(resourceName, "subnet_mapping.#", "1"), - tfawsresource.TestCheckTypeSetElemAttrPair(resourceName, "subnet_mapping.*.subnet_id", subnetResourceName, "id"), + resource.TestCheckTypeSetElemAttrPair(resourceName, "subnet_mapping.*.subnet_id", subnetResourceName, "id"), ), }, { @@ -233,7 +232,7 @@ func TestAccAwsNetworkFirewallFirewall_subnetMappings_updateSubnet(t *testing.T) }), resource.TestCheckTypeSetElemAttrPair(resourceName, "firewall_status.0.sync_states.*.attachment.0.subnet_id", updateSubnetResourceName, "id"), resource.TestCheckResourceAttr(resourceName, "subnet_mapping.#", "1"), - tfawsresource.TestCheckTypeSetElemAttrPair(resourceName, "subnet_mapping.*.subnet_id", updateSubnetResourceName, "id"), + resource.TestCheckTypeSetElemAttrPair(resourceName, "subnet_mapping.*.subnet_id", updateSubnetResourceName, "id"), ), }, { @@ -261,7 +260,7 @@ func TestAccAwsNetworkFirewallFirewall_subnetMappings_updateMultipleSubnets(t *t Check: resource.ComposeTestCheckFunc( testAccCheckAwsNetworkFirewallFirewallExists(resourceName), resource.TestCheckResourceAttr(resourceName, "subnet_mapping.#", "1"), - tfawsresource.TestCheckTypeSetElemAttrPair(resourceName, "subnet_mapping.*.subnet_id", subnetResourceName, "id"), + resource.TestCheckTypeSetElemAttrPair(resourceName, "subnet_mapping.*.subnet_id", subnetResourceName, "id"), ), }, { @@ -275,8 +274,8 @@ func TestAccAwsNetworkFirewallFirewall_subnetMappings_updateMultipleSubnets(t *t resource.TestCheckTypeSetElemAttrPair(resourceName, "firewall_status.0.sync_states.*.availability_zone", updateSubnetResourceName, "availability_zone"), resource.TestCheckTypeSetElemAttrPair(resourceName, "firewall_status.0.sync_states.*.attachment.0.subnet_id", updateSubnetResourceName, "id"), resource.TestCheckResourceAttr(resourceName, "subnet_mapping.#", "2"), - tfawsresource.TestCheckTypeSetElemAttrPair(resourceName, "subnet_mapping.*.subnet_id", subnetResourceName, "id"), - tfawsresource.TestCheckTypeSetElemAttrPair(resourceName, "subnet_mapping.*.subnet_id", updateSubnetResourceName, "id"), + resource.TestCheckTypeSetElemAttrPair(resourceName, "subnet_mapping.*.subnet_id", subnetResourceName, "id"), + resource.TestCheckTypeSetElemAttrPair(resourceName, "subnet_mapping.*.subnet_id", updateSubnetResourceName, "id"), ), }, { @@ -291,7 +290,7 @@ func TestAccAwsNetworkFirewallFirewall_subnetMappings_updateMultipleSubnets(t *t }), resource.TestCheckTypeSetElemAttrPair(resourceName, "firewall_status.0.sync_states.*.attachment.0.subnet_id", subnetResourceName, "id"), resource.TestCheckResourceAttr(resourceName, "subnet_mapping.#", "1"), - tfawsresource.TestCheckTypeSetElemAttrPair(resourceName, "subnet_mapping.*.subnet_id", subnetResourceName, "id"), + resource.TestCheckTypeSetElemAttrPair(resourceName, "subnet_mapping.*.subnet_id", subnetResourceName, "id"), ), }, { diff --git a/aws/resource_aws_networkfirewall_logging_configuration_test.go b/aws/resource_aws_networkfirewall_logging_configuration_test.go index 43e07db60c9..2eb9f866665 100644 --- a/aws/resource_aws_networkfirewall_logging_configuration_test.go +++ b/aws/resource_aws_networkfirewall_logging_configuration_test.go @@ -15,7 +15,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/networkfirewall/finder" - "github.com/terraform-providers/terraform-provider-aws/aws/internal/tfawsresource" ) func init() { @@ -92,7 +91,7 @@ func TestAccAwsNetworkFirewallLoggingConfiguration_cloudwatchLogDestination_logG Check: resource.ComposeTestCheckFunc( testAccCheckAwsNetworkFirewallLoggingConfigurationExists(resourceName), resource.TestCheckResourceAttr(resourceName, "logging_configuration.#", "1"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ "log_destination.%": "1", "log_destination.logGroup": logGroupName, "log_destination_type": networkfirewall.LogDestinationTypeCloudWatchLogs, @@ -104,7 +103,7 @@ func TestAccAwsNetworkFirewallLoggingConfiguration_cloudwatchLogDestination_logG Check: resource.ComposeTestCheckFunc( testAccCheckAwsNetworkFirewallLoggingConfigurationExists(resourceName), resource.TestCheckResourceAttr(resourceName, "logging_configuration.#", "1"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ "log_destination.%": "1", "log_destination.logGroup": updatedLogGroupName, "log_destination_type": networkfirewall.LogDestinationTypeCloudWatchLogs, @@ -135,7 +134,7 @@ func TestAccAwsNetworkFirewallLoggingConfiguration_cloudwatchLogDestination_logT Check: resource.ComposeTestCheckFunc( testAccCheckAwsNetworkFirewallLoggingConfigurationExists(resourceName), resource.TestCheckResourceAttr(resourceName, "logging_configuration.#", "1"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ "log_type": networkfirewall.LogTypeFlow, }), ), @@ -145,7 +144,7 @@ func TestAccAwsNetworkFirewallLoggingConfiguration_cloudwatchLogDestination_logT Check: resource.ComposeTestCheckFunc( testAccCheckAwsNetworkFirewallLoggingConfigurationExists(resourceName), resource.TestCheckResourceAttr(resourceName, "logging_configuration.#", "1"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ "log_type": networkfirewall.LogTypeAlert, }), ), @@ -175,7 +174,7 @@ func TestAccAwsNetworkFirewallLoggingConfiguration_kinesisLogDestination_deliver Check: resource.ComposeTestCheckFunc( testAccCheckAwsNetworkFirewallLoggingConfigurationExists(resourceName), resource.TestCheckResourceAttr(resourceName, "logging_configuration.#", "1"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ "log_destination.%": "1", "log_destination.deliveryStream": streamName, "log_destination_type": networkfirewall.LogDestinationTypeKinesisDataFirehose, @@ -187,7 +186,7 @@ func TestAccAwsNetworkFirewallLoggingConfiguration_kinesisLogDestination_deliver Check: resource.ComposeTestCheckFunc( testAccCheckAwsNetworkFirewallLoggingConfigurationExists(resourceName), resource.TestCheckResourceAttr(resourceName, "logging_configuration.#", "1"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ "log_destination.%": "1", "log_destination.deliveryStream": updatedStreamName, "log_destination_type": networkfirewall.LogDestinationTypeKinesisDataFirehose, @@ -218,7 +217,7 @@ func TestAccAwsNetworkFirewallLoggingConfiguration_kinesisLogDestination_logType Check: resource.ComposeTestCheckFunc( testAccCheckAwsNetworkFirewallLoggingConfigurationExists(resourceName), resource.TestCheckResourceAttr(resourceName, "logging_configuration.#", "1"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ "log_type": networkfirewall.LogTypeFlow, }), ), @@ -228,7 +227,7 @@ func TestAccAwsNetworkFirewallLoggingConfiguration_kinesisLogDestination_logType Check: resource.ComposeTestCheckFunc( testAccCheckAwsNetworkFirewallLoggingConfigurationExists(resourceName), resource.TestCheckResourceAttr(resourceName, "logging_configuration.#", "1"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ "log_type": networkfirewall.LogTypeAlert, }), ), @@ -259,7 +258,7 @@ func TestAccAwsNetworkFirewallLoggingConfiguration_s3LogDestination_bucketName(t Check: resource.ComposeTestCheckFunc( testAccCheckAwsNetworkFirewallLoggingConfigurationExists(resourceName), resource.TestCheckResourceAttr(resourceName, "logging_configuration.#", "1"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ "log_destination.%": "1", "log_destination.bucketName": bucketName, }), @@ -270,7 +269,7 @@ func TestAccAwsNetworkFirewallLoggingConfiguration_s3LogDestination_bucketName(t Check: resource.ComposeTestCheckFunc( testAccCheckAwsNetworkFirewallLoggingConfigurationExists(resourceName), resource.TestCheckResourceAttr(resourceName, "logging_configuration.#", "1"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ "log_destination.%": "1", "log_destination.bucketName": updatedBucketName, }), @@ -301,7 +300,7 @@ func TestAccAwsNetworkFirewallLoggingConfiguration_s3LogDestination_logType(t *t Check: resource.ComposeTestCheckFunc( testAccCheckAwsNetworkFirewallLoggingConfigurationExists(resourceName), resource.TestCheckResourceAttr(resourceName, "logging_configuration.#", "1"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ "log_type": networkfirewall.LogTypeFlow, }), ), @@ -311,7 +310,7 @@ func TestAccAwsNetworkFirewallLoggingConfiguration_s3LogDestination_logType(t *t Check: resource.ComposeTestCheckFunc( testAccCheckAwsNetworkFirewallLoggingConfigurationExists(resourceName), resource.TestCheckResourceAttr(resourceName, "logging_configuration.#", "1"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ "log_type": networkfirewall.LogTypeAlert, }), ), @@ -341,7 +340,7 @@ func TestAccAwsNetworkFirewallLoggingConfiguration_s3LogDestination_prefix(t *te Check: resource.ComposeTestCheckFunc( testAccCheckAwsNetworkFirewallLoggingConfigurationExists(resourceName), resource.TestCheckResourceAttr(resourceName, "logging_configuration.#", "1"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ "log_destination.%": "1", "log_destination.bucketName": bucketName, }), @@ -352,7 +351,7 @@ func TestAccAwsNetworkFirewallLoggingConfiguration_s3LogDestination_prefix(t *te Check: resource.ComposeTestCheckFunc( testAccCheckAwsNetworkFirewallLoggingConfigurationExists(resourceName), resource.TestCheckResourceAttr(resourceName, "logging_configuration.#", "1"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ "log_destination.%": "2", "log_destination.bucketName": bucketName, "log_destination.prefix": "update-prefix", @@ -420,7 +419,7 @@ func TestAccAwsNetworkFirewallLoggingConfiguration_updateLogDestinationType(t *t Check: resource.ComposeTestCheckFunc( testAccCheckAwsNetworkFirewallLoggingConfigurationExists(resourceName), resource.TestCheckResourceAttr(resourceName, "logging_configuration.#", "1"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ "log_destination.%": "1", "log_destination.logGroup": logGroupName, "log_destination_type": networkfirewall.LogDestinationTypeCloudWatchLogs, @@ -433,7 +432,7 @@ func TestAccAwsNetworkFirewallLoggingConfiguration_updateLogDestinationType(t *t Check: resource.ComposeTestCheckFunc( testAccCheckAwsNetworkFirewallLoggingConfigurationExists(resourceName), resource.TestCheckResourceAttr(resourceName, "logging_configuration.#", "1"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ "log_destination.%": "1", "log_destination.deliveryStream": streamName, "log_destination_type": networkfirewall.LogDestinationTypeKinesisDataFirehose, @@ -446,7 +445,7 @@ func TestAccAwsNetworkFirewallLoggingConfiguration_updateLogDestinationType(t *t Check: resource.ComposeTestCheckFunc( testAccCheckAwsNetworkFirewallLoggingConfigurationExists(resourceName), resource.TestCheckResourceAttr(resourceName, "logging_configuration.#", "1"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ "log_destination_type": networkfirewall.LogDestinationTypeS3, "log_type": networkfirewall.LogTypeFlow, }), @@ -484,13 +483,13 @@ func TestAccAwsNetworkFirewallLoggingConfiguration_updateToMultipleLogDestinatio testAccCheckAwsNetworkFirewallLoggingConfigurationExists(resourceName), resource.TestCheckResourceAttr(resourceName, "logging_configuration.#", "1"), resource.TestCheckResourceAttr(resourceName, "logging_configuration.0.log_destination_config.#", "2"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ "log_destination.%": "1", "log_destination.deliveryStream": streamName, "log_destination_type": networkfirewall.LogDestinationTypeKinesisDataFirehose, "log_type": networkfirewall.LogTypeFlow, }), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ "log_destination.%": "1", "log_destination.bucketName": bucketName, "log_destination_type": networkfirewall.LogDestinationTypeS3, @@ -532,13 +531,13 @@ func TestAccAwsNetworkFirewallLoggingConfiguration_updateToSingleAlertTypeLogDes testAccCheckAwsNetworkFirewallLoggingConfigurationExists(resourceName), resource.TestCheckResourceAttr(resourceName, "logging_configuration.#", "1"), resource.TestCheckResourceAttr(resourceName, "logging_configuration.0.log_destination_config.#", "2"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ "log_destination.%": "1", "log_destination.logGroup": logGroupName, "log_destination_type": networkfirewall.LogDestinationTypeCloudWatchLogs, "log_type": networkfirewall.LogTypeFlow, }), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ "log_destination.%": "1", "log_destination.bucketName": bucketName, "log_destination_type": networkfirewall.LogDestinationTypeS3, @@ -552,7 +551,7 @@ func TestAccAwsNetworkFirewallLoggingConfiguration_updateToSingleAlertTypeLogDes testAccCheckAwsNetworkFirewallLoggingConfigurationExists(resourceName), resource.TestCheckResourceAttr(resourceName, "logging_configuration.#", "1"), resource.TestCheckResourceAttr(resourceName, "logging_configuration.0.log_destination_config.#", "1"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ "log_destination.%": "1", "log_destination.bucketName": bucketName, "log_destination_type": networkfirewall.LogDestinationTypeS3, @@ -586,13 +585,13 @@ func TestAccAwsNetworkFirewallLoggingConfiguration_updateToSingleFlowTypeLogDest testAccCheckAwsNetworkFirewallLoggingConfigurationExists(resourceName), resource.TestCheckResourceAttr(resourceName, "logging_configuration.#", "1"), resource.TestCheckResourceAttr(resourceName, "logging_configuration.0.log_destination_config.#", "2"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ "log_destination.%": "1", "log_destination.logGroup": logGroupName, "log_destination_type": networkfirewall.LogDestinationTypeCloudWatchLogs, "log_type": networkfirewall.LogTypeFlow, }), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ "log_destination.%": "1", "log_destination.bucketName": bucketName, "log_destination_type": networkfirewall.LogDestinationTypeS3, @@ -606,7 +605,7 @@ func TestAccAwsNetworkFirewallLoggingConfiguration_updateToSingleFlowTypeLogDest testAccCheckAwsNetworkFirewallLoggingConfigurationExists(resourceName), resource.TestCheckResourceAttr(resourceName, "logging_configuration.#", "1"), resource.TestCheckResourceAttr(resourceName, "logging_configuration.0.log_destination_config.#", "1"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{ "log_destination.%": "1", "log_destination.logGroup": logGroupName, "log_destination_type": networkfirewall.LogDestinationTypeCloudWatchLogs, diff --git a/aws/resource_aws_networkfirewall_rule_group_test.go b/aws/resource_aws_networkfirewall_rule_group_test.go index 300bc6ce00b..5ee23c0acf8 100644 --- a/aws/resource_aws_networkfirewall_rule_group_test.go +++ b/aws/resource_aws_networkfirewall_rule_group_test.go @@ -15,7 +15,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/networkfirewall/finder" - "github.com/terraform-providers/terraform-provider-aws/aws/internal/tfawsresource" ) func init() { @@ -100,9 +99,9 @@ func TestAccAwsNetworkFirewallRuleGroup_basic_rulesSourceList(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "rule_group.0.rules_source.0.rules_source_list.#", "1"), resource.TestCheckResourceAttr(resourceName, "rule_group.0.rules_source.0.rules_source_list.0.generated_rules_type", networkfirewall.GeneratedRulesTypeAllowlist), resource.TestCheckResourceAttr(resourceName, "rule_group.0.rules_source.0.rules_source_list.0.target_types.#", "1"), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rules_source.0.rules_source_list.0.target_types.*", networkfirewall.TargetTypeHttpHost), + resource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rules_source.0.rules_source_list.0.target_types.*", networkfirewall.TargetTypeHttpHost), resource.TestCheckResourceAttr(resourceName, "rule_group.0.rules_source.0.rules_source_list.0.targets.#", "1"), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rules_source.0.rules_source_list.0.targets.*", "test.example.com"), + resource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rules_source.0.rules_source_list.0.targets.*", "test.example.com"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), ), }, @@ -135,7 +134,7 @@ func TestAccAwsNetworkFirewallRuleGroup_basic_statefulRule(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "rule_group.#", "1"), resource.TestCheckResourceAttr(resourceName, "rule_group.0.rules_source.#", "1"), resource.TestCheckResourceAttr(resourceName, "rule_group.0.rules_source.0.stateful_rule.#", "1"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "rule_group.0.rules_source.0.stateful_rule.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "rule_group.0.rules_source.0.stateful_rule.*", map[string]string{ "action": networkfirewall.StatefulActionPass, "header.#": "1", "header.0.destination": "124.1.1.24/32", @@ -178,7 +177,7 @@ func TestAccAwsNetworkFirewallRuleGroup_basic_statelessRule(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "rule_group.#", "1"), resource.TestCheckResourceAttr(resourceName, "rule_group.0.rules_source.#", "1"), resource.TestCheckResourceAttr(resourceName, "rule_group.0.rules_source.0.stateless_rules_and_custom_actions.#", "1"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "rule_group.0.rules_source.0.stateless_rules_and_custom_actions.0.stateless_rule.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "rule_group.0.rules_source.0.stateless_rules_and_custom_actions.0.stateless_rule.*", map[string]string{ "priority": "1", "rule_definition.#": "1", "rule_definition.0.actions.#": "1", @@ -186,7 +185,7 @@ func TestAccAwsNetworkFirewallRuleGroup_basic_statelessRule(t *testing.T) { "rule_definition.0.match_attributes.0.destination.#": "1", "rule_definition.0.match_attributes.0.source.#": "1", }), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rules_source.0.stateless_rules_and_custom_actions.0.stateless_rule.*.rule_definition.0.actions.*", "aws:drop"), + resource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rules_source.0.stateless_rules_and_custom_actions.0.stateless_rule.*.rule_definition.0.actions.*", "aws:drop"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), ), }, @@ -255,7 +254,7 @@ func TestAccAwsNetworkFirewallRuleGroup_statelessRuleWithCustomAction(t *testing resource.TestCheckResourceAttr(resourceName, "rule_group.#", "1"), resource.TestCheckResourceAttr(resourceName, "rule_group.0.rules_source.#", "1"), resource.TestCheckResourceAttr(resourceName, "rule_group.0.rules_source.0.stateless_rules_and_custom_actions.#", "1"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "rule_group.0.rules_source.0.stateless_rules_and_custom_actions.0.stateless_rule.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "rule_group.0.rules_source.0.stateless_rules_and_custom_actions.0.stateless_rule.*", map[string]string{ "priority": "1", "rule_definition.#": "1", "rule_definition.0.actions.#": "2", @@ -263,9 +262,9 @@ func TestAccAwsNetworkFirewallRuleGroup_statelessRuleWithCustomAction(t *testing "rule_definition.0.match_attributes.0.destination.#": "1", "rule_definition.0.match_attributes.0.source.#": "1", }), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rules_source.0.stateless_rules_and_custom_actions.0.stateless_rule.*.rule_definition.0.actions.*", "aws:pass"), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rules_source.0.stateless_rules_and_custom_actions.0.stateless_rule.*.rule_definition.0.actions.*", "example"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "rule_group.0.rules_source.0.stateless_rules_and_custom_actions.0.custom_action.*", map[string]string{ + resource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rules_source.0.stateless_rules_and_custom_actions.0.stateless_rule.*.rule_definition.0.actions.*", "aws:pass"), + resource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rules_source.0.stateless_rules_and_custom_actions.0.stateless_rule.*.rule_definition.0.actions.*", "example"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "rule_group.0.rules_source.0.stateless_rules_and_custom_actions.0.custom_action.*", map[string]string{ "action_name": "example", "action_definition.#": "1", "action_definition.0.publish_metric_action.#": "1", @@ -310,11 +309,11 @@ func TestAccAwsNetworkFirewallRuleGroup_updateRulesSourceList(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "rule_group.0.rules_source.0.rules_source_list.#", "1"), resource.TestCheckResourceAttr(resourceName, "rule_group.0.rules_source.0.rules_source_list.0.generated_rules_type", networkfirewall.GeneratedRulesTypeDenylist), resource.TestCheckResourceAttr(resourceName, "rule_group.0.rules_source.0.rules_source_list.0.target_types.#", "2"), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rules_source.0.rules_source_list.0.target_types.*", networkfirewall.TargetTypeHttpHost), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rules_source.0.rules_source_list.0.target_types.*", networkfirewall.TargetTypeTlsSni), + resource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rules_source.0.rules_source_list.0.target_types.*", networkfirewall.TargetTypeHttpHost), + resource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rules_source.0.rules_source_list.0.target_types.*", networkfirewall.TargetTypeTlsSni), resource.TestCheckResourceAttr(resourceName, "rule_group.0.rules_source.0.rules_source_list.0.targets.#", "2"), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rules_source.0.rules_source_list.0.targets.*", "test.example.com"), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rules_source.0.rules_source_list.0.targets.*", "test2.example.com"), + resource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rules_source.0.rules_source_list.0.targets.*", "test.example.com"), + resource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rules_source.0.rules_source_list.0.targets.*", "test2.example.com"), ), }, { @@ -343,13 +342,13 @@ func TestAccAwsNetworkFirewallRuleGroup_rulesSourceAndRuleVariables(t *testing.T resource.TestCheckResourceAttr(resourceName, "rule_group.0.rule_variables.#", "1"), resource.TestCheckResourceAttr(resourceName, "rule_group.0.rules_source.#", "1"), resource.TestCheckResourceAttr(resourceName, "rule_group.0.rule_variables.0.ip_sets.#", "1"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "rule_group.0.rule_variables.0.ip_sets.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "rule_group.0.rule_variables.0.ip_sets.*", map[string]string{ "key": "example", "ip_set.#": "1", "ip_set.0.definition.#": "2", }), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rule_variables.0.ip_sets.*.ip_set.0.definition.*", "10.0.0.0/16"), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rule_variables.0.ip_sets.*.ip_set.0.definition.*", "10.0.1.0/24"), + resource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rule_variables.0.ip_sets.*.ip_set.0.definition.*", "10.0.0.0/16"), + resource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rule_variables.0.ip_sets.*.ip_set.0.definition.*", "10.0.1.0/24"), ), }, { @@ -361,27 +360,27 @@ func TestAccAwsNetworkFirewallRuleGroup_rulesSourceAndRuleVariables(t *testing.T resource.TestCheckResourceAttr(resourceName, "rule_group.0.rules_source.#", "1"), resource.TestCheckResourceAttr(resourceName, "rule_group.0.rule_variables.0.ip_sets.#", "2"), resource.TestCheckResourceAttr(resourceName, "rule_group.0.rule_variables.0.port_sets.#", "1"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "rule_group.0.rule_variables.0.ip_sets.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "rule_group.0.rule_variables.0.ip_sets.*", map[string]string{ "key": "example", "ip_set.#": "1", "ip_set.0.definition.#": "3", }), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rule_variables.0.ip_sets.*.ip_set.0.definition.*", "10.0.0.0/16"), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rule_variables.0.ip_sets.*.ip_set.0.definition.*", "10.0.1.0/24"), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rule_variables.0.ip_sets.*.ip_set.0.definition.*", "192.168.0.0/16"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "rule_group.0.rule_variables.0.ip_sets.*", map[string]string{ + resource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rule_variables.0.ip_sets.*.ip_set.0.definition.*", "10.0.0.0/16"), + resource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rule_variables.0.ip_sets.*.ip_set.0.definition.*", "10.0.1.0/24"), + resource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rule_variables.0.ip_sets.*.ip_set.0.definition.*", "192.168.0.0/16"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "rule_group.0.rule_variables.0.ip_sets.*", map[string]string{ "key": "example2", "ip_set.#": "1", "ip_set.0.definition.#": "1", }), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rule_variables.0.ip_sets.*.ip_set.0.definition.*", "1.2.3.4/32"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "rule_group.0.rule_variables.0.port_sets.*", map[string]string{ + resource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rule_variables.0.ip_sets.*.ip_set.0.definition.*", "1.2.3.4/32"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "rule_group.0.rule_variables.0.port_sets.*", map[string]string{ "key": "example", "port_set.#": "1", "port_set.0.definition.#": "2", }), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rule_variables.0.port_sets.*.port_set.0.definition.*", "443"), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rule_variables.0.port_sets.*.port_set.0.definition.*", "80"), + resource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rule_variables.0.port_sets.*.port_set.0.definition.*", "443"), + resource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rule_variables.0.port_sets.*.port_set.0.definition.*", "80"), ), }, { @@ -422,7 +421,7 @@ func TestAccAwsNetworkFirewallRuleGroup_updateStatefulRule(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckAwsNetworkFirewallRuleGroupExists(resourceName), resource.TestCheckResourceAttr(resourceName, "rule_group.0.rules_source.0.stateful_rule.#", "1"), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "rule_group.0.rules_source.0.stateful_rule.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "rule_group.0.rules_source.0.stateful_rule.*", map[string]string{ "action": networkfirewall.StatefulActionDrop, "header.#": "1", "header.0.destination": "1.2.3.4/32", @@ -463,7 +462,7 @@ func TestAccAwsNetworkFirewallRuleGroup_updateStatelessRule(t *testing.T) { Config: testAccNetworkFirewallRuleGroup_updateStatelessRule(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAwsNetworkFirewallRuleGroupExists(resourceName), - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "rule_group.0.rules_source.0.stateless_rules_and_custom_actions.0.stateless_rule.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "rule_group.0.rules_source.0.stateless_rules_and_custom_actions.0.stateless_rule.*", map[string]string{ "priority": "10", "rule_definition.#": "1", "rule_definition.0.actions.#": "1", @@ -475,11 +474,11 @@ func TestAccAwsNetworkFirewallRuleGroup_updateStatelessRule(t *testing.T) { "rule_definition.0.match_attributes.0.source_port.#": "1", "rule_definition.0.match_attributes.0.tcp_flag.#": "1", }), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rules_source.0.stateless_rules_and_custom_actions.0.stateless_rule.*.rule_definition.0.actions.*", "aws:pass"), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rules_source.0.stateless_rules_and_custom_actions.0.stateless_rule.*.rule_definition.0.match_attributes.0.protocols.*", "6"), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rules_source.0.stateless_rules_and_custom_actions.0.stateless_rule.*.rule_definition.0.match_attributes.0.tcp_flag.*.flags.*", "SYN"), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rules_source.0.stateless_rules_and_custom_actions.0.stateless_rule.*.rule_definition.0.match_attributes.0.tcp_flag.*.masks.*", "SYN"), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rules_source.0.stateless_rules_and_custom_actions.0.stateless_rule.*.rule_definition.0.match_attributes.0.tcp_flag.*.masks.*", "ACK"), + resource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rules_source.0.stateless_rules_and_custom_actions.0.stateless_rule.*.rule_definition.0.actions.*", "aws:pass"), + resource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rules_source.0.stateless_rules_and_custom_actions.0.stateless_rule.*.rule_definition.0.match_attributes.0.protocols.*", "6"), + resource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rules_source.0.stateless_rules_and_custom_actions.0.stateless_rule.*.rule_definition.0.match_attributes.0.tcp_flag.*.flags.*", "SYN"), + resource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rules_source.0.stateless_rules_and_custom_actions.0.stateless_rule.*.rule_definition.0.match_attributes.0.tcp_flag.*.masks.*", "SYN"), + resource.TestCheckTypeSetElemAttr(resourceName, "rule_group.0.rules_source.0.stateless_rules_and_custom_actions.0.stateless_rule.*.rule_definition.0.match_attributes.0.tcp_flag.*.masks.*", "ACK"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), ), }, diff --git a/aws/resource_aws_serverlessapplicationrepository_cloudformation_stack_test.go b/aws/resource_aws_serverlessapplicationrepository_cloudformation_stack_test.go index db48a36a51c..bd96fd7bc8e 100644 --- a/aws/resource_aws_serverlessapplicationrepository_cloudformation_stack_test.go +++ b/aws/resource_aws_serverlessapplicationrepository_cloudformation_stack_test.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - "github.com/terraform-providers/terraform-provider-aws/aws/internal/tfawsresource" ) // Since aws_serverlessapplicationrepository_cloudformation_stack creates CloudFormation stacks, @@ -39,8 +38,8 @@ func TestAccAwsServerlessApplicationRepositoryCloudFormationStack_basic(t *testi resource.TestCheckResourceAttr(resourceName, "outputs.%", "1"), resource.TestCheckResourceAttrSet(resourceName, "outputs.RotationLambdaARN"), resource.TestCheckResourceAttr(resourceName, "capabilities.#", "2"), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "capabilities.*", "CAPABILITY_IAM"), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "capabilities.*", "CAPABILITY_RESOURCE_POLICY"), + resource.TestCheckTypeSetElemAttr(resourceName, "capabilities.*", "CAPABILITY_IAM"), + resource.TestCheckTypeSetElemAttr(resourceName, "capabilities.*", "CAPABILITY_RESOURCE_POLICY"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), ), }, @@ -110,7 +109,7 @@ func TestAccAwsServerlessApplicationRepositoryCloudFormationStack_versioned(t *t testAccCheckServerlessApplicationRepositoryCloudFormationStackExists(resourceName, &stack1), resource.TestCheckResourceAttr(resourceName, "semantic_version", version1), resource.TestCheckResourceAttr(resourceName, "capabilities.#", "1"), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "capabilities.*", "CAPABILITY_IAM"), + resource.TestCheckTypeSetElemAttr(resourceName, "capabilities.*", "CAPABILITY_IAM"), ), }, { @@ -125,8 +124,8 @@ func TestAccAwsServerlessApplicationRepositoryCloudFormationStack_versioned(t *t testAccCheckCloudFormationStackNotRecreated(&stack1, &stack2), resource.TestCheckResourceAttr(resourceName, "semantic_version", version2), resource.TestCheckResourceAttr(resourceName, "capabilities.#", "2"), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "capabilities.*", "CAPABILITY_IAM"), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "capabilities.*", "CAPABILITY_RESOURCE_POLICY"), + resource.TestCheckTypeSetElemAttr(resourceName, "capabilities.*", "CAPABILITY_IAM"), + resource.TestCheckTypeSetElemAttr(resourceName, "capabilities.*", "CAPABILITY_RESOURCE_POLICY"), ), }, { @@ -137,7 +136,7 @@ func TestAccAwsServerlessApplicationRepositoryCloudFormationStack_versioned(t *t testAccCheckCloudFormationStackNotRecreated(&stack2, &stack3), resource.TestCheckResourceAttr(resourceName, "semantic_version", version1), resource.TestCheckResourceAttr(resourceName, "capabilities.#", "1"), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "capabilities.*", "CAPABILITY_IAM"), + resource.TestCheckTypeSetElemAttr(resourceName, "capabilities.*", "CAPABILITY_IAM"), ), }, }, @@ -163,8 +162,8 @@ func TestAccAwsServerlessApplicationRepositoryCloudFormationStack_paired(t *test testAccCheckServerlessApplicationRepositoryCloudFormationStackExists(resourceName, &stack), resource.TestCheckResourceAttr(resourceName, "semantic_version", version), resource.TestCheckResourceAttr(resourceName, "capabilities.#", "2"), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "capabilities.*", "CAPABILITY_IAM"), - tfawsresource.TestCheckTypeSetElemAttr(resourceName, "capabilities.*", "CAPABILITY_RESOURCE_POLICY"), + resource.TestCheckTypeSetElemAttr(resourceName, "capabilities.*", "CAPABILITY_IAM"), + resource.TestCheckTypeSetElemAttr(resourceName, "capabilities.*", "CAPABILITY_RESOURCE_POLICY"), ), }, }, From 674012e5b51d04b95288e98cc3f3adbe1ab4f296 Mon Sep 17 00:00:00 2001 From: Simon Davis Date: Fri, 27 Nov 2020 08:27:31 -0800 Subject: [PATCH 2/3] remove provider level typeset check functions --- aws/internal/tfawsresource/testing.go | 270 --- aws/internal/tfawsresource/testing_test.go | 2495 -------------------- 2 files changed, 2765 deletions(-) delete mode 100644 aws/internal/tfawsresource/testing.go delete mode 100644 aws/internal/tfawsresource/testing_test.go diff --git a/aws/internal/tfawsresource/testing.go b/aws/internal/tfawsresource/testing.go deleted file mode 100644 index c3e11ed9692..00000000000 --- a/aws/internal/tfawsresource/testing.go +++ /dev/null @@ -1,270 +0,0 @@ -package tfawsresource - -import ( - "fmt" - "regexp" - "strings" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -const ( - sentinelIndex = "*" -) - -// TestCheckTypeSetElemNestedAttrs is a resource.TestCheckFunc that accepts a resource -// name, an attribute path, which should use the sentinel value '*' for indexing -// into a TypeSet. The function verifies that an element matches the whole value -// map. -// -// You may check for unset keys, however this will also match keys set to empty -// string. Please provide a map with at least 1 non-empty value. -// -// map[string]string{ -// "key1": "value", -// "key2": "", -// } -// -// Use this function over SDK provided TestCheckFunctions when validating a -// TypeSet where its elements are a nested object with their own attrs/values. -// -// Please note, if the provided value map is not granular enough, there exists -// the possibility you match an element you were not intending to, in the TypeSet. -// Provide a full mapping of attributes to be sure the unique element exists. -func TestCheckTypeSetElemNestedAttrs(name, attr string, values map[string]string) resource.TestCheckFunc { - return func(s *terraform.State) error { - is, err := instanceState(s, name) - if err != nil { - return err - } - - attrParts := strings.Split(attr, ".") - if attrParts[len(attrParts)-1] != sentinelIndex { - return fmt.Errorf("%q does not end with the special value %q", attr, sentinelIndex) - } - // account for cases where the user is trying to see if the value is unset/empty - // there may be ambiguous scenarios where a field was deliberately unset vs set - // to the empty string, this will match both, which may be a false positive. - var matchCount int - for _, v := range values { - if v != "" { - matchCount++ - } - } - if matchCount == 0 { - return fmt.Errorf("%#v has no non-empty values", values) - } - - if testCheckTypeSetElemNestedAttrsInState(is, attrParts, matchCount, values) { - return nil - } - return fmt.Errorf("%q no TypeSet element %q, with nested attrs %#v in state: %#v", name, attr, values, is.Attributes) - } -} - -// TestMatchTypeSetElemNestedAttrs is a resource.TestCheckFunc similar to TestCheckTypeSetElemNestedAttrs -// with the exception that it verifies that an element matches a *regexp.Regexp. -// -// You may check for unset keys, however this will also match keys set to empty -// string. Please provide a map with at least 1 non-empty value e.g. -// -// map[string]*regexp.Regexp{ -// "key1": regexp.MustCompile("value"), -// "key2": regexp.MustCompile(""), -// } -// -func TestMatchTypeSetElemNestedAttrs(name, attr string, values map[string]*regexp.Regexp) resource.TestCheckFunc { - return func(s *terraform.State) error { - is, err := instanceState(s, name) - if err != nil { - return err - } - - attrParts := strings.Split(attr, ".") - if attrParts[len(attrParts)-1] != sentinelIndex { - return fmt.Errorf("%q does not end with the special value %q", attr, sentinelIndex) - } - // account for cases where the user is trying to see if the value is unset/empty - // there may be ambiguous scenarios where a field was deliberately unset vs set - // to the empty string, this will match both, which may be a false positive. - var matchCount int - for _, v := range values { - if v != nil { - matchCount++ - } - } - if matchCount == 0 { - return fmt.Errorf("%#v has no non-empty values", values) - } - - if testCheckTypeSetElemNestedAttrsInState(is, attrParts, matchCount, values) { - return nil - } - return fmt.Errorf("%q no TypeSet element %q, with the regex provided, match in state: %#v", name, attr, is.Attributes) - } -} - -// TestCheckTypeSetElemAttr is a resource.TestCheckFunc that accepts a resource -// name, an attribute path, which should use the sentinel value '*' for indexing -// into a TypeSet. The function verifies that an element matches the provided -// value. -// -// Use this function over SDK provided TestCheckFunctions when validating a -// TypeSet where its elements are a simple value -func TestCheckTypeSetElemAttr(name, attr, value string) resource.TestCheckFunc { - return func(s *terraform.State) error { - is, err := instanceState(s, name) - if err != nil { - return err - } - - err = testCheckTypeSetElem(is, attr, value) - if err != nil { - return fmt.Errorf("%q error: %s", name, err) - } - - return nil - } -} - -// TestCheckTypeSetElemAttrPair is a TestCheckFunc that verifies a pair of name/key -// combinations are equal where the first uses the sentinel value to index into a -// TypeSet. -// -// E.g., tfawsresource.TestCheckTypeSetElemAttrPair("aws_autoscaling_group.bar", "availability_zones.*", "data.aws_availability_zones.available", "names.0") -// E.g., tfawsresource.TestCheckTypeSetElemAttrPair("aws_spot_fleet_request.bar", "launch_specification.*.instance_type", "data.data.aws_ec2_instance_type_offering.available", "instance_type") -func TestCheckTypeSetElemAttrPair(nameFirst, keyFirst, nameSecond, keySecond string) resource.TestCheckFunc { - return func(s *terraform.State) error { - isFirst, err := instanceState(s, nameFirst) - if err != nil { - return err - } - - isSecond, err := instanceState(s, nameSecond) - if err != nil { - return err - } - - vSecond, okSecond := isSecond.Attributes[keySecond] - if !okSecond { - return fmt.Errorf("%s: Attribute %q not set, cannot be checked against TypeSet", nameSecond, keySecond) - } - - return testCheckTypeSetElemPair(isFirst, keyFirst, vSecond) - } -} - -// instanceState returns the primary instance state for the given -// resource name in the root module. -func instanceState(s *terraform.State, name string) (*terraform.InstanceState, error) { - ms := s.RootModule() - rs, ok := ms.Resources[name] - if !ok { - return nil, fmt.Errorf("Not found: %s in %s", name, ms.Path) - } - - is := rs.Primary - if is == nil { - return nil, fmt.Errorf("No primary instance: %s in %s", name, ms.Path) - } - - return is, nil -} - -func testCheckTypeSetElem(is *terraform.InstanceState, attr, value string) error { - attrParts := strings.Split(attr, ".") - if attrParts[len(attrParts)-1] != sentinelIndex { - return fmt.Errorf("%q does not end with the special value %q", attr, sentinelIndex) - } - for stateKey, stateValue := range is.Attributes { - if stateValue == value { - stateKeyParts := strings.Split(stateKey, ".") - if len(stateKeyParts) == len(attrParts) { - for i := range attrParts { - if attrParts[i] != stateKeyParts[i] && attrParts[i] != sentinelIndex { - break - } - if i == len(attrParts)-1 { - return nil - } - } - } - } - } - - return fmt.Errorf("no TypeSet element %q, with value %q in state: %#v", attr, value, is.Attributes) -} - -func testCheckTypeSetElemPair(is *terraform.InstanceState, attr, value string) error { - attrParts := strings.Split(attr, ".") - for stateKey, stateValue := range is.Attributes { - if stateValue == value { - stateKeyParts := strings.Split(stateKey, ".") - if len(stateKeyParts) == len(attrParts) { - for i := range attrParts { - if attrParts[i] != stateKeyParts[i] && attrParts[i] != sentinelIndex { - break - } - if i == len(attrParts)-1 { - return nil - } - } - } - } - } - - return fmt.Errorf("no TypeSet element %q, with value %q in state: %#v", attr, value, is.Attributes) -} - -// testCheckTypeSetElemNestedAttrsInState is a helper function -// to determine if nested attributes and their values are equal to those -// in the instance state. Currently, the function accepts a "values" param of type -// map[string]string or map[string]*regexp.Regexp. -// Returns true if all attributes match, else false. -func testCheckTypeSetElemNestedAttrsInState(is *terraform.InstanceState, attrParts []string, matchCount int, values interface{}) bool { - matches := make(map[string]int) - - for stateKey, stateValue := range is.Attributes { - stateKeyParts := strings.Split(stateKey, ".") - // a Set/List item with nested attrs would have a flatmap address of - // at least length 3 - // foo.0.name = "bar" - if len(stateKeyParts) < 3 { - continue - } - var pathMatch bool - for i := range attrParts { - if attrParts[i] != stateKeyParts[i] && attrParts[i] != sentinelIndex { - break - } - if i == len(attrParts)-1 { - pathMatch = true - } - } - if !pathMatch { - continue - } - id := stateKeyParts[len(attrParts)-1] - nestedAttr := strings.Join(stateKeyParts[len(attrParts):], ".") - - var match bool - switch t := values.(type) { - case map[string]string: - if v, keyExists := t[nestedAttr]; keyExists && v == stateValue { - match = true - } - case map[string]*regexp.Regexp: - if v, keyExists := t[nestedAttr]; keyExists && v != nil && v.MatchString(stateValue) { - match = true - } - } - if match { - matches[id] = matches[id] + 1 - if matches[id] == matchCount { - return true - } - } - } - return false -} diff --git a/aws/internal/tfawsresource/testing_test.go b/aws/internal/tfawsresource/testing_test.go deleted file mode 100644 index b31e23577ef..00000000000 --- a/aws/internal/tfawsresource/testing_test.go +++ /dev/null @@ -1,2495 +0,0 @@ -package tfawsresource - -import ( - "regexp" - "strings" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestTestCheckTypeSetElemAttr(t *testing.T) { - testCases := []struct { - Description string - ResourceAddress string - ResourceAttribute string - Value string - TerraformState *terraform.State - ExpectedError func(err error) bool - }{ - { - Description: "no resources", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Value: "", - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{}, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "Not found: example_thing.test") - }, - }, - { - Description: "resource not found", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Value: "", - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_other_thing.test": { - Type: "example_other_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "11111", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "Not found: example_thing.test") - }, - }, - { - Description: "no primary instance", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Value: "", - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Deposed: []*terraform.InstanceState{ - { - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "11111", - }, - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "No primary instance: example_thing.test") - }, - }, - { - Description: "attribute path does not end with sentinel value", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test", - Value: "", - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "11111", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "does not end with the special value") - }, - }, - { - Description: "attribute not found", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Value: "", - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "11111", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "\"example_thing.test\" error: no TypeSet element \"test.*\"") - }, - }, - { - Description: "single root TypeSet attribute match", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Value: "value1", - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "3", - "id": "11111", - "test.%": "1", - "test.12345": "value1", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - }, - { - Description: "single root TypeSet attribute mismatch", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Value: "value2", - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "3", - "id": "11111", - "test.%": "1", - "test.12345": "value1", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "\"example_thing.test\" error: no TypeSet element \"test.*\"") - }, - }, - { - Description: "multiple root TypeSet attribute match", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Value: "value1", - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "4", - "id": "11111", - "test.%": "2", - "test.12345": "value2", - "test.67890": "value1", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - }, - { - Description: "multiple root TypeSet attribute mismatch", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Value: "value3", - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "4", - "id": "11111", - "test.%": "2", - "test.12345": "value2", - "test.67890": "value1", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "\"example_thing.test\" error: no TypeSet element \"test.*\"") - }, - }, - { - Description: "single nested TypeSet attribute match", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.0.nested_test.*", - Value: "value1", - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "4", - "id": "11111", - "test.%": "1", - "test.0.nested_test.12345": "value1", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - }, - { - Description: "single nested TypeSet attribute mismatch", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.0.nested_test.*", - Value: "value2", - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "4", - "id": "11111", - "test.%": "1", - "test.0.nested_test.12345": "value1", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "\"example_thing.test\" error: no TypeSet element \"test.0.nested_test.*\"") - }, - }, - } - - for _, testCase := range testCases { - t.Run(testCase.Description, func(t *testing.T) { - err := TestCheckTypeSetElemAttr(testCase.ResourceAddress, testCase.ResourceAttribute, testCase.Value)(testCase.TerraformState) - - if err != nil { - if testCase.ExpectedError == nil { - t.Fatalf("expected no error, got error: %s", err) - } - - if !testCase.ExpectedError(err) { - t.Fatalf("unexpected error: %s", err) - } - - t.Logf("received expected error: %s", err) - return - } - - if err == nil && testCase.ExpectedError != nil { - t.Fatalf("expected error, got no error") - } - }) - } -} - -func TestTestCheckTypeSetElemAttrPair(t *testing.T) { - testCases := []struct { - Description string - FirstResourceAddress string - FirstResourceAttribute string - SecondResourceAddress string - SecondResourceAttribute string - TerraformState *terraform.State - ExpectedError func(err error) bool - }{ - { - Description: "first resource no primary instance", - FirstResourceAddress: "asg.bar", - FirstResourceAttribute: "az.*", - SecondResourceAddress: "data.az.available", - SecondResourceAttribute: "names.0", - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "asg.bar": { - Type: "asg", - Provider: "example", - }, - "data.az.available": { - Type: "data.az", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "3579", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "3579", - "names.#": "3", - "names.0": "uswst3", - "names.1": "uswst2", - "names.3": "uswst1", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "No primary instance") - }, - }, - { - Description: "second resource no primary instance", - FirstResourceAddress: "asg.bar", - FirstResourceAttribute: "az.*", - SecondResourceAddress: "data.az.available", - SecondResourceAttribute: "names.0", - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "asg.bar": { - Type: "asg", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "11111", - "az.%": "2", - "az.12345": "uswst2", - "az.23456": "uswst3", - }, - }, - }, - "data.az.available": { - Type: "data.az", - Provider: "example", - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "No primary instance") - }, - }, - { - Description: "no resources", - FirstResourceAddress: "asg.bar", - FirstResourceAttribute: "az.*", - SecondResourceAddress: "data.az.available", - SecondResourceAttribute: "names.0", - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{}, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "Not found: asg.bar") - }, - }, - { - Description: "first resource not found", - FirstResourceAddress: "asg.bar", - FirstResourceAttribute: "az.*", - SecondResourceAddress: "data.az.available", - SecondResourceAttribute: "names.0", - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "data.az.available": { - Type: "data.az", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "3579", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "3579", - "names.#": "3", - "names.0": "uswst3", - "names.1": "uswst2", - "names.3": "uswst1", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "Not found: asg.bar") - }, - }, - { - Description: "second resource not found", - FirstResourceAddress: "asg.bar", - FirstResourceAttribute: "az.*", - SecondResourceAddress: "data.az.available", - SecondResourceAttribute: "names.0", - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "asg.bar": { - Type: "asg", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "11111", - "az.%": "2", - "az.12345": "uswst2", - "az.23456": "uswst3", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "Not found") - }, - }, - { - Description: "first resource attribute not found", - FirstResourceAddress: "asg.bar", - FirstResourceAttribute: "az.*", - SecondResourceAddress: "data.az.available", - SecondResourceAttribute: "names.0", - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "asg.bar": { - Type: "asg", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "11111", - }, - }, - }, - "data.az.available": { - Type: "data.az", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "3579", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "3579", - "names.#": "3", - "names.0": "uswst3", - "names.1": "uswst2", - "names.3": "uswst1", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "no TypeSet element \"az.*\", with value \"uswst3\" in state") - }, - }, - { - Description: "second resource attribute not found", - FirstResourceAddress: "asg.bar", - FirstResourceAttribute: "az.*", - SecondResourceAddress: "data.az.available", - SecondResourceAttribute: "names.0", - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "asg.bar": { - Type: "asg", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "11111", - "az.%": "2", - "az.12345": "uswst2", - "az.23456": "uswst3", - }, - }, - }, - "data.az.available": { - Type: "data.az", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "3579", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "3579", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), `Attribute "names.0" not set`) - }, - }, - { - Description: "first resource attribute does not end with sentinel", - FirstResourceAddress: "asg.bar", - FirstResourceAttribute: "az.34812", - SecondResourceAddress: "data.az.available", - SecondResourceAttribute: "names.0", - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "asg.bar": { - Type: "asg", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "11111", - "az.%": "2", - "az.12345": "uswst2", - "az.23456": "uswst3", - }, - }, - }, - "data.az.available": { - Type: "data.az", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "3579", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "3579", - "names.#": "3", - "names.0": "uswst3", - "names.1": "uswst2", - "names.3": "uswst1", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), `no TypeSet element "az.34812", with value "uswst3" in state`) - }, - }, - { - Description: "second resource attribute ends with sentinel", - FirstResourceAddress: "asg.bar", - FirstResourceAttribute: "az.*", - SecondResourceAddress: "data.az.available", - SecondResourceAttribute: "names.*", - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "asg.bar": { - Type: "asg", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "11111", - "az.%": "2", - "az.12345": "uswst2", - "az.23456": "uswst3", - }, - }, - }, - "data.az.available": { - Type: "data.az", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "3579", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "3579", - "names.#": "3", - "names.0": "uswst3", - "names.1": "uswst2", - "names.3": "uswst1", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), `data.az.available: Attribute "names.*" not set`) - }, - }, - { - Description: "match zero attribute", - FirstResourceAddress: "asg.bar", - FirstResourceAttribute: "az.*", - SecondResourceAddress: "data.az.available", - SecondResourceAttribute: "names.0", - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "asg.bar": { - Type: "asg", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "11111", - "az.%": "2", - "az.12345": "uswst2", - "az.23456": "uswst3", - }, - }, - }, - "data.az.available": { - Type: "data.az", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "3579", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "3579", - "names.#": "3", - "names.0": "uswst3", - "names.1": "uswst2", - "names.3": "uswst1", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - }, - { - Description: "match non-zero attribute", - FirstResourceAddress: "asg.bar", - FirstResourceAttribute: "az.*", - SecondResourceAddress: "data.az.available", - SecondResourceAttribute: "names.2", - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "asg.bar": { - Type: "asg", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "11111", - "az.%": "2", - "az.12345": "uswst1", - "az.23456": "uswst3", - }, - }, - }, - "data.az.available": { - Type: "data.az", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "3579", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "3579", - "names.#": "3", - "names.0": "uswst3", - "names.1": "uswst2", - "names.2": "uswst1", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - }, - { - Description: "single nested TypeSet argument and root TypeSet argument", - FirstResourceAddress: "spot_fleet_request.bar", - FirstResourceAttribute: "launch_specification.*.instance_type", - SecondResourceAddress: "data.ec2_instances.available", - SecondResourceAttribute: "instance_type", - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "spot_fleet_request.bar": { - Type: "spot_fleet_request", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "11111", - "launch_specification.#": "1", - "launch_specification.12345.instance_type": "t2.micro", - }, - }, - }, - "data.ec2_instances.available": { - Type: "data.ec2_instances", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "3579", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "3579", - "instance_type": "t2.micro", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - }, - } - - for _, testCase := range testCases { - t.Run(testCase.Description, func(t *testing.T) { - err := TestCheckTypeSetElemAttrPair( - testCase.FirstResourceAddress, - testCase.FirstResourceAttribute, - testCase.SecondResourceAddress, - testCase.SecondResourceAttribute)(testCase.TerraformState) - - if err != nil { - if testCase.ExpectedError == nil { - t.Fatalf("expected no error, got error: %s", err) - } - - if !testCase.ExpectedError(err) { - t.Fatalf("unexpected error: %s", err) - } - - t.Logf("received expected error: %s", err) - return - } - - if err == nil && testCase.ExpectedError != nil { - t.Fatalf("expected error, got no error") - } - }) - } -} - -func TestTestMatchTypeSetElemNestedAttrs(t *testing.T) { - testCases := []struct { - Description string - ResourceAddress string - ResourceAttribute string - Values map[string]*regexp.Regexp - TerraformState *terraform.State - ExpectedError func(err error) bool - }{ - { - Description: "no resources", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Values: map[string]*regexp.Regexp{}, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{}, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "Not found: example_thing.test") - }, - }, - { - Description: "resource not found", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Values: map[string]*regexp.Regexp{}, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_other_thing.test": { - Type: "example_other_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "11111", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "Not found: example_thing.test") - }, - }, - { - Description: "no primary instance", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Values: map[string]*regexp.Regexp{}, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Deposed: []*terraform.InstanceState{ - { - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "11111", - }, - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "No primary instance: example_thing.test") - }, - }, - { - Description: "value map has no non-empty values", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Values: map[string]*regexp.Regexp{"key": nil}, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "11111", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "has no non-empty values") - }, - }, - { - Description: "attribute path does not end with sentinel value", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test", - Values: map[string]*regexp.Regexp{}, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "11111", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "does not end with the special value") - }, - }, - { - Description: "attribute not found", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Values: map[string]*regexp.Regexp{"key": regexp.MustCompile("value")}, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "11111", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "\"example_thing.test\" no TypeSet element \"test.*\"") - }, - }, - { - Description: "single root TypeSet attribute single value match", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Values: map[string]*regexp.Regexp{ - "key1": regexp.MustCompile("value"), - }, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "3", - "id": "11111", - "test.%": "1", - "test.12345.key1": "value1", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - }, - { - Description: "single root TypeSet attribute single value mismatch", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Values: map[string]*regexp.Regexp{ - "key1": regexp.MustCompile("2"), - }, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "3", - "id": "11111", - "test.%": "1", - "test.12345.key1": "value1", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "\"example_thing.test\" no TypeSet element \"test.*\"") - }, - }, - { - Description: "single root TypeSet attribute single nested value match", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Values: map[string]*regexp.Regexp{ - "key1.0.nested_key1": regexp.MustCompile("value"), - }, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "3", - "id": "11111", - "test.%": "1", - "test.12345.key1.0.nested_key1": "value1", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - }, - { - Description: "single root TypeSet attribute single nested value mismatch", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Values: map[string]*regexp.Regexp{ - "key1.0.nested_key1": regexp.MustCompile("2"), - }, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "3", - "id": "11111", - "test.%": "1", - "test.12345.key1.0.nested_key1": "value1", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "\"example_thing.test\" no TypeSet element \"test.*\"") - }, - }, - { - Description: "single root TypeSet attribute multiple value match", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Values: map[string]*regexp.Regexp{ - "key1": regexp.MustCompile("value"), - "key2": regexp.MustCompile("value"), - }, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "4", - "id": "11111", - "test.%": "1", - "test.12345.key1": "value1", - "test.12345.key2": "value2", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - }, - { - Description: "single root TypeSet attribute unset/empty value match", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Values: map[string]*regexp.Regexp{ - "key1": regexp.MustCompile("value"), - "key2": nil, - "key3": nil, - }, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "4", - "id": "11111", - "test.%": "1", - "test.12345.key1": "value1", - "test.12345.key2": "", - // key3 is unset - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - }, - { - Description: "single root TypeSet attribute multiple value mismatch", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Values: map[string]*regexp.Regexp{ - "key1": regexp.MustCompile("1"), - "key2": regexp.MustCompile("3"), - }, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "4", - "id": "11111", - "test.%": "1", - "test.12345.key1": "value1", - "test.12345.key2": "value2", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "\"example_thing.test\" no TypeSet element \"test.*\"") - }, - }, - { - Description: "multiple root TypeSet attribute single value match", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Values: map[string]*regexp.Regexp{ - "key1": regexp.MustCompile("value1"), - }, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "4", - "id": "11111", - "test.%": "2", - "test.12345.key1": "value2", - "test.67890.key1": "value1", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - }, - { - Description: "multiple root TypeSet attribute multiple value match", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Values: map[string]*regexp.Regexp{ - "key1": regexp.MustCompile("1"), - "key2": regexp.MustCompile("2"), - }, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "6", - "id": "11111", - "test.%": "2", - "test.12345.key1": "value2", - "test.12345.key2": "value3", - "test.67890.key1": "value1", - "test.67890.key2": "value2", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - }, - { - Description: "single nested TypeSet attribute single value match", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.0.nested_test.*", - Values: map[string]*regexp.Regexp{ - "key1": regexp.MustCompile("value"), - }, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "4", - "id": "11111", - "test.%": "1", - "test.0.nested_test.%": "1", - "test.0.nested_test.12345.key1": "value1", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - }, - { - Description: "single nested TypeSet attribute single value mismatch", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.0.nested_test.*", - Values: map[string]*regexp.Regexp{ - "key1": regexp.MustCompile("2"), - }, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "4", - "id": "11111", - "test.%": "1", - "test.0.nested_test.%": "1", - "test.0.nested_test.12345.key1": "value1", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "\"example_thing.test\" no TypeSet element \"test.0.nested_test.*\"") - }, - }, - { - Description: "single nested TypeSet attribute single nested value match", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.0.nested_test.*", - Values: map[string]*regexp.Regexp{ - "key1.0.nested_key1": regexp.MustCompile("value"), - }, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "5", - "id": "11111", - "test.%": "1", - "test.0.nested_test.%": "1", - "test.0.nested_test.12345.key1.%": "1", - "test.0.nested_test.12345.key1.0.nested_key1": "value1", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - }, - { - Description: "single nested TypeSet attribute single nested value mismatch", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.0.nested_test.*", - Values: map[string]*regexp.Regexp{ - "key1.0.nested_key1": regexp.MustCompile("2"), - }, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "5", - "id": "11111", - "test.%": "1", - "test.0.nested_test.%": "1", - "test.0.nested_test.12345.key1.%": "1", - "test.0.nested_test.12345.key1.0.nested_key1": "value1", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "\"example_thing.test\" no TypeSet element \"test.0.nested_test.*\"") - }, - }, - } - - for _, testCase := range testCases { - t.Run(testCase.Description, func(t *testing.T) { - err := TestMatchTypeSetElemNestedAttrs(testCase.ResourceAddress, testCase.ResourceAttribute, testCase.Values)(testCase.TerraformState) - - if err != nil { - if testCase.ExpectedError == nil { - t.Fatalf("expected no error, got error: %s", err) - } - - if !testCase.ExpectedError(err) { - t.Fatalf("unexpected error: %s", err) - } - - t.Logf("received expected error: %s", err) - return - } - - if err == nil && testCase.ExpectedError != nil { - t.Fatalf("expected error, got no error") - } - }) - } -} - -func TestTestCheckTypeSetElemNestedAttrs(t *testing.T) { - testCases := []struct { - Description string - ResourceAddress string - ResourceAttribute string - Values map[string]string - TerraformState *terraform.State - ExpectedError func(err error) bool - }{ - { - Description: "no resources", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Values: map[string]string{}, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{}, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "Not found: example_thing.test") - }, - }, - { - Description: "resource not found", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Values: map[string]string{}, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_other_thing.test": { - Type: "example_other_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "11111", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "Not found: example_thing.test") - }, - }, - { - Description: "no primary instance", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Values: map[string]string{}, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Deposed: []*terraform.InstanceState{ - { - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "11111", - }, - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "No primary instance: example_thing.test") - }, - }, - { - Description: "value map has no non-empty values", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Values: map[string]string{"key": ""}, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "11111", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "has no non-empty values") - }, - }, - { - Description: "attribute path does not end with sentinel value", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test", - Values: map[string]string{}, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "11111", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "does not end with the special value") - }, - }, - { - Description: "attribute not found", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Values: map[string]string{"key": "value"}, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "1", - "id": "11111", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "\"example_thing.test\" no TypeSet element \"test.*\"") - }, - }, - { - Description: "single root TypeSet attribute single value match", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Values: map[string]string{ - "key1": "value1", - }, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "3", - "id": "11111", - "test.%": "1", - "test.12345.key1": "value1", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - }, - { - Description: "single root TypeSet attribute single value mismatch", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Values: map[string]string{ - "key1": "value2", - }, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "3", - "id": "11111", - "test.%": "1", - "test.12345.key1": "value1", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "\"example_thing.test\" no TypeSet element \"test.*\"") - }, - }, - { - Description: "single root TypeSet attribute single nested value match", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Values: map[string]string{ - "key1.0.nested_key1": "value1", - }, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "3", - "id": "11111", - "test.%": "1", - "test.12345.key1.0.nested_key1": "value1", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - }, - { - Description: "single root TypeSet attribute single nested value mismatch", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Values: map[string]string{ - "key1.0.nested_key1": "value2", - }, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "3", - "id": "11111", - "test.%": "1", - "test.12345.key1.0.nested_key1": "value1", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "\"example_thing.test\" no TypeSet element \"test.*\"") - }, - }, - { - Description: "single root TypeSet attribute multiple value match", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Values: map[string]string{ - "key1": "value1", - "key2": "value2", - }, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "4", - "id": "11111", - "test.%": "1", - "test.12345.key1": "value1", - "test.12345.key2": "value2", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - }, - { - Description: "single root TypeSet attribute unset/empty value match", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Values: map[string]string{ - "key1": "value1", - "key2": "", - "key3": "", - }, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "4", - "id": "11111", - "test.%": "1", - "test.12345.key1": "value1", - "test.12345.key2": "", - // key3 is unset - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - }, - { - Description: "single root TypeSet attribute multiple value mismatch", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Values: map[string]string{ - "key1": "value1", - "key2": "value3", - }, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "4", - "id": "11111", - "test.%": "1", - "test.12345.key1": "value1", - "test.12345.key2": "value2", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "\"example_thing.test\" no TypeSet element \"test.*\"") - }, - }, - { - Description: "multiple root TypeSet attribute single value match", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Values: map[string]string{ - "key1": "value1", - }, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "4", - "id": "11111", - "test.%": "2", - "test.12345.key1": "value2", - "test.67890.key1": "value1", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - }, - { - Description: "multiple root TypeSet attribute multiple value match", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.*", - Values: map[string]string{ - "key1": "value1", - "key2": "value2", - }, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "6", - "id": "11111", - "test.%": "2", - "test.12345.key1": "value2", - "test.12345.key2": "value3", - "test.67890.key1": "value1", - "test.67890.key2": "value2", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - }, - { - Description: "single nested TypeSet attribute single value match", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.0.nested_test.*", - Values: map[string]string{ - "key1": "value1", - }, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "4", - "id": "11111", - "test.%": "1", - "test.0.nested_test.%": "1", - "test.0.nested_test.12345.key1": "value1", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - }, - { - Description: "single nested TypeSet attribute single value mismatch", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.0.nested_test.*", - Values: map[string]string{ - "key1": "value2", - }, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "4", - "id": "11111", - "test.%": "1", - "test.0.nested_test.%": "1", - "test.0.nested_test.12345.key1": "value1", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "\"example_thing.test\" no TypeSet element \"test.0.nested_test.*\"") - }, - }, - { - Description: "single nested TypeSet attribute single nested value match", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.0.nested_test.*", - Values: map[string]string{ - "key1.0.nested_key1": "value1", - }, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "5", - "id": "11111", - "test.%": "1", - "test.0.nested_test.%": "1", - "test.0.nested_test.12345.key1.%": "1", - "test.0.nested_test.12345.key1.0.nested_key1": "value1", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - }, - { - Description: "single nested TypeSet attribute single nested value mismatch", - ResourceAddress: "example_thing.test", - ResourceAttribute: "test.0.nested_test.*", - Values: map[string]string{ - "key1.0.nested_key1": "value2", - }, - TerraformState: &terraform.State{ - Version: 3, - Modules: []*terraform.ModuleState{ - { - Path: []string{"root"}, - Outputs: map[string]*terraform.OutputState{}, - Resources: map[string]*terraform.ResourceState{ - "example_thing.test": { - Type: "example_thing", - Provider: "example", - Primary: &terraform.InstanceState{ - ID: "11111", - Meta: map[string]interface{}{ - "schema_version": 0, - }, - Attributes: map[string]string{ - "%": "5", - "id": "11111", - "test.%": "1", - "test.0.nested_test.%": "1", - "test.0.nested_test.12345.key1.%": "1", - "test.0.nested_test.12345.key1.0.nested_key1": "value1", - }, - }, - }, - }, - Dependencies: []string{}, - }, - }, - }, - ExpectedError: func(err error) bool { - return strings.Contains(err.Error(), "\"example_thing.test\" no TypeSet element \"test.0.nested_test.*\"") - }, - }, - } - - for _, testCase := range testCases { - t.Run(testCase.Description, func(t *testing.T) { - err := TestCheckTypeSetElemNestedAttrs(testCase.ResourceAddress, testCase.ResourceAttribute, testCase.Values)(testCase.TerraformState) - - if err != nil { - if testCase.ExpectedError == nil { - t.Fatalf("expected no error, got error: %s", err) - } - - if !testCase.ExpectedError(err) { - t.Fatalf("unexpected error: %s", err) - } - - t.Logf("received expected error: %s", err) - return - } - - if err == nil && testCase.ExpectedError != nil { - t.Fatalf("expected error, got no error") - } - }) - } -} From b31b0634a5c32f6653276ea6e314fb0fef14ccbf Mon Sep 17 00:00:00 2001 From: Simon Davis Date: Fri, 27 Nov 2020 08:37:49 -0800 Subject: [PATCH 3/3] update AWSAT004 docs to reflect migration --- awsproviderlint/passes/AWSAT004/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awsproviderlint/passes/AWSAT004/README.md b/awsproviderlint/passes/AWSAT004/README.md index 379b844a37f..51d6753c354 100644 --- a/awsproviderlint/passes/AWSAT004/README.md +++ b/awsproviderlint/passes/AWSAT004/README.md @@ -45,7 +45,7 @@ func TestAccAWSELB_basic(t *testing.T) { Config: testAccAWSELBConfig, Check: resource.ComposeTestCheckFunc( ... - tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "listener.*", map[string]string{ + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "listener.*", map[string]string{ "instance_port": "8000", "instance_protocol": "http", "lb_port": "80",