Skip to content

Commit de7d1d5

Browse files
committed
aws_lakeformation_lf_tag_expression: test updates
1 parent c33a4f7 commit de7d1d5

File tree

2 files changed

+33
-219
lines changed

2 files changed

+33
-219
lines changed

internal/service/lakeformation/lakeformation_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ func TestAccLakeFormation_serial(t *testing.T) {
8686
},
8787
"LFTagExpression": {
8888
acctest.CtBasic: testAccLFTagExpression_basic,
89-
"values": testAccLFTagExpression_update,
90-
"import": testAccLFTagExpression_import,
89+
"update": testAccLFTagExpression_update,
9190
},
9291
"ResourceLFTag": {
9392
acctest.CtBasic: testAccResourceLFTag_basic,

internal/service/lakeformation/lf_tag_expression_test.go

Lines changed: 32 additions & 217 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func testAccLFTagExpression_basic(t *testing.T) {
5050
testAccCheckLFTagExpressionExists(ctx, resourceName, &lftagexpression),
5151
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
5252
resource.TestCheckResourceAttrSet(resourceName, names.AttrCatalogID),
53+
resource.TestCheckResourceAttr(resourceName, names.AttrDescription, "test description"),
5354
resource.TestCheckResourceAttr(resourceName, "expression.#", "1"),
5455
),
5556
},
@@ -82,93 +83,30 @@ func testAccLFTagExpression_update(t *testing.T) {
8283
CheckDestroy: testAccCheckLFTagExpressionDestroy(ctx),
8384
Steps: []resource.TestStep{
8485
{
85-
Config: testAccLFTagExpressionConfig_update1(rName),
86+
Config: testAccLFTagExpressionConfig_basic(rName),
8687
Check: resource.ComposeTestCheckFunc(
8788
testAccCheckLFTagExpressionExists(ctx, resourceName, &lftagexpression),
8889
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
89-
resource.TestCheckResourceAttr(resourceName, names.AttrDescription, "Initial description"),
9090
resource.TestCheckResourceAttrSet(resourceName, names.AttrCatalogID),
91-
resource.TestCheckResourceAttrSet(resourceName, names.AttrID),
92-
resource.TestCheckResourceAttr(resourceName, "tag_expression.%", "3"),
93-
resource.TestCheckResourceAttr(resourceName, "tag_expression.domain.#", "2"),
94-
resource.TestCheckTypeSetElemAttr(resourceName, "tag_expression.domain.*", "finance"),
95-
resource.TestCheckTypeSetElemAttr(resourceName, "tag_expression.domain.*", "hr"),
96-
resource.TestCheckResourceAttr(resourceName, "tag_expression.environment.#", "3"),
97-
resource.TestCheckTypeSetElemAttr(resourceName, "tag_expression.environment.*", "dev"),
98-
resource.TestCheckTypeSetElemAttr(resourceName, "tag_expression.environment.*", "staging"),
99-
resource.TestCheckTypeSetElemAttr(resourceName, "tag_expression.environment.*", "prod"),
100-
resource.TestCheckResourceAttr(resourceName, "tag_expression.team.#", "1"),
101-
resource.TestCheckTypeSetElemAttr(resourceName, "tag_expression.team.*", "data-eng"),
91+
resource.TestCheckResourceAttr(resourceName, names.AttrDescription, "test description"),
92+
resource.TestCheckResourceAttr(resourceName, "expression.#", "1"),
10293
),
10394
},
10495
{
105-
Config: testAccLFTagExpressionConfig_update2(rName),
106-
Check: resource.ComposeTestCheckFunc(
107-
testAccCheckLFTagExpressionExists(ctx, resourceName, &lftagexpression),
108-
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
109-
resource.TestCheckResourceAttr(resourceName, names.AttrDescription, "Updated description"),
110-
resource.TestCheckResourceAttrSet(resourceName, names.AttrCatalogID),
111-
resource.TestCheckResourceAttrSet(resourceName, names.AttrID),
112-
// Verify tag_expression changes: removed 'team', added 'project', modified 'domain' and 'environment'
113-
resource.TestCheckResourceAttr(resourceName, "tag_expression.%", "3"),
114-
resource.TestCheckResourceAttr(resourceName, "tag_expression.domain.#", "3"),
115-
resource.TestCheckTypeSetElemAttr(resourceName, "tag_expression.domain.*", "finance"),
116-
resource.TestCheckTypeSetElemAttr(resourceName, "tag_expression.domain.*", "marketing"),
117-
resource.TestCheckTypeSetElemAttr(resourceName, "tag_expression.domain.*", "operations"),
118-
resource.TestCheckResourceAttr(resourceName, "tag_expression.environment.#", "2"),
119-
resource.TestCheckTypeSetElemAttr(resourceName, "tag_expression.environment.*", "prod"),
120-
resource.TestCheckTypeSetElemAttr(resourceName, "tag_expression.environment.*", "test"),
121-
resource.TestCheckResourceAttr(resourceName, "tag_expression.project.#", "2"),
122-
resource.TestCheckTypeSetElemAttr(resourceName, "tag_expression.project.*", "alpha"),
123-
resource.TestCheckTypeSetElemAttr(resourceName, "tag_expression.project.*", "beta"),
124-
),
96+
ResourceName: resourceName,
97+
ImportState: true,
98+
ImportStateIdFunc: acctest.AttrsImportStateIdFunc(resourceName, ",", names.AttrName, names.AttrCatalogID),
99+
ImportStateVerify: true,
100+
ImportStateVerifyIdentifierAttribute: names.AttrName,
125101
},
126102
{
127-
// Remove LF Tag Expression but keep Data Lake Settings to verify destruction with proper permissions
128-
Config: testAccLFTagExpressionConfig_updateOnlyDataLakeSettings(rName),
129-
Check: resource.ComposeTestCheckFunc(
130-
// Verify LF Tag Expression is destroyed while admin permissions still exist
131-
testAccCheckLFTagExpressionDestroy(ctx),
132-
),
133-
},
134-
},
135-
})
136-
}
137-
138-
func testAccLFTagExpression_import(t *testing.T) {
139-
ctx := acctest.Context(t)
140-
141-
var lftagexpression lakeformation.GetLFTagExpressionOutput
142-
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
143-
resourceName := "aws_lakeformation_lf_tag_expression.test"
144-
145-
resource.Test(t, resource.TestCase{
146-
PreCheck: func() {
147-
acctest.PreCheck(ctx, t)
148-
acctest.PreCheckPartitionHasService(t, names.LakeFormation)
149-
testAccLFTagExpressionPreCheck(ctx, t)
150-
},
151-
ErrorCheck: acctest.ErrorCheck(t, names.LakeFormationServiceID),
152-
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
153-
CheckDestroy: testAccCheckLFTagExpressionDestroy(ctx),
154-
Steps: []resource.TestStep{
155-
{
156-
Config: testAccLFTagExpressionConfig_basic(rName),
103+
Config: testAccLFTagExpressionConfig_update(rName),
157104
Check: resource.ComposeTestCheckFunc(
158105
testAccCheckLFTagExpressionExists(ctx, resourceName, &lftagexpression),
159-
),
160-
},
161-
{
162-
ResourceName: resourceName,
163-
ImportState: true,
164-
ImportStateVerify: true,
165-
},
166-
{
167-
// Remove LF Tag Expression but keep Data Lake Settings to verify destruction with proper permissions
168-
Config: testAccLFTagExpressionConfig_onlyDataLakeSettings(rName),
169-
Check: resource.ComposeTestCheckFunc(
170-
// Verify LF Tag Expression is destroyed while admin permissions still exist
171-
testAccCheckLFTagExpressionDestroy(ctx),
106+
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
107+
resource.TestCheckResourceAttrSet(resourceName, names.AttrCatalogID),
108+
resource.TestCheckResourceAttr(resourceName, names.AttrDescription, "test description two"),
109+
resource.TestCheckResourceAttr(resourceName, "expression.#", "2"),
172110
),
173111
},
174112
},
@@ -279,141 +217,36 @@ resource "aws_lakeformation_lf_tag_expression" "test" {
279217
`, rName))
280218
}
281219

282-
func testAccLFTagExpressionConfig_onlyDataLakeSettings(rName string) string {
283-
return `
284-
data "aws_caller_identity" "current" {}
285-
286-
data "aws_iam_session_context" "current" {
287-
arn = data.aws_caller_identity.current.arn
288-
}
289-
290-
resource "aws_lakeformation_data_lake_settings" "test" {
291-
admins = [data.aws_iam_session_context.current.issuer_arn]
292-
}
293-
294-
resource "aws_lakeformation_lf_tag" "domain" {
295-
key = "domain"
296-
values = ["prisons"]
297-
depends_on = [aws_lakeformation_data_lake_settings.test]
298-
}
299-
`
300-
}
301-
302-
func testAccLFTagExpressionConfig_update1(rName string) string {
303-
return fmt.Sprintf(`
304-
data "aws_caller_identity" "current" {}
305-
306-
data "aws_iam_session_context" "current" {
307-
arn = data.aws_caller_identity.current.arn
308-
}
309-
310-
resource "aws_lakeformation_data_lake_settings" "test" {
311-
admins = [data.aws_iam_session_context.current.issuer_arn]
312-
}
313-
314-
resource "aws_lakeformation_lf_tag" "domain" {
315-
key = "domain"
316-
values = ["finance", "hr", "marketing", "operations"]
317-
depends_on = [aws_lakeformation_data_lake_settings.test]
318-
}
319-
320-
resource "aws_lakeformation_lf_tag" "environment" {
321-
key = "environment"
322-
values = ["dev", "staging", "prod", "test"]
323-
depends_on = [aws_lakeformation_data_lake_settings.test]
324-
}
325-
326-
resource "aws_lakeformation_lf_tag" "team" {
327-
key = "team"
328-
values = ["data-eng"]
329-
depends_on = [aws_lakeformation_data_lake_settings.test]
330-
}
220+
func testAccLFTagExpressionConfig_update(rName string) string {
221+
return acctest.ConfigCompose(testAccLFTagExpression_baseConfig,
222+
fmt.Sprintf(`
223+
resource "aws_lakeformation_lf_tag" "test2" {
224+
key = "key2"
225+
values = ["value2"]
331226
332-
resource "aws_lakeformation_lf_tag" "project" {
333-
key = "project"
334-
values = ["alpha", "beta"]
335227
depends_on = [aws_lakeformation_data_lake_settings.test]
336228
}
337229
338230
resource "aws_lakeformation_lf_tag_expression" "test" {
339231
name = %[1]q
340-
description = "Initial description"
341-
342-
tag_expression = {
343-
domain = ["finance", "hr"]
344-
environment = ["dev", "staging", "prod"]
345-
team = ["data-eng"]
346-
}
347-
348-
depends_on = [
349-
aws_lakeformation_lf_tag.domain,
350-
aws_lakeformation_lf_tag.environment,
351-
aws_lakeformation_lf_tag.team,
352-
aws_lakeformation_lf_tag.project,
353-
aws_lakeformation_data_lake_settings.test,
354-
]
355-
}
356-
`, rName)
357-
}
358-
359-
func testAccLFTagExpressionConfig_update2(rName string) string {
360-
return fmt.Sprintf(`
361-
data "aws_caller_identity" "current" {}
362-
363-
data "aws_iam_session_context" "current" {
364-
arn = data.aws_caller_identity.current.arn
365-
}
366-
367-
resource "aws_lakeformation_data_lake_settings" "test" {
368-
admins = [data.aws_iam_session_context.current.issuer_arn]
369-
}
232+
description = "test description two"
370233
371-
resource "aws_lakeformation_lf_tag" "domain" {
372-
key = "domain"
373-
values = ["finance", "hr", "marketing", "operations"]
374-
depends_on = [aws_lakeformation_data_lake_settings.test]
375-
}
376-
377-
resource "aws_lakeformation_lf_tag" "environment" {
378-
key = "environment"
379-
values = ["dev", "staging", "prod", "test"]
380-
depends_on = [aws_lakeformation_data_lake_settings.test]
381-
}
382-
383-
resource "aws_lakeformation_lf_tag" "team" {
384-
key = "team"
385-
values = ["data-eng"]
386-
depends_on = [aws_lakeformation_data_lake_settings.test]
387-
}
388-
389-
resource "aws_lakeformation_lf_tag" "project" {
390-
key = "project"
391-
values = ["alpha", "beta"]
392-
depends_on = [aws_lakeformation_data_lake_settings.test]
393-
}
234+
expression {
235+
tag_key = aws_lakeformation_lf_tag.test.key
236+
tag_values = aws_lakeformation_lf_tag.test.values
237+
}
394238
395-
resource "aws_lakeformation_lf_tag_expression" "test" {
396-
name = %[1]q
397-
description = "Updated description"
398-
399-
tag_expression = {
400-
domain = ["finance", "marketing", "operations"]
401-
environment = ["prod", "test"]
402-
project = ["alpha", "beta"]
239+
expression {
240+
tag_key = aws_lakeformation_lf_tag.test2.key
241+
tag_values = aws_lakeformation_lf_tag.test2.values
403242
}
404243
405-
depends_on = [
406-
aws_lakeformation_lf_tag.domain,
407-
aws_lakeformation_lf_tag.environment,
408-
aws_lakeformation_lf_tag.team,
409-
aws_lakeformation_lf_tag.project,
410-
aws_lakeformation_data_lake_settings.test,
411-
]
244+
depends_on = [aws_lakeformation_data_lake_settings.test]
412245
}
413-
`, rName)
246+
`, rName))
414247
}
415248

416-
func testAccLFTagExpressionConfig_updateOnlyDataLakeSettings(rName string) string {
249+
func testAccLFTagExpressionConfig_onlyDataLakeSettings(rName string) string {
417250
return `
418251
data "aws_caller_identity" "current" {}
419252
@@ -427,25 +260,7 @@ resource "aws_lakeformation_data_lake_settings" "test" {
427260
428261
resource "aws_lakeformation_lf_tag" "domain" {
429262
key = "domain"
430-
values = ["finance", "hr", "marketing", "operations"]
431-
depends_on = [aws_lakeformation_data_lake_settings.test]
432-
}
433-
434-
resource "aws_lakeformation_lf_tag" "environment" {
435-
key = "environment"
436-
values = ["dev", "staging", "prod", "test"]
437-
depends_on = [aws_lakeformation_data_lake_settings.test]
438-
}
439-
440-
resource "aws_lakeformation_lf_tag" "team" {
441-
key = "team"
442-
values = ["data-eng"]
443-
depends_on = [aws_lakeformation_data_lake_settings.test]
444-
}
445-
446-
resource "aws_lakeformation_lf_tag" "project" {
447-
key = "project"
448-
values = ["alpha", "beta"]
263+
values = ["prisons"]
449264
depends_on = [aws_lakeformation_data_lake_settings.test]
450265
}
451266
`

0 commit comments

Comments
 (0)