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

r/aws_glue_data_quality_ruleset - support target_table catalog_id #31926

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/31926.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_glue_data_quality_ruleset: Add `catalog_id` argument to `target_table` block
```
21 changes: 14 additions & 7 deletions internal/service/glue/data_quality_ruleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,12 @@ func ResourceDataQualityRuleset() *schema.Resource {
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
// not found in SDK
// "catalog_id": {
// Type: schema.TypeString,
// Optional: true,
// ForceNew: true,
// ValidateFunc: validation.StringLenBetween(1, 255),
// },
"catalog_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 255),
},
"database_name": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -223,6 +222,10 @@ func expandTargetTable(tfMap map[string]interface{}) *glue.DataQualityTargetTabl
TableName: aws.String(tfMap["table_name"].(string)),
}

if v, ok := tfMap["catalog_id"].(string); ok && v != "" {
apiObject.CatalogId = aws.String(v)
}

return apiObject
}

Expand All @@ -236,5 +239,9 @@ func flattenTargetTable(apiObject *glue.DataQualityTargetTable) []interface{} {
"table_name": aws.StringValue(apiObject.TableName),
}

if v := apiObject.CatalogId; v != nil {
tfMap["catalog_id"] = aws.StringValue(v)
}

return []interface{}{tfMap}
}
55 changes: 54 additions & 1 deletion internal/service/glue/data_quality_ruleset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func TestAccGlueDataQualityRuleset_updateDescription(t *testing.T) {
})
}

func TestAccGlueDataQualityRuleset_targetTable(t *testing.T) {
func TestAccGlueDataQualityRuleset_targetTableRequired(t *testing.T) {
ctx := acctest.Context(t)

rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
Expand All @@ -148,6 +148,42 @@ func TestAccGlueDataQualityRuleset_targetTable(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckDataQualityRulesetExists(ctx, resourceName),
resource.TestCheckResourceAttr(resourceName, "target_table.#", "1"),
resource.TestCheckResourceAttr(resourceName, "target_table.0.catalog_id", ""),
resource.TestCheckResourceAttrPair(resourceName, "target_table.0.database_name", "aws_glue_catalog_database.test", "name"),
resource.TestCheckResourceAttrPair(resourceName, "target_table.0.table_name", "aws_glue_catalog_table.test", "name"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccGlueDataQualityRuleset_targetTableFull(t *testing.T) {
ctx := acctest.Context(t)

rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
rName2 := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
rName3 := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
ruleset := "Rules = [Completeness \"colA\" between 0.4 and 0.8]"
resourceName := "aws_glue_data_quality_ruleset.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, glue.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckDataQualityRulesetDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccDataQualityRulesetConfig_targetTableFull(rName, rName2, rName3, ruleset),
Destroy: false,
Check: resource.ComposeTestCheckFunc(
testAccCheckDataQualityRulesetExists(ctx, resourceName),
resource.TestCheckResourceAttr(resourceName, "target_table.#", "1"),
resource.TestCheckResourceAttrPair(resourceName, "target_table.0.catalog_id", "aws_glue_catalog_table.test", "catalog_id"),
resource.TestCheckResourceAttrPair(resourceName, "target_table.0.database_name", "aws_glue_catalog_database.test", "name"),
resource.TestCheckResourceAttrPair(resourceName, "target_table.0.table_name", "aws_glue_catalog_table.test", "name"),
),
Expand Down Expand Up @@ -342,6 +378,23 @@ resource "aws_glue_data_quality_ruleset" "test" {
`, rName, ruleset))
}

func testAccDataQualityRulesetConfig_targetTableFull(rName, rName2, rName3, ruleset string) string {
return acctest.ConfigCompose(
testAccDataQualityRulesetConfigTargetTableConfigBasic(rName2, rName3),
fmt.Sprintf(`
resource "aws_glue_data_quality_ruleset" "test" {
name = %[1]q
ruleset = %[2]q

target_table {
catalog_id = aws_glue_catalog_table.test.catalog_id
database_name = aws_glue_catalog_database.test.name
table_name = aws_glue_catalog_table.test.name
}
}
`, rName, ruleset))
}

func testAccDataQualityRulesetConfig_tags1(rName, ruleset, tagKey1, tagValue1 string) string {
return fmt.Sprintf(`
resource "aws_glue_data_quality_ruleset" "test" {
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/glue_data_quality_ruleset.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ The following arguments are supported:

### target_table

* `catalog_id` - (Optional, Forces new resource) The catalog id where the AWS Glue table exists.
* `database_name` - (Required, Forces new resource) Name of the database where the AWS Glue table exists.
* `table_name` - (Required, Forces new resource) Name of the AWS Glue table.

Expand Down