Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 26920 support colon in LakeFormation lf-tag key #28258

Merged
3 changes: 3 additions & 0 deletions .changelog/28258.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_lakeformation_lf_tag: Fix support for lf-tag keys with colons in the name
```
7 changes: 4 additions & 3 deletions internal/service/lakeformation/lakeformation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ func TestAccLakeFormation_serial(t *testing.T) {
"wildcardSelectPlus": testAccPermissions_twcWildcardSelectPlus,
},
"LFTags": {
"basic": testAccLFTag_basic,
"disappears": testAccLFTag_disappears,
"values": testAccLFTag_values,
"basic": testAccLFTag_basic,
"disappears": testAccLFTag_disappears,
"tagKeyComplex": testAccLFTag_TagKey_complex,
"values": testAccLFTag_values,
},
"ResourceLFTags": {
"basic": testAccResourceLFTags_basic,
Expand Down
10 changes: 6 additions & 4 deletions internal/service/lakeformation/lf_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,14 @@ func resourceLFTagDelete(ctx context.Context, d *schema.ResourceData, meta inter
return diags
}

func ReadLFTagID(id string) (catalogID string, tagKey string, err error) {
idParts := strings.Split(id, ":")
if len(idParts) != 2 {
func ReadLFTagID(id string) (string, string, error) {
catalogID, tagKey, found := strings.Cut(id, ":")

if !found {
return "", "", fmt.Errorf("unexpected format of ID (%q), expected CATALOG-ID:TAG-KEY", id)
}
return idParts[0], idParts[1], nil

return catalogID, tagKey, nil
}

func validateLFTagValues() schema.SchemaValidateFunc {
Expand Down
76 changes: 76 additions & 0 deletions internal/service/lakeformation/lf_tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,58 @@ import (
tflakeformation "github.com/hashicorp/terraform-provider-aws/internal/service/lakeformation"
)

func TestReadLFTagID(t *testing.T) {
t.Parallel()

type testCase struct {
val string
catalogID string
tagKey string
expectError bool
}

tests := map[string]testCase{
"empty_string": {
expectError: true,
},
"invalid_id": {
val: "test",
expectError: true,
},
"valid_key_simple": {
val: "123344556:tagKey",
catalogID: "123344556",
tagKey: "tagKey",
},
"valid_key_complex": {
val: "123344556:keyPrefix:tagKey",
catalogID: "123344556",
tagKey: "keyPrefix:tagKey",
},
}

for name, test := range tests {
name, test := name, test
t.Run(name, func(t *testing.T) {
t.Parallel()

catalogID, tagKey, err := tflakeformation.ReadLFTagID(test.val)

if err == nil && test.expectError {
t.Fatal("expected error")
}

if err != nil && !test.expectError {
t.Fatalf("got unexpected error: %s", err)
}

if test.catalogID != catalogID || test.tagKey != tagKey {
t.Fatalf("expected catalogID (%s), tagKey (%s), got catalogID (%s), tagKey (%s)", test.catalogID, test.tagKey, catalogID, tagKey)
}
})
}
}

func testAccLFTag_basic(t *testing.T) {
ctx := acctest.Context(t)
resourceName := "aws_lakeformation_lf_tag.test"
Expand Down Expand Up @@ -47,6 +99,30 @@ func testAccLFTag_basic(t *testing.T) {
})
}

func testAccLFTag_TagKey_complex(t *testing.T) {
ctx := acctest.Context(t)
resourceName := "aws_lakeformation_lf_tag.test"
rName := fmt.Sprintf("%s:%s", sdkacctest.RandomWithPrefix(acctest.ResourcePrefix), "subKey")

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, lakeformation.EndpointsID) },
ErrorCheck: acctest.ErrorCheck(t, lakeformation.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckLFTagsDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccLFTagConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckLFTagExists(ctx, resourceName),
resource.TestCheckResourceAttr(resourceName, "key", rName),
resource.TestCheckResourceAttr(resourceName, "values.0", "value"),
acctest.CheckResourceAttrAccountID(resourceName, "catalog_id"),
),
},
},
})
}

func testAccLFTag_disappears(t *testing.T) {
ctx := acctest.Context(t)
resourceName := "aws_lakeformation_lf_tag.test"
Expand Down