@@ -247,6 +247,31 @@ func resourceAwsGlueCatalogTable() *schema.Resource {
247247 Optional : true ,
248248 ValidateFunc : validation .StringLenBetween (0 , 409600 ),
249249 },
250+ "partition_index" : {
251+ Type : schema .TypeList ,
252+ Optional : true ,
253+ ForceNew : true ,
254+ MaxItems : 3 ,
255+ Elem : & schema.Resource {
256+ Schema : map [string ]* schema.Schema {
257+ "index_name" : {
258+ Type : schema .TypeString ,
259+ Required : true ,
260+ ValidateFunc : validation .StringLenBetween (1 , 255 ),
261+ },
262+ "keys" : {
263+ Type : schema .TypeSet ,
264+ Required : true ,
265+ MinItems : 1 ,
266+ Elem : & schema.Schema {Type : schema .TypeString },
267+ },
268+ "index_status" : {
269+ Type : schema .TypeString ,
270+ Computed : true ,
271+ },
272+ },
273+ },
274+ },
250275 },
251276 }
252277}
@@ -266,9 +291,10 @@ func resourceAwsGlueCatalogTableCreate(d *schema.ResourceData, meta interface{})
266291 name := d .Get ("name" ).(string )
267292
268293 input := & glue.CreateTableInput {
269- CatalogId : aws .String (catalogID ),
270- DatabaseName : aws .String (dbName ),
271- TableInput : expandGlueTableInput (d ),
294+ CatalogId : aws .String (catalogID ),
295+ DatabaseName : aws .String (dbName ),
296+ TableInput : expandGlueTableInput (d ),
297+ PartitionIndexes : expandGlueTablePartitionIndexes (d .Get ("partition_index" ).([]interface {})),
272298 }
273299
274300 log .Printf ("[DEBUG] Glue catalog table input: %#v" , input )
@@ -341,6 +367,22 @@ func resourceAwsGlueCatalogTableRead(d *schema.ResourceData, meta interface{}) e
341367 return fmt .Errorf ("error setting parameters: %w" , err )
342368 }
343369
370+ partIndexInput := & glue.GetPartitionIndexesInput {
371+ CatalogId : out .Table .CatalogId ,
372+ TableName : out .Table .Name ,
373+ DatabaseName : out .Table .DatabaseName ,
374+ }
375+ partOut , err := conn .GetPartitionIndexes (partIndexInput )
376+ if err != nil {
377+ return fmt .Errorf ("error getting Glue Partition Indexes: %w" , err )
378+ }
379+
380+ if partOut != nil && len (partOut .PartitionIndexDescriptorList ) > 0 {
381+ if err := d .Set ("partition_index" , flattenGluePartitionIndexes (partOut .PartitionIndexDescriptorList )); err != nil {
382+ return fmt .Errorf ("error setting partition_index: %w" , err )
383+ }
384+ }
385+
344386 return nil
345387}
346388
@@ -429,6 +471,25 @@ func expandGlueTableInput(d *schema.ResourceData) *glue.TableInput {
429471 return tableInput
430472}
431473
474+ func expandGlueTablePartitionIndexes (a []interface {}) []* glue.PartitionIndex {
475+ partitionIndexes := make ([]* glue.PartitionIndex , 0 , len (a ))
476+
477+ for _ , m := range a {
478+ partitionIndexes = append (partitionIndexes , expandGlueTablePartitionIndex (m .(map [string ]interface {})))
479+ }
480+
481+ return partitionIndexes
482+ }
483+
484+ func expandGlueTablePartitionIndex (m map [string ]interface {}) * glue.PartitionIndex {
485+ partitionIndex := & glue.PartitionIndex {
486+ IndexName : aws .String (m ["index_name" ].(string )),
487+ Keys : expandStringSet (m ["keys" ].(* schema.Set )),
488+ }
489+
490+ return partitionIndex
491+ }
492+
432493func expandGlueStorageDescriptor (l []interface {}) * glue.StorageDescriptor {
433494 if len (l ) == 0 || l [0 ] == nil {
434495 return nil
@@ -646,6 +707,43 @@ func flattenGlueColumn(c *glue.Column) map[string]interface{} {
646707 return column
647708}
648709
710+ func flattenGluePartitionIndexes (cs []* glue.PartitionIndexDescriptor ) []map [string ]interface {} {
711+ partitionIndexSlice := make ([]map [string ]interface {}, len (cs ))
712+ if len (cs ) > 0 {
713+ for i , v := range cs {
714+ partitionIndexSlice [i ] = flattenGluePartitionIndex (v )
715+ }
716+ }
717+
718+ return partitionIndexSlice
719+ }
720+
721+ func flattenGluePartitionIndex (c * glue.PartitionIndexDescriptor ) map [string ]interface {} {
722+ partitionIndex := make (map [string ]interface {})
723+
724+ if c == nil {
725+ return partitionIndex
726+ }
727+
728+ if v := aws .StringValue (c .IndexName ); v != "" {
729+ partitionIndex ["index_name" ] = v
730+ }
731+
732+ if v := aws .StringValue (c .IndexStatus ); v != "" {
733+ partitionIndex ["index_status" ] = v
734+ }
735+
736+ if c .Keys != nil {
737+ names := make ([]* string , 0 , len (c .Keys ))
738+ for _ , key := range c .Keys {
739+ names = append (names , key .Name )
740+ }
741+ partitionIndex ["keys" ] = flattenStringSet (names )
742+ }
743+
744+ return partitionIndex
745+ }
746+
649747func flattenGlueSerDeInfo (s * glue.SerDeInfo ) []map [string ]interface {} {
650748 if s == nil {
651749 serDeInfos := make ([]map [string ]interface {}, 0 )
0 commit comments