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_quicksight_data_set: Allow physical_table_map to be optional #31867

Merged
merged 2 commits into from
Jun 13, 2023
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/31863.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_quicksight_data_set: Allow physical table map to be optional
```
10 changes: 1 addition & 9 deletions internal/service/quicksight/data_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func ResourceDataSet() *schema.Resource {
},
"physical_table_map": {
Type: schema.TypeSet,
Required: true,
Optional: true,
MaxItems: 32,
Elem: physicalTableMapSchema(),
},
Expand Down Expand Up @@ -1644,10 +1644,6 @@ func expandDataSetUntagColumnOperation(tfList []interface{}) *quicksight.UntagCo
}

func expandDataSetPhysicalTableMap(tfSet *schema.Set) map[string]*quicksight.PhysicalTable {
if tfSet.Len() == 0 {
return nil
}

physicalTableMap := make(map[string]*quicksight.PhysicalTable)
for _, v := range tfSet.List() {
vMap, ok := v.(map[string]interface{})
Expand Down Expand Up @@ -2426,10 +2422,6 @@ func flattenJoinKeyProperties(apiObject *quicksight.JoinKeyProperties) map[strin
}

func flattenPhysicalTableMap(apiObject map[string]*quicksight.PhysicalTable, resourceSchema *schema.Resource) *schema.Set {
if len(apiObject) == 0 {
return nil
}

var tfList []interface{}
for k, v := range apiObject {
if v == nil {
Expand Down
121 changes: 121 additions & 0 deletions internal/service/quicksight/data_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,46 @@ func TestAccQuickSightDataSet_tags(t *testing.T) {
})
}

func TestAccQuickSightDataSet_noPhysicalTableMap(t *testing.T) {
ctx := acctest.Context(t)
var dataSet quicksight.DataSet
resourceName := "aws_quicksight_data_set.test"
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
rId := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, quicksight.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckDataSetDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccDataSetConfigNoPhysicalTableMap(rId, rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckDataSetExists(ctx, resourceName, &dataSet),
resource.TestCheckResourceAttr(resourceName, "data_set_id", rId),
acctest.CheckResourceAttrRegionalARN(resourceName, "arn", "quicksight", fmt.Sprintf("dataset/%s", rId)),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "import_mode", "SPICE"),
resource.TestCheckResourceAttr(resourceName, "physical_table_map.#", "0"),
resource.TestCheckResourceAttr(resourceName, "logical_table_map.#", "3"),
resource.TestCheckResourceAttr(resourceName, "logical_table_map.0.logical_table_map_id", "joined"),
resource.TestCheckResourceAttr(resourceName, "logical_table_map.0.alias", "j"),
resource.TestCheckResourceAttr(resourceName, "logical_table_map.0.source.0.join_instruction.0.right_operand", "right"),
resource.TestCheckResourceAttr(resourceName, "logical_table_map.0.source.0.join_instruction.0.left_operand", "left"),
resource.TestCheckResourceAttr(resourceName, "logical_table_map.0.source.0.join_instruction.0.type", "INNER"),
resource.TestCheckResourceAttr(resourceName, "logical_table_map.0.source.0.join_instruction.0.on_clause", "Column1 = Column2"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccCheckDataSetExists(ctx context.Context, resourceName string, dataSet *quicksight.DataSet) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[resourceName]
Expand Down Expand Up @@ -1034,3 +1074,84 @@ resource "aws_quicksight_data_set" "test" {
}
`, rId, rName, key1, value1, key2, value2))
}

func testAccDataSetConfigNoPhysicalTableMap(rId, rName string) string {
return acctest.ConfigCompose(
testAccDataSetConfigBase(rId, rName),
fmt.Sprintf(`
resource "aws_quicksight_data_set" "left" {
data_set_id = "%[1]s-left"
name = "%[2]s-left"
import_mode = "SPICE"

physical_table_map {
physical_table_map_id = "%[1]s-left"
s3_source {
data_source_arn = aws_quicksight_data_source.test.arn
input_columns {
name = "Column1"
type = "STRING"
}
upload_settings {
format = "JSON"
}
}
}
}

resource "aws_quicksight_data_set" "right" {
data_set_id = "%[1]s-right"
name = "%[2]s-right"
import_mode = "SPICE"

physical_table_map {
physical_table_map_id = "%[1]s-right"
s3_source {
data_source_arn = aws_quicksight_data_source.test.arn
input_columns {
name = "Column2"
type = "STRING"
}
upload_settings {
format = "JSON"
}
}
}
}

resource "aws_quicksight_data_set" "test" {
data_set_id = %[1]q
name = %[2]q
import_mode = "SPICE"

logical_table_map {
logical_table_map_id = "right"
alias = "r"
source {
data_set_arn = aws_quicksight_data_set.right.arn
}
}

logical_table_map {
logical_table_map_id = "left"
alias = "l"
source {
data_set_arn = aws_quicksight_data_set.left.arn
}
}

logical_table_map {
logical_table_map_id = "joined"
alias = "j"
source {
join_instruction {
left_operand = "left"
right_operand = "right"
type = "INNER"
on_clause = "Column1 = Column2"
}
}
}
}
`, rId, rName))
}