Skip to content

Commit

Permalink
Rename policy tag to LF tag
Browse files Browse the repository at this point in the history
  • Loading branch information
danielcmessias committed Aug 3, 2021
1 parent ba62404 commit c0f51dc
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .changelog/19523.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```release-note:new-resource
aws_lakeformation_policy_tag
aws_lakeformation_lf_tag
```
2 changes: 1 addition & 1 deletion aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ func Provider() *schema.Provider {
"aws_kms_ciphertext": resourceAwsKmsCiphertext(),
"aws_lakeformation_data_lake_settings": resourceAwsLakeFormationDataLakeSettings(),
"aws_lakeformation_permissions": resourceAwsLakeFormationPermissions(),
"aws_lakeformation_policy_tag": resourceAwsLakeFormationPolicyTag(),
"aws_lakeformation_lf_tag": resourceAwsLakeFormationLFTag(),
"aws_lakeformation_resource": resourceAwsLakeFormationResource(),
"aws_lambda_alias": resourceAwsLambdaAlias(),
"aws_lambda_code_signing_config": resourceAwsLambdaCodeSigningConfig(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

func resourceAwsLakeFormationPolicyTag() *schema.Resource {
func resourceAwsLakeFormationLFTag() *schema.Resource {
return &schema.Resource{
Create: resourceAwsLakeFormationPolicyTagCreate,
Read: resourceAwsLakeFormationPolicyTagRead,
Update: resourceAwsLakeFormationPolicyTagUpdate,
Delete: resourceAwsLakeFormationPolicyTagDelete,
Create: resourceAwsLakeFormationLFTagCreate,
Read: resourceAwsLakeFormationLFTagRead,
Update: resourceAwsLakeFormationLFTagUpdate,
Delete: resourceAwsLakeFormationLFTagDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Expand All @@ -36,7 +36,7 @@ func resourceAwsLakeFormationPolicyTag() *schema.Resource {
MaxItems: 15,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validatePolicyTagValues(),
ValidateFunc: validateLFTagValues(),
},
Set: schema.HashString,
},
Expand All @@ -50,7 +50,7 @@ func resourceAwsLakeFormationPolicyTag() *schema.Resource {
}
}

func resourceAwsLakeFormationPolicyTagCreate(d *schema.ResourceData, meta interface{}) error {
func resourceAwsLakeFormationLFTagCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).lakeformationconn

tagKey := d.Get("key").(string)
Expand All @@ -71,18 +71,18 @@ func resourceAwsLakeFormationPolicyTagCreate(d *schema.ResourceData, meta interf

_, err := conn.CreateLFTag(input)
if err != nil {
return fmt.Errorf("Error creating Lake Formation Policy Tag: %w", err)
return fmt.Errorf("Error creating Lake Formation LF-Tag: %w", err)
}

d.SetId(fmt.Sprintf("%s:%s", catalogID, tagKey))

return resourceAwsLakeFormationPolicyTagRead(d, meta)
return resourceAwsLakeFormationLFTagRead(d, meta)
}

func resourceAwsLakeFormationPolicyTagRead(d *schema.ResourceData, meta interface{}) error {
func resourceAwsLakeFormationLFTagRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).lakeformationconn

catalogID, tagKey, err := readPolicyTagID(d.Id())
catalogID, tagKey, err := readLFTagID(d.Id())
if err != nil {
return err
}
Expand All @@ -95,12 +95,12 @@ func resourceAwsLakeFormationPolicyTagRead(d *schema.ResourceData, meta interfac
output, err := conn.GetLFTag(input)
if err != nil {
if isAWSErr(err, lakeformation.ErrCodeEntityNotFoundException, "") {
log.Printf("[WARN] Lake Formation Policy Tag (%s) not found, removing from state", d.Id())
log.Printf("[WARN] Lake Formation LF-Tag (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
}

return fmt.Errorf("Error reading Lake Formation Policy Tag: %s", err.Error())
return fmt.Errorf("Error reading Lake Formation LF-Tag: %s", err.Error())
}

d.Set("key", output.TagKey)
Expand All @@ -110,10 +110,10 @@ func resourceAwsLakeFormationPolicyTagRead(d *schema.ResourceData, meta interfac
return nil
}

func resourceAwsLakeFormationPolicyTagUpdate(d *schema.ResourceData, meta interface{}) error {
func resourceAwsLakeFormationLFTagUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).lakeformationconn

catalogID, tagKey, err := readPolicyTagID(d.Id())
catalogID, tagKey, err := readLFTagID(d.Id())
if err != nil {
return err
}
Expand All @@ -139,16 +139,16 @@ func resourceAwsLakeFormationPolicyTagUpdate(d *schema.ResourceData, meta interf

_, err = conn.UpdateLFTag(input)
if err != nil {
return fmt.Errorf("Error updating Lake Formation Policy Tag (%s): %w", d.Id(), err)
return fmt.Errorf("Error updating Lake Formation LF-Tag (%s): %w", d.Id(), err)
}

return resourceAwsLakeFormationPolicyTagRead(d, meta)
return resourceAwsLakeFormationLFTagRead(d, meta)
}

func resourceAwsLakeFormationPolicyTagDelete(d *schema.ResourceData, meta interface{}) error {
func resourceAwsLakeFormationLFTagDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).lakeformationconn

catalogID, tagKey, err := readPolicyTagID(d.Id())
catalogID, tagKey, err := readLFTagID(d.Id())
if err != nil {
return err
}
Expand All @@ -160,21 +160,21 @@ func resourceAwsLakeFormationPolicyTagDelete(d *schema.ResourceData, meta interf

_, err = conn.DeleteLFTag(input)
if err != nil {
return fmt.Errorf("Error deleting Lake Formation Policy Tag (%s): %w", d.Id(), err)
return fmt.Errorf("Error deleting Lake Formation LF-Tag (%s): %w", d.Id(), err)
}

return nil
}

func readPolicyTagID(id string) (catalogID string, tagKey string, err error) {
func readLFTagID(id string) (catalogID string, tagKey string, err error) {
idParts := strings.Split(id, ":")
if len(idParts) != 2 {
return "", "", fmt.Errorf("Unexpected format of ID (%q), expected CATALOG-ID:TAG-KEY", id)
}
return idParts[0], idParts[1], nil
}

func validatePolicyTagValues() schema.SchemaValidateFunc {
func validateLFTagValues() schema.SchemaValidateFunc {
return validation.All(
validation.StringLenBetween(1, 255),
validation.StringMatch(regexp.MustCompile(`^([\p{L}\p{Z}\p{N}_.:\*\/=+\-@%]*)$`), ""),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

func testAccAWSLakeFormationPolicyTag_basic(t *testing.T) {
resourceName := "aws_lakeformation_policy_tag.test"
func testAccAWSLakeFormationLFTag_basic(t *testing.T) {
resourceName := "aws_lakeformation_lf_tag.test"
rKey := acctest.RandomWithPrefix("tf-acc-test")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPartitionHasServicePreCheck(lakeformation.EndpointsID, t) },
ErrorCheck: testAccErrorCheck(t, lakeformation.EndpointsID),
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSLakeFormationPolicyTagsDestroy,
CheckDestroy: testAccCheckAWSLakeFormationLFTagsDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSLakeFormationPolicyTagConfig_basic(rKey),
Config: testAccAWSLakeFormationLFTagConfig_basic(rKey),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSLakeFormationPolicyTagExists(resourceName),
testAccCheckAWSLakeFormationLFTagExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "key", rKey),
resource.TestCheckResourceAttr(resourceName, "values.0", "value"),
testAccCheckResourceAttrAccountID(resourceName, "catalog_id"),
Expand All @@ -41,43 +41,43 @@ func testAccAWSLakeFormationPolicyTag_basic(t *testing.T) {
})
}

func testAccAWSLakeFormationPolicyTag_disappears(t *testing.T) {
resourceName := "aws_lakeformation_policy_tag.test"
func testAccAWSLakeFormationLFTag_disappears(t *testing.T) {
resourceName := "aws_lakeformation_lf_tag.test"
rKey := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPartitionHasServicePreCheck(lakeformation.EndpointsID, t) },
ErrorCheck: testAccErrorCheck(t, lakeformation.EndpointsID),
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSLakeFormationPolicyTagsDestroy,
CheckDestroy: testAccCheckAWSLakeFormationLFTagsDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSLakeFormationPolicyTagConfig_basic(rKey),
Config: testAccAWSLakeFormationLFTagConfig_basic(rKey),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSLakeFormationPolicyTagExists(resourceName),
testAccCheckResourceDisappears(testAccProvider, resourceAwsLakeFormationPolicyTag(), resourceName),
testAccCheckAWSLakeFormationLFTagExists(resourceName),
testAccCheckResourceDisappears(testAccProvider, resourceAwsLakeFormationLFTag(), resourceName),
),
ExpectNonEmptyPlan: true,
},
},
})
}

func testAccAWSLakeFormationPolicyTag_values(t *testing.T) {
resourceName := "aws_lakeformation_policy_tag.test"
func testAccAWSLakeFormationLFTag_values(t *testing.T) {
resourceName := "aws_lakeformation_lf_tag.test"
rKey := acctest.RandomWithPrefix("tf-acc-test")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPartitionHasServicePreCheck(lakeformation.EndpointsID, t) },
ErrorCheck: testAccErrorCheck(t, lakeformation.EndpointsID),
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSLakeFormationPolicyTagsDestroy,
CheckDestroy: testAccCheckAWSLakeFormationLFTagsDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSLakeFormationPolicyTagConfig_values(rKey, []string{"value1", "value2"}),
Config: testAccAWSLakeFormationLFTagConfig_values(rKey, []string{"value1", "value2"}),
Destroy: false,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSLakeFormationPolicyTagExists(resourceName),
testAccCheckAWSLakeFormationLFTagExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "key", rKey),
resource.TestCheckResourceAttr(resourceName, "values.0", "value1"),
testAccCheckResourceAttrAccountID(resourceName, "catalog_id"),
Expand All @@ -90,9 +90,9 @@ func testAccAWSLakeFormationPolicyTag_values(t *testing.T) {
},
{
// Test an update that adds, removes and retains a tag value
Config: testAccAWSLakeFormationPolicyTagConfig_values(rKey, []string{"value1", "value3"}),
Config: testAccAWSLakeFormationLFTagConfig_values(rKey, []string{"value1", "value3"}),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSLakeFormationPolicyTagExists(resourceName),
testAccCheckAWSLakeFormationLFTagExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "key", rKey),
resource.TestCheckResourceAttr(resourceName, "values.0", "value1"),
resource.TestCheckResourceAttr(resourceName, "values.1", "value3"),
Expand All @@ -103,15 +103,15 @@ func testAccAWSLakeFormationPolicyTag_values(t *testing.T) {
})
}

func testAccCheckAWSLakeFormationPolicyTagsDestroy(s *terraform.State) error {
func testAccCheckAWSLakeFormationLFTagsDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).lakeformationconn

for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_lakeformation_policy_tag" {
if rs.Type != "aws_lakeformation_lf_tag" {
continue
}

catalogID, tagKey, err := readPolicyTagID(rs.Primary.ID)
catalogID, tagKey, err := readLFTagID(rs.Primary.ID)
if err != nil {
return err
}
Expand All @@ -131,13 +131,13 @@ func testAccCheckAWSLakeFormationPolicyTagsDestroy(s *terraform.State) error {
}
return err
}
return fmt.Errorf("Lake Formation Policy Tag (%s) still exists", rs.Primary.ID)
return fmt.Errorf("Lake Formation LF-Tag (%s) still exists", rs.Primary.ID)
}

return nil
}

func testAccCheckAWSLakeFormationPolicyTagExists(name string) resource.TestCheckFunc {
func testAccCheckAWSLakeFormationLFTagExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]
if !ok {
Expand All @@ -148,7 +148,7 @@ func testAccCheckAWSLakeFormationPolicyTagExists(name string) resource.TestCheck
return fmt.Errorf("No ID is set")
}

catalogID, tagKey, err := readPolicyTagID(rs.Primary.ID)
catalogID, tagKey, err := readLFTagID(rs.Primary.ID)
if err != nil {
return err
}
Expand All @@ -169,15 +169,15 @@ func testAccCheckAWSLakeFormationPolicyTagExists(name string) resource.TestCheck
}
}

func testAccAWSLakeFormationPolicyTagConfig_basic(rKey string) string {
func testAccAWSLakeFormationLFTagConfig_basic(rKey string) string {
return fmt.Sprintf(`
data "aws_caller_identity" "current" {}
resource "aws_lakeformation_data_lake_settings" "test" {
admins = [data.aws_caller_identity.current.arn]
}
resource "aws_lakeformation_policy_tag" "test" {
resource "aws_lakeformation_lf_tag" "test" {
key = %[1]q
values = ["value"]
Expand All @@ -187,7 +187,7 @@ resource "aws_lakeformation_policy_tag" "test" {
`, rKey)
}

func testAccAWSLakeFormationPolicyTagConfig_values(rKey string, values []string) string {
func testAccAWSLakeFormationLFTagConfig_values(rKey string, values []string) string {
quotedValues := make([]string, len(values))
for i, v := range values {
quotedValues[i] = strconv.Quote(v)
Expand All @@ -200,7 +200,7 @@ resource "aws_lakeformation_data_lake_settings" "test" {
admins = [data.aws_caller_identity.current.arn]
}
resource "aws_lakeformation_policy_tag" "test" {
resource "aws_lakeformation_lf_tag" "test" {
key = %[1]q
values = [%s]
Expand Down
8 changes: 4 additions & 4 deletions aws/resource_aws_lakeformation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ func TestAccAWSLakeFormation_serial(t *testing.T) {
"tableDataSource": testAccAWSLakeFormationPermissionsDataSource_table,
"tableWithColumnsDataSource": testAccAWSLakeFormationPermissionsDataSource_tableWithColumns,
},
"PolicyTag": {
"basic": testAccAWSLakeFormationPolicyTag_basic,
"disappears": testAccAWSLakeFormationPolicyTag_disappears,
"values": testAccAWSLakeFormationPolicyTag_values,
"LFTags": {
"basic": testAccAWSLakeFormationLFTag_basic,
"disappears": testAccAWSLakeFormationLFTag_disappears,
"values": testAccAWSLakeFormationLFTag_values,
},
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
---
subcategory: "Lake Formation"
layout: "aws"
page_title: "AWS: aws_lakeformation_policy_tag"
page_title: "AWS: aws_lakeformation_lf_tag"
description: |-
Creates a tag with the specified name and values.
---

# Resource: aws_lakeformation_policy_tag
# Resource: aws_lakeformation_lf_tag

Creates a policy tag with the specified name and values. Each key must have at least one value. The maximum number of values permitted is 15.
Creates an LF-Tag with the specified name and values. Each key must have at least one value. The maximum number of values permitted is 15.

## Example Usage

```terraform
resource "aws_lakeformation_policy_tag" "example" {
resource "aws_lakeformation_lf_tag" "example" {
key = "module"
values = ["Orders", "Sales", "Customers"]
}
Expand All @@ -35,9 +35,9 @@ In addition to all arguments above, the following attributes are exported:

## Import

Lake Formation Policy Tags can be imported using the `catalog_id:key`. If you have not set a Catalog ID specify the AWS Account ID that the database is in, e.g.
Lake Formation LF-Tags can be imported using the `catalog_id:key`. If you have not set a Catalog ID specify the AWS Account ID that the database is in, e.g.

```
$ terraform import aws_lakeformation_policy_tag.example 123456789012:some_key
$ terraform import aws_lakeformation_lf_tag.example 123456789012:some_key
```

0 comments on commit c0f51dc

Please sign in to comment.