@@ -188,7 +188,12 @@ func ResourceTencentCloudCosBucket() *schema.Resource {
188
188
"encryption_algorithm" : {
189
189
Type : schema .TypeString ,
190
190
Optional : true ,
191
- Description : "The server-side encryption algorithm to use. Valid value is `AES256`." ,
191
+ Description : "The server-side encryption algorithm to use. Valid value is `AES256` or `KMS`." ,
192
+ },
193
+ "kms_id" : {
194
+ Type : schema .TypeString ,
195
+ Optional : true ,
196
+ Description : "The KMS Master Key ID. When `encryption_algorithm` is set to `KMS`, please provide it." ,
192
197
},
193
198
"versioning_enable" : {
194
199
Type : schema .TypeBool ,
@@ -718,13 +723,16 @@ func resourceTencentCloudCosBucketRead(d *schema.ResourceData, meta interface{})
718
723
}
719
724
720
725
// read the encryption algorithm
721
- encryption , err := cosService .GetBucketEncryption (ctx , bucket , cdcId )
726
+ encryption , kmsId , err := cosService .GetBucketEncryption (ctx , bucket , cdcId )
722
727
if err != nil {
723
728
return err
724
729
}
725
730
if err = d .Set ("encryption_algorithm" , encryption ); err != nil {
726
731
return fmt .Errorf ("setting encryption error: %v" , err )
727
732
}
733
+ if err = d .Set ("kms_id" , kmsId ); err != nil {
734
+ return fmt .Errorf ("setting kms_id error: %v" , err )
735
+ }
728
736
729
737
// read the versioning
730
738
versioning , err := cosService .GetBucketVersioning (ctx , bucket , cdcId )
@@ -894,12 +902,11 @@ func resourceTencentCloudCosBucketUpdate(d *schema.ResourceData, meta interface{
894
902
895
903
}
896
904
897
- if d .HasChange ("encryption_algorithm" ) {
905
+ if d .HasChange ("encryption_algorithm" ) || d . HasChange ( "kms_id" ) {
898
906
err := resourceTencentCloudCosBucketEncryptionUpdate (ctx , meta , d )
899
907
if err != nil {
900
908
return err
901
909
}
902
-
903
910
}
904
911
905
912
if d .HasChange ("versioning_enable" ) {
@@ -1005,6 +1012,7 @@ func resourceTencentCloudCosBucketEncryptionUpdate(ctx context.Context, meta int
1005
1012
1006
1013
bucket := d .Get ("bucket" ).(string )
1007
1014
encryption := d .Get ("encryption_algorithm" ).(string )
1015
+ kmsId := d .Get ("kms_id" ).(string )
1008
1016
cdcId := d .Get ("cdc_id" ).(string )
1009
1017
if encryption == "" {
1010
1018
request := s3.DeleteBucketEncryptionInput {
@@ -1029,7 +1037,8 @@ func resourceTencentCloudCosBucketEncryptionUpdate(ctx context.Context, meta int
1029
1037
request .ServerSideEncryptionConfiguration = & s3.ServerSideEncryptionConfiguration {}
1030
1038
rules := make ([]* s3.ServerSideEncryptionRule , 0 )
1031
1039
defaultRule := & s3.ServerSideEncryptionByDefault {
1032
- SSEAlgorithm : aws .String (encryption ),
1040
+ SSEAlgorithm : aws .String (encryption ),
1041
+ KMSMasterKeyID : aws .String (kmsId ),
1033
1042
}
1034
1043
rule := & s3.ServerSideEncryptionRule {
1035
1044
ApplyServerSideEncryptionByDefault : defaultRule ,
0 commit comments