|
| 1 | +// Copyright (c) HashiCorp, Inc. |
| 2 | +// SPDX-License-Identifier: MPL-2.0 |
| 3 | + |
| 4 | +package account_test |
| 5 | + |
| 6 | +import ( |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 10 | + "github.com/hashicorp/terraform-provider-aws/internal/acctest" |
| 11 | + "github.com/hashicorp/terraform-provider-aws/names" |
| 12 | +) |
| 13 | + |
| 14 | +func testAccPrimaryContactDataSource_basic(t *testing.T) { |
| 15 | + ctx := acctest.Context(t) |
| 16 | + resourceName := "aws_account_primary_contact.test" |
| 17 | + dataSourceName := "data.aws_account_primary_contact.test" |
| 18 | + |
| 19 | + resource.Test(t, resource.TestCase{ |
| 20 | + PreCheck: func() { acctest.PreCheck(ctx, t) }, |
| 21 | + ErrorCheck: acctest.ErrorCheck(t, names.AccountServiceID), |
| 22 | + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, |
| 23 | + CheckDestroy: acctest.CheckDestroyNoop, |
| 24 | + Steps: []resource.TestStep{ |
| 25 | + { |
| 26 | + Config: testAccPrimaryContactDataSourceConfig_basic(), |
| 27 | + Check: resource.ComposeAggregateTestCheckFunc( |
| 28 | + resource.TestCheckResourceAttrPair(dataSourceName, "address_line_1", resourceName, "address_line_1"), |
| 29 | + resource.TestCheckResourceAttrPair(dataSourceName, "address_line_2", resourceName, "address_line_2"), |
| 30 | + resource.TestCheckResourceAttrPair(dataSourceName, "address_line_3", resourceName, "address_line_3"), |
| 31 | + resource.TestCheckResourceAttrPair(dataSourceName, "city", resourceName, "city"), |
| 32 | + resource.TestCheckResourceAttrPair(dataSourceName, "company_name", resourceName, "company_name"), |
| 33 | + resource.TestCheckResourceAttrPair(dataSourceName, "country_code", resourceName, "country_code"), |
| 34 | + resource.TestCheckResourceAttrPair(dataSourceName, "district_or_county", resourceName, "district_or_county"), |
| 35 | + resource.TestCheckResourceAttrPair(dataSourceName, "full_name", resourceName, "full_name"), |
| 36 | + resource.TestCheckResourceAttrPair(dataSourceName, "phone_number", resourceName, "phone_number"), |
| 37 | + resource.TestCheckResourceAttrPair(dataSourceName, "postal_code", resourceName, "postal_code"), |
| 38 | + resource.TestCheckResourceAttrPair(dataSourceName, "state_or_region", resourceName, "state_or_region"), |
| 39 | + resource.TestCheckResourceAttrPair(dataSourceName, "website_url", resourceName, "website_url"), |
| 40 | + ), |
| 41 | + }, |
| 42 | + }, |
| 43 | + }) |
| 44 | +} |
| 45 | + |
| 46 | +func testAccPrimaryContactDataSource_accountID(t *testing.T) { |
| 47 | + ctx := acctest.Context(t) |
| 48 | + resourceName := "aws_account_primary_contact.test" |
| 49 | + dataSourceName := "data.aws_account_primary_contact.test" |
| 50 | + |
| 51 | + resource.Test(t, resource.TestCase{ |
| 52 | + PreCheck: func() { |
| 53 | + acctest.PreCheck(ctx, t) |
| 54 | + acctest.PreCheckAlternateAccount(t) |
| 55 | + acctest.PreCheckOrganizationManagementAccount(ctx, t) |
| 56 | + acctest.PreCheckOrganizationsEnabledServicePrincipal(ctx, t, "account.amazonaws.com") |
| 57 | + }, |
| 58 | + ErrorCheck: acctest.ErrorCheck(t, names.AccountServiceID), |
| 59 | + ProtoV5ProviderFactories: acctest.ProtoV5FactoriesAlternate(ctx, t), |
| 60 | + CheckDestroy: acctest.CheckDestroyNoop, |
| 61 | + Steps: []resource.TestStep{ |
| 62 | + { |
| 63 | + Config: testAccPrimaryContactDataSourceConfig_organization(), |
| 64 | + Check: resource.ComposeAggregateTestCheckFunc( |
| 65 | + resource.TestCheckResourceAttrPair(dataSourceName, names.AttrAccountID, resourceName, names.AttrAccountID), |
| 66 | + resource.TestCheckResourceAttrPair(dataSourceName, "address_line_1", resourceName, "address_line_1"), |
| 67 | + resource.TestCheckResourceAttrPair(dataSourceName, "address_line_2", resourceName, "address_line_2"), |
| 68 | + resource.TestCheckResourceAttrPair(dataSourceName, "address_line_3", resourceName, "address_line_3"), |
| 69 | + resource.TestCheckResourceAttrPair(dataSourceName, "city", resourceName, "city"), |
| 70 | + resource.TestCheckResourceAttrPair(dataSourceName, "company_name", resourceName, "company_name"), |
| 71 | + resource.TestCheckResourceAttrPair(dataSourceName, "country_code", resourceName, "country_code"), |
| 72 | + resource.TestCheckResourceAttrPair(dataSourceName, "district_or_county", resourceName, "district_or_county"), |
| 73 | + resource.TestCheckResourceAttrPair(dataSourceName, "full_name", resourceName, "full_name"), |
| 74 | + resource.TestCheckResourceAttrPair(dataSourceName, "phone_number", resourceName, "phone_number"), |
| 75 | + resource.TestCheckResourceAttrPair(dataSourceName, "postal_code", resourceName, "postal_code"), |
| 76 | + resource.TestCheckResourceAttrPair(dataSourceName, "state_or_region", resourceName, "state_or_region"), |
| 77 | + resource.TestCheckResourceAttrPair(dataSourceName, "website_url", resourceName, "website_url"), |
| 78 | + ), |
| 79 | + }, |
| 80 | + }, |
| 81 | + }) |
| 82 | +} |
| 83 | + |
| 84 | +func testAccPrimaryContactDataSourceConfig_basic() string { |
| 85 | + return ` |
| 86 | +resource "aws_account_primary_contact" "test" { |
| 87 | + address_line_1 = "123 Any Street" |
| 88 | + address_line_2 = "234 Any Street" |
| 89 | + address_line_3 = "345 Any Street" |
| 90 | + city = "Seattle" |
| 91 | + company_name = "Example Corp, Inc." |
| 92 | + country_code = "US" |
| 93 | + district_or_county = "King" |
| 94 | + full_name = "Foo Bar" |
| 95 | + phone_number = "+64211111111" |
| 96 | + postal_code = "98101" |
| 97 | + state_or_region = "WA" |
| 98 | + website_url = "https://www.examplecorp.com" |
| 99 | +} |
| 100 | +
|
| 101 | +data "aws_account_primary_contact" "test" { |
| 102 | + depends_on = [aws_account_primary_contact.test] |
| 103 | +} |
| 104 | +` |
| 105 | +} |
| 106 | + |
| 107 | +func testAccPrimaryContactDataSourceConfig_organization() string { |
| 108 | + return acctest.ConfigCompose(acctest.ConfigAlternateAccountProvider(), ` |
| 109 | +data "aws_caller_identity" "test" { |
| 110 | + provider = "awsalternate" |
| 111 | +} |
| 112 | +
|
| 113 | +resource "aws_account_primary_contact" "test" { |
| 114 | + account_id = data.aws_caller_identity.test.account_id |
| 115 | + address_line_1 = "123 Any Street" |
| 116 | + address_line_2 = "234 Any Street" |
| 117 | + address_line_3 = "345 Any Street" |
| 118 | + city = "Seattle" |
| 119 | + company_name = "Example Corp, Inc." |
| 120 | + country_code = "US" |
| 121 | + district_or_county = "King" |
| 122 | + full_name = "Foo Bar" |
| 123 | + phone_number = "+64211111111" |
| 124 | + postal_code = "98101" |
| 125 | + state_or_region = "WA" |
| 126 | + website_url = "https://www.examplecorp.com" |
| 127 | +} |
| 128 | +
|
| 129 | +data "aws_account_primary_contact" "test" { |
| 130 | + account_id = data.aws_caller_identity.test.account_id |
| 131 | + depends_on = [aws_account_primary_contact.test] |
| 132 | +} |
| 133 | +`) |
| 134 | +} |
0 commit comments