Skip to content

Commit 374277a

Browse files
g-dxjar-b
andauthored
r/aws_quicksight_data_set: Allow physical_table_map to be optional (#31867)
* r/aws_quicksight_data_set: Allow physical_table_map to be optional Fixes #31863 * r/aws_quicksight_data_set(test): reuse config args --------- Co-authored-by: Jared Baker <jared.baker@hashicorp.com>
1 parent 43f8ee9 commit 374277a

File tree

3 files changed

+125
-9
lines changed

3 files changed

+125
-9
lines changed

.changelog/31863.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
resource/aws_quicksight_data_set: Allow physical table map to be optional
3+
```

internal/service/quicksight/data_set.go

+1-9
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func ResourceDataSet() *schema.Resource {
218218
},
219219
"physical_table_map": {
220220
Type: schema.TypeSet,
221-
Required: true,
221+
Optional: true,
222222
MaxItems: 32,
223223
Elem: physicalTableMapSchema(),
224224
},
@@ -1644,10 +1644,6 @@ func expandDataSetUntagColumnOperation(tfList []interface{}) *quicksight.UntagCo
16441644
}
16451645

16461646
func expandDataSetPhysicalTableMap(tfSet *schema.Set) map[string]*quicksight.PhysicalTable {
1647-
if tfSet.Len() == 0 {
1648-
return nil
1649-
}
1650-
16511647
physicalTableMap := make(map[string]*quicksight.PhysicalTable)
16521648
for _, v := range tfSet.List() {
16531649
vMap, ok := v.(map[string]interface{})
@@ -2426,10 +2422,6 @@ func flattenJoinKeyProperties(apiObject *quicksight.JoinKeyProperties) map[strin
24262422
}
24272423

24282424
func flattenPhysicalTableMap(apiObject map[string]*quicksight.PhysicalTable, resourceSchema *schema.Resource) *schema.Set {
2429-
if len(apiObject) == 0 {
2430-
return nil
2431-
}
2432-
24332425
var tfList []interface{}
24342426
for k, v := range apiObject {
24352427
if v == nil {

internal/service/quicksight/data_set_test.go

+121
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,46 @@ func TestAccQuickSightDataSet_tags(t *testing.T) {
453453
})
454454
}
455455

456+
func TestAccQuickSightDataSet_noPhysicalTableMap(t *testing.T) {
457+
ctx := acctest.Context(t)
458+
var dataSet quicksight.DataSet
459+
resourceName := "aws_quicksight_data_set.test"
460+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
461+
rId := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
462+
463+
resource.ParallelTest(t, resource.TestCase{
464+
PreCheck: func() { acctest.PreCheck(ctx, t) },
465+
ErrorCheck: acctest.ErrorCheck(t, quicksight.EndpointsID),
466+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
467+
CheckDestroy: testAccCheckDataSetDestroy(ctx),
468+
Steps: []resource.TestStep{
469+
{
470+
Config: testAccDataSetConfigNoPhysicalTableMap(rId, rName),
471+
Check: resource.ComposeTestCheckFunc(
472+
testAccCheckDataSetExists(ctx, resourceName, &dataSet),
473+
resource.TestCheckResourceAttr(resourceName, "data_set_id", rId),
474+
acctest.CheckResourceAttrRegionalARN(resourceName, "arn", "quicksight", fmt.Sprintf("dataset/%s", rId)),
475+
resource.TestCheckResourceAttr(resourceName, "name", rName),
476+
resource.TestCheckResourceAttr(resourceName, "import_mode", "SPICE"),
477+
resource.TestCheckResourceAttr(resourceName, "physical_table_map.#", "0"),
478+
resource.TestCheckResourceAttr(resourceName, "logical_table_map.#", "3"),
479+
resource.TestCheckResourceAttr(resourceName, "logical_table_map.0.logical_table_map_id", "joined"),
480+
resource.TestCheckResourceAttr(resourceName, "logical_table_map.0.alias", "j"),
481+
resource.TestCheckResourceAttr(resourceName, "logical_table_map.0.source.0.join_instruction.0.right_operand", "right"),
482+
resource.TestCheckResourceAttr(resourceName, "logical_table_map.0.source.0.join_instruction.0.left_operand", "left"),
483+
resource.TestCheckResourceAttr(resourceName, "logical_table_map.0.source.0.join_instruction.0.type", "INNER"),
484+
resource.TestCheckResourceAttr(resourceName, "logical_table_map.0.source.0.join_instruction.0.on_clause", "Column1 = Column2"),
485+
),
486+
},
487+
{
488+
ResourceName: resourceName,
489+
ImportState: true,
490+
ImportStateVerify: true,
491+
},
492+
},
493+
})
494+
}
495+
456496
func testAccCheckDataSetExists(ctx context.Context, resourceName string, dataSet *quicksight.DataSet) resource.TestCheckFunc {
457497
return func(s *terraform.State) error {
458498
rs, ok := s.RootModule().Resources[resourceName]
@@ -1034,3 +1074,84 @@ resource "aws_quicksight_data_set" "test" {
10341074
}
10351075
`, rId, rName, key1, value1, key2, value2))
10361076
}
1077+
1078+
func testAccDataSetConfigNoPhysicalTableMap(rId, rName string) string {
1079+
return acctest.ConfigCompose(
1080+
testAccDataSetConfigBase(rId, rName),
1081+
fmt.Sprintf(`
1082+
resource "aws_quicksight_data_set" "left" {
1083+
data_set_id = "%[1]s-left"
1084+
name = "%[2]s-left"
1085+
import_mode = "SPICE"
1086+
1087+
physical_table_map {
1088+
physical_table_map_id = "%[1]s-left"
1089+
s3_source {
1090+
data_source_arn = aws_quicksight_data_source.test.arn
1091+
input_columns {
1092+
name = "Column1"
1093+
type = "STRING"
1094+
}
1095+
upload_settings {
1096+
format = "JSON"
1097+
}
1098+
}
1099+
}
1100+
}
1101+
1102+
resource "aws_quicksight_data_set" "right" {
1103+
data_set_id = "%[1]s-right"
1104+
name = "%[2]s-right"
1105+
import_mode = "SPICE"
1106+
1107+
physical_table_map {
1108+
physical_table_map_id = "%[1]s-right"
1109+
s3_source {
1110+
data_source_arn = aws_quicksight_data_source.test.arn
1111+
input_columns {
1112+
name = "Column2"
1113+
type = "STRING"
1114+
}
1115+
upload_settings {
1116+
format = "JSON"
1117+
}
1118+
}
1119+
}
1120+
}
1121+
1122+
resource "aws_quicksight_data_set" "test" {
1123+
data_set_id = %[1]q
1124+
name = %[2]q
1125+
import_mode = "SPICE"
1126+
1127+
logical_table_map {
1128+
logical_table_map_id = "right"
1129+
alias = "r"
1130+
source {
1131+
data_set_arn = aws_quicksight_data_set.right.arn
1132+
}
1133+
}
1134+
1135+
logical_table_map {
1136+
logical_table_map_id = "left"
1137+
alias = "l"
1138+
source {
1139+
data_set_arn = aws_quicksight_data_set.left.arn
1140+
}
1141+
}
1142+
1143+
logical_table_map {
1144+
logical_table_map_id = "joined"
1145+
alias = "j"
1146+
source {
1147+
join_instruction {
1148+
left_operand = "left"
1149+
right_operand = "right"
1150+
type = "INNER"
1151+
on_clause = "Column1 = Column2"
1152+
}
1153+
}
1154+
}
1155+
}
1156+
`, rId, rName))
1157+
}

0 commit comments

Comments
 (0)