@@ -114,6 +114,11 @@ Creation, truncation and append actions occur as one atomic update upon job comp
114114 Description : `Describes the Cloud KMS encryption key that will be used to protect destination BigQuery table.
115115The BigQuery Service Account associated with your project requires access to this encryption key.` ,
116116 },
117+ "kms_key_version" : {
118+ Type : schema .TypeString ,
119+ Computed : true ,
120+ Description : `Describes the Cloud KMS encryption key version used to protect destination BigQuery table.` ,
121+ },
117122 },
118123 },
119124 },
@@ -407,6 +412,11 @@ Creation, truncation and append actions occur as one atomic update upon job comp
407412 Description : `Describes the Cloud KMS encryption key that will be used to protect destination BigQuery table.
408413The BigQuery Service Account associated with your project requires access to this encryption key.` ,
409414 },
415+ "kms_key_version" : {
416+ Type : schema .TypeString ,
417+ Computed : true ,
418+ Description : `Describes the Cloud KMS encryption key version used to protect destination BigQuery table.` ,
419+ },
410420 },
411421 },
412422 },
@@ -645,6 +655,11 @@ or of the form 'projects/{{project}}/datasets/{{dataset_id}}' if not.`,
645655 Description : `Describes the Cloud KMS encryption key that will be used to protect destination BigQuery table.
646656The BigQuery Service Account associated with your project requires access to this encryption key.` ,
647657 },
658+ "kms_key_version" : {
659+ Type : schema .TypeString ,
660+ Computed : true ,
661+ Description : `Describes the Cloud KMS encryption key version used to protect destination BigQuery table.` ,
662+ },
648663 },
649664 },
650665 },
@@ -1344,21 +1359,29 @@ func flattenBigQueryJobConfigurationQuerySchemaUpdateOptions(v interface{}, d *s
13441359 return v
13451360}
13461361
1362+ // KmsKeyName switched from using a key name to a key version, this will separate the key name from the key version and save them
1363+ // separately in state. https://github.com/hashicorp/terraform-provider-google/issues/9208
13471364func flattenBigQueryJobConfigurationQueryDestinationEncryptionConfiguration (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
13481365 if v == nil {
1349- return nil
1366+ return [] map [ string ] interface {}{}
13501367 }
1351- original := v .(map [string ]interface {})
1352- if len (original ) == 0 {
1353- return nil
1368+
1369+ kmsKeyName := v .(map [string ]interface {})["kmsKeyName" ].(string )
1370+ re := regexp .MustCompile (`(projects/.*/locations/.*/keyRings/.*/cryptoKeys/.*)/cryptoKeyVersions/.*` )
1371+ paths := re .FindStringSubmatch (kmsKeyName )
1372+
1373+ if len (paths ) > 0 {
1374+ return []map [string ]interface {}{
1375+ {
1376+ "kms_key_name" : paths [0 ],
1377+ "kms_key_version" : kmsKeyName ,
1378+ },
1379+ }
13541380 }
1355- transformed := make (map [string ]interface {})
1356- transformed ["kms_key_name" ] =
1357- flattenBigQueryJobConfigurationQueryDestinationEncryptionConfigurationKmsKeyName (original ["kmsKeyName" ], d , config )
1358- return []interface {}{transformed }
1359- }
1360- func flattenBigQueryJobConfigurationQueryDestinationEncryptionConfigurationKmsKeyName (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
1361- return v
1381+
1382+ // The key name was returned, no need to set the version
1383+ return []map [string ]interface {}{{"kms_key_name" : kmsKeyName , "kms_key_version" : "" }}
1384+
13621385}
13631386
13641387func flattenBigQueryJobConfigurationQueryScriptOptions (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
@@ -1578,21 +1601,29 @@ func flattenBigQueryJobConfigurationLoadTimePartitioningField(v interface{}, d *
15781601 return v
15791602}
15801603
1604+ // KmsKeyName switched from using a key name to a key version, this will separate the key name from the key version and save them
1605+ // separately in state. https://github.com/hashicorp/terraform-provider-google/issues/9208
15811606func flattenBigQueryJobConfigurationLoadDestinationEncryptionConfiguration (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
15821607 if v == nil {
1583- return nil
1608+ return [] map [ string ] interface {}{}
15841609 }
1585- original := v .(map [string ]interface {})
1586- if len (original ) == 0 {
1587- return nil
1610+
1611+ kmsKeyName := v .(map [string ]interface {})["kmsKeyName" ].(string )
1612+ re := regexp .MustCompile (`(projects/.*/locations/.*/keyRings/.*/cryptoKeys/.*)/cryptoKeyVersions/.*` )
1613+ paths := re .FindStringSubmatch (kmsKeyName )
1614+
1615+ if len (paths ) > 0 {
1616+ return []map [string ]interface {}{
1617+ {
1618+ "kms_key_name" : paths [0 ],
1619+ "kms_key_version" : kmsKeyName ,
1620+ },
1621+ }
15881622 }
1589- transformed := make (map [string ]interface {})
1590- transformed ["kms_key_name" ] =
1591- flattenBigQueryJobConfigurationLoadDestinationEncryptionConfigurationKmsKeyName (original ["kmsKeyName" ], d , config )
1592- return []interface {}{transformed }
1593- }
1594- func flattenBigQueryJobConfigurationLoadDestinationEncryptionConfigurationKmsKeyName (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
1595- return v
1623+
1624+ // The key name was returned, no need to set the version
1625+ return []map [string ]interface {}{{"kms_key_name" : kmsKeyName , "kms_key_version" : "" }}
1626+
15961627}
15971628
15981629func flattenBigQueryJobConfigurationCopy (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
@@ -1672,21 +1703,29 @@ func flattenBigQueryJobConfigurationCopyWriteDisposition(v interface{}, d *schem
16721703 return v
16731704}
16741705
1706+ // KmsKeyName switched from using a key name to a key version, this will separate the key name from the key version and save them
1707+ // separately in state. https://github.com/hashicorp/terraform-provider-google/issues/9208
16751708func flattenBigQueryJobConfigurationCopyDestinationEncryptionConfiguration (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
16761709 if v == nil {
1677- return nil
1710+ return [] map [ string ] interface {}{}
16781711 }
1679- original := v .(map [string ]interface {})
1680- if len (original ) == 0 {
1681- return nil
1712+
1713+ kmsKeyName := v .(map [string ]interface {})["kmsKeyName" ].(string )
1714+ re := regexp .MustCompile (`(projects/.*/locations/.*/keyRings/.*/cryptoKeys/.*)/cryptoKeyVersions/.*` )
1715+ paths := re .FindStringSubmatch (kmsKeyName )
1716+
1717+ if len (paths ) > 0 {
1718+ return []map [string ]interface {}{
1719+ {
1720+ "kms_key_name" : paths [0 ],
1721+ "kms_key_version" : kmsKeyName ,
1722+ },
1723+ }
16821724 }
1683- transformed := make (map [string ]interface {})
1684- transformed ["kms_key_name" ] =
1685- flattenBigQueryJobConfigurationCopyDestinationEncryptionConfigurationKmsKeyName (original ["kmsKeyName" ], d , config )
1686- return []interface {}{transformed }
1687- }
1688- func flattenBigQueryJobConfigurationCopyDestinationEncryptionConfigurationKmsKeyName (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
1689- return v
1725+
1726+ // The key name was returned, no need to set the version
1727+ return []map [string ]interface {}{{"kms_key_name" : kmsKeyName , "kms_key_version" : "" }}
1728+
16901729}
16911730
16921731func flattenBigQueryJobConfigurationExtract (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
@@ -2259,13 +2298,24 @@ func expandBigQueryJobConfigurationQueryDestinationEncryptionConfiguration(v int
22592298 transformed ["kmsKeyName" ] = transformedKmsKeyName
22602299 }
22612300
2301+ transformedKmsKeyVersion , err := expandBigQueryJobConfigurationQueryDestinationEncryptionConfigurationKmsKeyVersion (original ["kms_key_version" ], d , config )
2302+ if err != nil {
2303+ return nil , err
2304+ } else if val := reflect .ValueOf (transformedKmsKeyVersion ); val .IsValid () && ! isEmptyValue (val ) {
2305+ transformed ["kmsKeyVersion" ] = transformedKmsKeyVersion
2306+ }
2307+
22622308 return transformed , nil
22632309}
22642310
22652311func expandBigQueryJobConfigurationQueryDestinationEncryptionConfigurationKmsKeyName (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
22662312 return v , nil
22672313}
22682314
2315+ func expandBigQueryJobConfigurationQueryDestinationEncryptionConfigurationKmsKeyVersion (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
2316+ return v , nil
2317+ }
2318+
22692319func expandBigQueryJobConfigurationQueryScriptOptions (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
22702320 l := v .([]interface {})
22712321 if len (l ) == 0 || l [0 ] == nil {
@@ -2614,13 +2664,24 @@ func expandBigQueryJobConfigurationLoadDestinationEncryptionConfiguration(v inte
26142664 transformed ["kmsKeyName" ] = transformedKmsKeyName
26152665 }
26162666
2667+ transformedKmsKeyVersion , err := expandBigQueryJobConfigurationLoadDestinationEncryptionConfigurationKmsKeyVersion (original ["kms_key_version" ], d , config )
2668+ if err != nil {
2669+ return nil , err
2670+ } else if val := reflect .ValueOf (transformedKmsKeyVersion ); val .IsValid () && ! isEmptyValue (val ) {
2671+ transformed ["kmsKeyVersion" ] = transformedKmsKeyVersion
2672+ }
2673+
26172674 return transformed , nil
26182675}
26192676
26202677func expandBigQueryJobConfigurationLoadDestinationEncryptionConfigurationKmsKeyName (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
26212678 return v , nil
26222679}
26232680
2681+ func expandBigQueryJobConfigurationLoadDestinationEncryptionConfigurationKmsKeyVersion (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
2682+ return v , nil
2683+ }
2684+
26242685func expandBigQueryJobConfigurationCopy (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
26252686 l := v .([]interface {})
26262687 if len (l ) == 0 || l [0 ] == nil {
@@ -2762,13 +2823,24 @@ func expandBigQueryJobConfigurationCopyDestinationEncryptionConfiguration(v inte
27622823 transformed ["kmsKeyName" ] = transformedKmsKeyName
27632824 }
27642825
2826+ transformedKmsKeyVersion , err := expandBigQueryJobConfigurationCopyDestinationEncryptionConfigurationKmsKeyVersion (original ["kms_key_version" ], d , config )
2827+ if err != nil {
2828+ return nil , err
2829+ } else if val := reflect .ValueOf (transformedKmsKeyVersion ); val .IsValid () && ! isEmptyValue (val ) {
2830+ transformed ["kmsKeyVersion" ] = transformedKmsKeyVersion
2831+ }
2832+
27652833 return transformed , nil
27662834}
27672835
27682836func expandBigQueryJobConfigurationCopyDestinationEncryptionConfigurationKmsKeyName (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
27692837 return v , nil
27702838}
27712839
2840+ func expandBigQueryJobConfigurationCopyDestinationEncryptionConfigurationKmsKeyVersion (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
2841+ return v , nil
2842+ }
2843+
27722844func expandBigQueryJobConfigurationExtract (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
27732845 l := v .([]interface {})
27742846 if len (l ) == 0 || l [0 ] == nil {
0 commit comments