@@ -861,7 +861,7 @@ func TestUpdateDiffGSI_Provisioned(t *testing.T) {
861861 tc .New [i ] = normalizeGSIMapValue (v .(map [string ]any ))
862862 }
863863
864- ops , err := tfdynamodb .UpdateDiffGSI (tc .Old , tc .New , awstypes .BillingModeProvisioned )
864+ ops , err := tfdynamodb .UpdateDiffGSI (tc .Old , tc .New , awstypes .BillingModeProvisioned , nil , nil )
865865 if err != nil {
866866 t .Fatal (err )
867867 }
@@ -1756,7 +1756,7 @@ func TestUpdateDiffGSI_OnDemand(t *testing.T) {
17561756 tc .New [i ] = normalizeGSIMapValue (v .(map [string ]any ))
17571757 }
17581758
1759- ops , err := tfdynamodb .UpdateDiffGSI (tc .Old , tc .New , awstypes .BillingModePayPerRequest )
1759+ ops , err := tfdynamodb .UpdateDiffGSI (tc .Old , tc .New , awstypes .BillingModePayPerRequest , nil , nil )
17601760 if err != nil {
17611761 t .Fatal (err )
17621762 }
@@ -1800,9 +1800,11 @@ func TestCheckIfGSIRecreateAttributesChanged(t *testing.T) {
18001800 t .Parallel ()
18011801
18021802 testCases := map [string ]struct {
1803- Old map [string ]any
1804- New map [string ]any
1805- Expected bool
1803+ Old map [string ]any
1804+ New map [string ]any
1805+ OldAttrTypes map [string ]string
1806+ NewAttrTypes map [string ]string
1807+ Expected bool
18061808 }{
18071809 "key_schema syntax unchanged" : {
18081810 // State has hash_key/range_key, config only has key_schema
@@ -1888,13 +1890,70 @@ func TestCheckIfGSIRecreateAttributesChanged(t *testing.T) {
18881890 },
18891891 Expected : true ,
18901892 },
1893+ "hash_key attribute type changed S to N" : {
1894+ Old : map [string ]any {
1895+ names .AttrName : "gsi1" ,
1896+ "hash_key" : "alternate_id" ,
1897+ "range_key" : "" ,
1898+ "projection_type" : "ALL" ,
1899+ "key_schema" : nil ,
1900+ },
1901+ New : map [string ]any {
1902+ names .AttrName : "gsi1" ,
1903+ "hash_key" : "alternate_id" ,
1904+ "range_key" : "" ,
1905+ "projection_type" : "ALL" ,
1906+ "key_schema" : nil ,
1907+ },
1908+ OldAttrTypes : map [string ]string {"alternate_id" : "S" },
1909+ NewAttrTypes : map [string ]string {"alternate_id" : "N" },
1910+ Expected : true ,
1911+ },
1912+ "hash_key attribute type unchanged" : {
1913+ Old : map [string ]any {
1914+ names .AttrName : "gsi1" ,
1915+ "hash_key" : "alternate_id" ,
1916+ "range_key" : "" ,
1917+ "projection_type" : "ALL" ,
1918+ "key_schema" : nil ,
1919+ },
1920+ New : map [string ]any {
1921+ names .AttrName : "gsi1" ,
1922+ "hash_key" : "alternate_id" ,
1923+ "range_key" : "" ,
1924+ "projection_type" : "ALL" ,
1925+ "key_schema" : nil ,
1926+ },
1927+ OldAttrTypes : map [string ]string {"alternate_id" : "S" },
1928+ NewAttrTypes : map [string ]string {"alternate_id" : "S" },
1929+ Expected : false ,
1930+ },
1931+ "range_key attribute type changed S to N" : {
1932+ Old : map [string ]any {
1933+ names .AttrName : "gsi1" ,
1934+ "hash_key" : "pk" ,
1935+ "range_key" : "sk" ,
1936+ "projection_type" : "ALL" ,
1937+ "key_schema" : nil ,
1938+ },
1939+ New : map [string ]any {
1940+ names .AttrName : "gsi1" ,
1941+ "hash_key" : "pk" ,
1942+ "range_key" : "sk" ,
1943+ "projection_type" : "ALL" ,
1944+ "key_schema" : nil ,
1945+ },
1946+ OldAttrTypes : map [string ]string {"pk" : "S" , "sk" : "S" },
1947+ NewAttrTypes : map [string ]string {"pk" : "S" , "sk" : "N" },
1948+ Expected : true ,
1949+ },
18911950 }
18921951
18931952 for name , tc := range testCases {
18941953 t .Run (name , func (t * testing.T ) {
18951954 t .Parallel ()
18961955
1897- got := tfdynamodb .CheckIfGSIRecreateAttributesChanged (tc .Old , tc .New )
1956+ got := tfdynamodb .CheckIfGSIRecreateAttributesChanged (tc .Old , tc .New , tc . OldAttrTypes , tc . NewAttrTypes )
18981957 if got != tc .Expected {
18991958 t .Errorf ("expected %v, got %v" , tc .Expected , got )
19001959 }
@@ -4810,6 +4869,23 @@ func TestAccDynamoDBTable_attributeUpdate(t *testing.T) {
48104869 Check : resource .ComposeAggregateTestCheckFunc (
48114870 testAccCheckInitialTableExists (ctx , t , resourceName , & conf ),
48124871 ),
4872+ ConfigPlanChecks : resource.ConfigPlanChecks {
4873+ PreApply : []plancheck.PlanCheck {
4874+ plancheck .ExpectResourceAction (resourceName , plancheck .ResourceActionCreate ),
4875+ },
4876+ },
4877+ ConfigStateChecks : []statecheck.StateCheck {
4878+ statecheck .ExpectKnownValue (resourceName , tfjsonpath .New ("attribute" ), knownvalue .SetExact ([]knownvalue.Check {
4879+ knownvalue .ObjectExact (map [string ]knownvalue.Check {
4880+ names .AttrName : knownvalue .StringExact ("staticHashKey" ),
4881+ names .AttrType : knownvalue .StringExact ("S" ),
4882+ }),
4883+ knownvalue .ObjectExact (map [string ]knownvalue.Check {
4884+ names .AttrName : knownvalue .StringExact ("firstKey" ),
4885+ names .AttrType : knownvalue .StringExact ("S" ),
4886+ }),
4887+ })),
4888+ },
48134889 },
48144890 {
48154891 ResourceName : resourceName ,
@@ -4821,18 +4897,73 @@ func TestAccDynamoDBTable_attributeUpdate(t *testing.T) {
48214897 Check : resource .ComposeAggregateTestCheckFunc (
48224898 testAccCheckInitialTableExists (ctx , t , resourceName , & conf ),
48234899 ),
4900+ ConfigPlanChecks : resource.ConfigPlanChecks {
4901+ PreApply : []plancheck.PlanCheck {
4902+ plancheck .ExpectResourceAction (resourceName , plancheck .ResourceActionUpdate ),
4903+ },
4904+ },
4905+ ConfigStateChecks : []statecheck.StateCheck {
4906+ statecheck .ExpectKnownValue (resourceName , tfjsonpath .New ("attribute" ), knownvalue .SetExact ([]knownvalue.Check {
4907+ knownvalue .ObjectExact (map [string ]knownvalue.Check {
4908+ names .AttrName : knownvalue .StringExact ("staticHashKey" ),
4909+ names .AttrType : knownvalue .StringExact ("S" ),
4910+ }),
4911+ knownvalue .ObjectExact (map [string ]knownvalue.Check {
4912+ names .AttrName : knownvalue .StringExact ("firstKey" ),
4913+ names .AttrType : knownvalue .StringExact ("N" ),
4914+ }),
4915+ })),
4916+ },
48244917 },
48254918 { // New attribute addition (index update)
48264919 Config : testAccTableConfig_twoAttributes (rName , "firstKey" , "secondKey" , "firstKey" , "N" , "secondKey" , "S" ),
48274920 Check : resource .ComposeAggregateTestCheckFunc (
48284921 testAccCheckInitialTableExists (ctx , t , resourceName , & conf ),
48294922 ),
4923+ ConfigPlanChecks : resource.ConfigPlanChecks {
4924+ PreApply : []plancheck.PlanCheck {
4925+ plancheck .ExpectResourceAction (resourceName , plancheck .ResourceActionUpdate ),
4926+ },
4927+ },
4928+ ConfigStateChecks : []statecheck.StateCheck {
4929+ statecheck .ExpectKnownValue (resourceName , tfjsonpath .New ("attribute" ), knownvalue .SetExact ([]knownvalue.Check {
4930+ knownvalue .ObjectExact (map [string ]knownvalue.Check {
4931+ names .AttrName : knownvalue .StringExact ("staticHashKey" ),
4932+ names .AttrType : knownvalue .StringExact ("S" ),
4933+ }),
4934+ knownvalue .ObjectExact (map [string ]knownvalue.Check {
4935+ names .AttrName : knownvalue .StringExact ("firstKey" ),
4936+ names .AttrType : knownvalue .StringExact ("N" ),
4937+ }),
4938+ knownvalue .ObjectExact (map [string ]knownvalue.Check {
4939+ names .AttrName : knownvalue .StringExact ("secondKey" ),
4940+ names .AttrType : knownvalue .StringExact ("S" ),
4941+ }),
4942+ })),
4943+ },
48304944 },
48314945 { // Attribute removal (index update)
48324946 Config : testAccTableConfig_oneAttribute (rName , "firstKey" , "firstKey" , "S" ),
48334947 Check : resource .ComposeAggregateTestCheckFunc (
48344948 testAccCheckInitialTableExists (ctx , t , resourceName , & conf ),
48354949 ),
4950+ ConfigPlanChecks : resource.ConfigPlanChecks {
4951+ PreApply : []plancheck.PlanCheck {
4952+ plancheck .ExpectResourceAction (resourceName , plancheck .ResourceActionUpdate ),
4953+ },
4954+ },
4955+ ConfigStateChecks : []statecheck.StateCheck {
4956+ statecheck .ExpectKnownValue (resourceName , tfjsonpath .New ("attribute" ), knownvalue .SetExact ([]knownvalue.Check {
4957+ knownvalue .ObjectExact (map [string ]knownvalue.Check {
4958+ names .AttrName : knownvalue .StringExact ("staticHashKey" ),
4959+ names .AttrType : knownvalue .StringExact ("S" ),
4960+ }),
4961+ knownvalue .ObjectExact (map [string ]knownvalue.Check {
4962+ names .AttrName : knownvalue .StringExact ("firstKey" ),
4963+ names .AttrType : knownvalue .StringExact ("S" ),
4964+ }),
4965+ })),
4966+ },
48364967 },
48374968 },
48384969 })
0 commit comments