Skip to content

Commit c33a4f7

Browse files
committed
aws_lakeformation_lf_tag_expression: update basic test and add import verify
1 parent bba5380 commit c33a4f7

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

internal/service/lakeformation/lf_tag_expression_test.go

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ import (
1010
"testing"
1111

1212
"github.com/aws/aws-sdk-go-v2/service/lakeformation"
13+
awstypes "github.com/aws/aws-sdk-go-v2/service/lakeformation/types"
1314
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1415
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1516
"github.com/hashicorp/terraform-plugin-testing/terraform"
1617
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
1718
"github.com/hashicorp/terraform-provider-aws/internal/conns"
1819
"github.com/hashicorp/terraform-provider-aws/internal/create"
20+
"github.com/hashicorp/terraform-provider-aws/internal/errs"
1921
"github.com/hashicorp/terraform-provider-aws/internal/retry"
2022
tflakeformation "github.com/hashicorp/terraform-provider-aws/internal/service/lakeformation"
2123
"github.com/hashicorp/terraform-provider-aws/names"
@@ -48,18 +50,15 @@ func testAccLFTagExpression_basic(t *testing.T) {
4850
testAccCheckLFTagExpressionExists(ctx, resourceName, &lftagexpression),
4951
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
5052
resource.TestCheckResourceAttrSet(resourceName, names.AttrCatalogID),
51-
resource.TestCheckResourceAttrSet(resourceName, names.AttrID),
52-
resource.TestCheckResourceAttr(resourceName, "tag_expression.%", "1"),
53-
resource.TestCheckResourceAttr(resourceName, "tag_expression.domain.#", "1"),
53+
resource.TestCheckResourceAttr(resourceName, "expression.#", "1"),
5454
),
5555
},
5656
{
57-
// Remove LF Tag Expression but keep Data Lake Settings to verify destruction with proper permissions
58-
Config: testAccLFTagExpressionConfig_onlyDataLakeSettings(rName),
59-
Check: resource.ComposeTestCheckFunc(
60-
// Verify LF Tag Expression is destroyed while admin permissions still exist
61-
testAccCheckLFTagExpressionDestroy(ctx),
62-
),
57+
ResourceName: resourceName,
58+
ImportState: true,
59+
ImportStateIdFunc: acctest.AttrsImportStateIdFunc(resourceName, ",", names.AttrName, names.AttrCatalogID),
60+
ImportStateVerify: true,
61+
ImportStateVerifyIdentifierAttribute: names.AttrName,
6362
},
6463
},
6564
})
@@ -191,6 +190,10 @@ func testAccCheckLFTagExpressionDestroy(ctx context.Context) resource.TestCheckF
191190
continue
192191
}
193192

193+
if errs.IsAErrorMessageContains[*awstypes.AccessDeniedException](err, "Insufficient Lake Formation permission(s)") {
194+
continue
195+
}
196+
194197
if err != nil {
195198
return create.Error(names.LakeFormation, create.ErrActionCheckingDestroyed, ResNameLFTagExpression, rs.Primary.ID, err)
196199
}
@@ -240,8 +243,7 @@ func testAccLFTagExpressionPreCheck(ctx context.Context, t *testing.T) {
240243
}
241244
}
242245

243-
func testAccLFTagExpressionConfig_basic(rName string) string {
244-
return fmt.Sprintf(`
246+
const testAccLFTagExpression_baseConfig = `
245247
data "aws_caller_identity" "current" {}
246248
247249
data "aws_iam_session_context" "current" {
@@ -252,25 +254,29 @@ resource "aws_lakeformation_data_lake_settings" "test" {
252254
admins = [data.aws_iam_session_context.current.issuer_arn]
253255
}
254256
255-
resource "aws_lakeformation_lf_tag" "domain" {
256-
key = "domain"
257-
values = ["prisons"]
257+
resource "aws_lakeformation_lf_tag" "test" {
258+
key = "key"
259+
values = ["value"]
260+
258261
depends_on = [aws_lakeformation_data_lake_settings.test]
259262
}
263+
`
260264

265+
func testAccLFTagExpressionConfig_basic(rName string) string {
266+
return acctest.ConfigCompose(testAccLFTagExpression_baseConfig,
267+
fmt.Sprintf(`
261268
resource "aws_lakeformation_lf_tag_expression" "test" {
262-
name = %[1]q
263-
264-
tag_expression = {
265-
domain = ["prisons"]
269+
name = %[1]q
270+
description = "test description"
271+
272+
expression {
273+
tag_key = aws_lakeformation_lf_tag.test.key
274+
tag_values = aws_lakeformation_lf_tag.test.values
266275
}
267276
268-
depends_on = [
269-
aws_lakeformation_lf_tag.domain,
270-
aws_lakeformation_data_lake_settings.test
271-
]
277+
depends_on = [aws_lakeformation_data_lake_settings.test]
272278
}
273-
`, rName)
279+
`, rName))
274280
}
275281

276282
func testAccLFTagExpressionConfig_onlyDataLakeSettings(rName string) string {

0 commit comments

Comments
 (0)