Skip to content

Commit bba5380

Browse files
committed
aws_lakeformation_lf_tag_expression: cleanup tests
1 parent 179bcdd commit bba5380

File tree

4 files changed

+91
-119
lines changed

4 files changed

+91
-119
lines changed

internal/service/lakeformation/exports_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ package lakeformation
66
// exports used for testing only.
77
var (
88
ResourceDataCellsFilter = newDataCellsFilterResource
9+
ResourceLFTagExpression = newLFTagExpressionResource
910
ResourceResourceLFTag = newResourceLFTagResource
1011
ResourceOptIn = newOptInResource
1112

1213
FindDataCellsFilterByID = findDataCellsFilterByID
13-
FindResourceLFTagByID = findResourceLFTagByID
14+
FindLFTagExpression = findLFTagExpression
1415
LFTagParseResourceID = lfTagParseResourceID
1516
FindOptInByID = findOptInByID
1617

internal/service/lakeformation/lakeformation_test.go

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

internal/service/lakeformation/lf_tag_expression.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/aws/aws-sdk-go-v2/aws"
77
"github.com/aws/aws-sdk-go-v2/service/lakeformation"
88
awstypes "github.com/aws/aws-sdk-go-v2/service/lakeformation/types"
9-
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
9+
"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
1010
"github.com/hashicorp/terraform-plugin-framework/path"
1111
"github.com/hashicorp/terraform-plugin-framework/resource"
1212
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
@@ -50,6 +50,7 @@ func (r *lfTagExpressionResource) Schema(ctx context.Context, _ resource.SchemaR
5050
Description: "The ID of the Data Catalog.",
5151
PlanModifiers: []planmodifier.String{
5252
stringplanmodifier.UseStateForUnknown(),
53+
stringplanmodifier.RequiresReplaceIfConfigured(),
5354
},
5455
},
5556
names.AttrName: schema.StringAttribute{
@@ -65,10 +66,10 @@ func (r *lfTagExpressionResource) Schema(ctx context.Context, _ resource.SchemaR
6566
},
6667
},
6768
Blocks: map[string]schema.Block{
68-
names.AttrExpression: schema.ListNestedBlock{
69-
CustomType: fwtypes.NewListNestedObjectTypeOf[expressionLfTag](ctx),
70-
Validators: []validator.List{
71-
listvalidator.IsRequired(),
69+
names.AttrExpression: schema.SetNestedBlock{
70+
CustomType: fwtypes.NewSetNestedObjectTypeOf[expressionLfTag](ctx),
71+
Validators: []validator.Set{
72+
setvalidator.IsRequired(),
7273
},
7374
NestedObject: schema.NestedBlockObject{
7475
Attributes: map[string]schema.Attribute{
@@ -95,6 +96,10 @@ func (r *lfTagExpressionResource) Create(ctx context.Context, request resource.C
9596
return
9697
}
9798

99+
if data.CatalogId.IsNull() || data.CatalogId.IsUnknown() {
100+
data.CatalogId = fwflex.StringValueToFramework(ctx, r.Meta().AccountID(ctx))
101+
}
102+
98103
input := lakeformation.CreateLFTagExpressionInput{}
99104
response.Diagnostics.Append(fwflex.Expand(ctx, data, &input)...)
100105
if response.Diagnostics.HasError() {
@@ -237,10 +242,10 @@ func (r *lfTagExpressionResource) ImportState(ctx context.Context, request resou
237242

238243
type lfTagExpressionResourceModel struct {
239244
framework.WithRegionModel
240-
CatalogId types.String `tfsdk:"catalog_id"`
241-
Description types.String `tfsdk:"description"`
242-
Name types.String `tfsdk:"name"`
243-
Expression fwtypes.ListNestedObjectValueOf[expressionLfTag] `tfsdk:"expression"`
245+
CatalogId types.String `tfsdk:"catalog_id"`
246+
Description types.String `tfsdk:"description"`
247+
Name types.String `tfsdk:"name"`
248+
Expression fwtypes.SetNestedObjectValueOf[expressionLfTag] `tfsdk:"expression"`
244249
}
245250

246251
type expressionLfTag struct {

internal/service/lakeformation/lf_tag_expression_test.go

Lines changed: 73 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -10,122 +10,21 @@ 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"
14-
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
1513
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1614
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1715
"github.com/hashicorp/terraform-plugin-testing/terraform"
1816
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
1917
"github.com/hashicorp/terraform-provider-aws/internal/conns"
2018
"github.com/hashicorp/terraform-provider-aws/internal/create"
21-
"github.com/hashicorp/terraform-provider-aws/internal/errs"
22-
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
19+
"github.com/hashicorp/terraform-provider-aws/internal/retry"
20+
tflakeformation "github.com/hashicorp/terraform-provider-aws/internal/service/lakeformation"
2321
"github.com/hashicorp/terraform-provider-aws/names"
24-
"strings"
2522
)
2623

2724
const (
2825
ResNameLFTagExpression = "LF Tag Expression"
2926
)
3027

31-
//// FindLFTagExpressionByID retrieves an LF Tag Expression by parsing the ID (catalog_id:name)
32-
//func FindLFTagExpressionByID(ctx context.Context, conn *lakeformation.Client, id string) (*lakeformation.GetLFTagExpressionOutput, error) {
33-
// input := &lakeformation.GetLFTagExpressionInput{}
34-
//
35-
// // Check if ID contains catalog_id:name format or just name
36-
// if parts := strings.SplitN(id, ":", 2); len(parts) == 2 {
37-
// catalogId := parts[0]
38-
// name := parts[1]
39-
// input.CatalogId = &catalogId
40-
// input.Name = &name
41-
// } else {
42-
// // Treat entire ID as name, no catalog specified
43-
// input.Name = &id
44-
// }
45-
//
46-
// output, err := conn.GetLFTagExpression(ctx, input)
47-
//
48-
// if errs.IsA[*awstypes.EntityNotFoundException](err) {
49-
// return nil, &retry.NotFoundError{
50-
// LastError: err,
51-
// LastRequest: input,
52-
// }
53-
// }
54-
//
55-
// if err != nil {
56-
// return nil, err
57-
// }
58-
//
59-
// return output, nil
60-
//}
61-
62-
func testAccLFTagExpressionPreCheck(ctx context.Context, t *testing.T) {
63-
conn := acctest.Provider.Meta().(*conns.AWSClient).LakeFormationClient(ctx)
64-
65-
input := &lakeformation.ListLFTagExpressionsInput{}
66-
_, err := conn.ListLFTagExpressions(ctx, input)
67-
68-
if acctest.PreCheckSkipError(err) {
69-
t.Skipf("skipping acceptance testing: %s", err)
70-
}
71-
if err != nil {
72-
t.Fatalf("unexpected PreCheck error: %s", err)
73-
}
74-
}
75-
76-
func testAccLFTagExpressionConfig_basic(rName string) string {
77-
return fmt.Sprintf(`
78-
data "aws_caller_identity" "current" {}
79-
80-
data "aws_iam_session_context" "current" {
81-
arn = data.aws_caller_identity.current.arn
82-
}
83-
84-
resource "aws_lakeformation_data_lake_settings" "test" {
85-
admins = [data.aws_iam_session_context.current.issuer_arn]
86-
}
87-
88-
resource "aws_lakeformation_lf_tag" "domain" {
89-
key = "domain"
90-
values = ["prisons"]
91-
depends_on = [aws_lakeformation_data_lake_settings.test]
92-
}
93-
94-
resource "aws_lakeformation_lf_tag_expression" "test" {
95-
name = %[1]q
96-
97-
tag_expression = {
98-
domain = ["prisons"]
99-
}
100-
101-
depends_on = [
102-
aws_lakeformation_lf_tag.domain,
103-
aws_lakeformation_data_lake_settings.test
104-
]
105-
}
106-
`, rName)
107-
}
108-
109-
func testAccLFTagExpressionConfig_onlyDataLakeSettings(rName string) string {
110-
return `
111-
data "aws_caller_identity" "current" {}
112-
113-
data "aws_iam_session_context" "current" {
114-
arn = data.aws_caller_identity.current.arn
115-
}
116-
117-
resource "aws_lakeformation_data_lake_settings" "test" {
118-
admins = [data.aws_iam_session_context.current.issuer_arn]
119-
}
120-
121-
resource "aws_lakeformation_lf_tag" "domain" {
122-
key = "domain"
123-
values = ["prisons"]
124-
depends_on = [aws_lakeformation_data_lake_settings.test]
125-
}
126-
`
127-
}
128-
12928
func testAccLFTagExpression_basic(t *testing.T) {
13029
ctx := acctest.Context(t)
13130

@@ -286,10 +185,10 @@ func testAccCheckLFTagExpressionDestroy(ctx context.Context) resource.TestCheckF
286185
continue
287186
}
288187

289-
_, err := FindLFTagExpressionByID(ctx, conn, rs.Primary.ID)
188+
_, err := tflakeformation.FindLFTagExpression(ctx, conn, rs.Primary.Attributes[names.AttrName], rs.Primary.Attributes[names.AttrCatalogID])
290189

291-
if tfresource.NotFound(err) {
292-
return nil
190+
if retry.NotFound(err) {
191+
continue
293192
}
294193

295194
if err != nil {
@@ -315,7 +214,7 @@ func testAccCheckLFTagExpressionExists(ctx context.Context, name string, lftagex
315214
}
316215

317216
conn := acctest.Provider.Meta().(*conns.AWSClient).LakeFormationClient(ctx)
318-
resp, err := FindLFTagExpressionByID(ctx, conn, rs.Primary.ID)
217+
resp, err := tflakeformation.FindLFTagExpression(ctx, conn, rs.Primary.Attributes[names.AttrName], rs.Primary.Attributes[names.AttrCatalogID])
319218

320219
if err != nil {
321220
return create.Error(names.LakeFormation, create.ErrActionCheckingExistence, ResNameLFTagExpression, rs.Primary.ID, err)
@@ -327,6 +226,73 @@ func testAccCheckLFTagExpressionExists(ctx context.Context, name string, lftagex
327226
}
328227
}
329228

229+
func testAccLFTagExpressionPreCheck(ctx context.Context, t *testing.T) {
230+
conn := acctest.Provider.Meta().(*conns.AWSClient).LakeFormationClient(ctx)
231+
232+
input := lakeformation.ListLFTagExpressionsInput{}
233+
_, err := conn.ListLFTagExpressions(ctx, &input)
234+
235+
if acctest.PreCheckSkipError(err) {
236+
t.Skipf("skipping acceptance testing: %s", err)
237+
}
238+
if err != nil {
239+
t.Fatalf("unexpected PreCheck error: %s", err)
240+
}
241+
}
242+
243+
func testAccLFTagExpressionConfig_basic(rName string) string {
244+
return fmt.Sprintf(`
245+
data "aws_caller_identity" "current" {}
246+
247+
data "aws_iam_session_context" "current" {
248+
arn = data.aws_caller_identity.current.arn
249+
}
250+
251+
resource "aws_lakeformation_data_lake_settings" "test" {
252+
admins = [data.aws_iam_session_context.current.issuer_arn]
253+
}
254+
255+
resource "aws_lakeformation_lf_tag" "domain" {
256+
key = "domain"
257+
values = ["prisons"]
258+
depends_on = [aws_lakeformation_data_lake_settings.test]
259+
}
260+
261+
resource "aws_lakeformation_lf_tag_expression" "test" {
262+
name = %[1]q
263+
264+
tag_expression = {
265+
domain = ["prisons"]
266+
}
267+
268+
depends_on = [
269+
aws_lakeformation_lf_tag.domain,
270+
aws_lakeformation_data_lake_settings.test
271+
]
272+
}
273+
`, rName)
274+
}
275+
276+
func testAccLFTagExpressionConfig_onlyDataLakeSettings(rName string) string {
277+
return `
278+
data "aws_caller_identity" "current" {}
279+
280+
data "aws_iam_session_context" "current" {
281+
arn = data.aws_caller_identity.current.arn
282+
}
283+
284+
resource "aws_lakeformation_data_lake_settings" "test" {
285+
admins = [data.aws_iam_session_context.current.issuer_arn]
286+
}
287+
288+
resource "aws_lakeformation_lf_tag" "domain" {
289+
key = "domain"
290+
values = ["prisons"]
291+
depends_on = [aws_lakeformation_data_lake_settings.test]
292+
}
293+
`
294+
}
295+
330296
func testAccLFTagExpressionConfig_update1(rName string) string {
331297
return fmt.Sprintf(`
332298
data "aws_caller_identity" "current" {}

0 commit comments

Comments
 (0)