@@ -46,34 +46,40 @@ func ResourceTencentCloudCosBucketDomainCertificateAttachment() *schema.Resource
4646 Type : schema .TypeList ,
4747 MaxItems : 1 ,
4848 Required : true ,
49+ ForceNew : true ,
4950 Description : "Certificate info." ,
5051 Elem : & schema.Resource {
5152 Schema : map [string ]* schema.Schema {
5253 "cert_type" : {
5354 Type : schema .TypeString ,
5455 Required : true ,
56+ ForceNew : true ,
5557 Description : "Certificate type." ,
5658 },
5759 "custom_cert" : {
5860 Type : schema .TypeList ,
5961 MaxItems : 1 ,
6062 Required : true ,
63+ ForceNew : true ,
6164 Description : "Custom certificate." ,
6265 Elem : & schema.Resource {
6366 Schema : map [string ]* schema.Schema {
6467 "cert_id" : {
6568 Type : schema .TypeString ,
6669 Optional : true ,
70+ ForceNew : true ,
6771 Description : "ID of certificate." ,
6872 },
6973 "cert" : {
7074 Type : schema .TypeString ,
7175 Required : true ,
76+ ForceNew : true ,
7277 Description : "Public key of certificate." ,
7378 },
7479 "private_key" : {
7580 Type : schema .TypeString ,
7681 Required : true ,
82+ ForceNew : true ,
7783 Description : "Private key of certificate." ,
7884 },
7985 },
@@ -85,6 +91,7 @@ func ResourceTencentCloudCosBucketDomainCertificateAttachment() *schema.Resource
8591 "domain" : {
8692 Type : schema .TypeString ,
8793 Required : true ,
94+ ForceNew : true ,
8895 Description : "The name of domain." ,
8996 },
9097 },
@@ -98,9 +105,11 @@ func resourceTencentCloudCosBucketDomainCertificateAttachmentCreate(d *schema.Re
98105 defer tccommon .LogElapsed ("resource.tencentcloud_cos_bucket_domain_certificate_attachment.create" )()
99106 defer tccommon .InconsistentCheck (d , meta )()
100107
101- logId := tccommon .GetLogId (tccommon .ContextNil )
102- ctx := context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
103- var bucket string
108+ var (
109+ logId = tccommon .GetLogId (tccommon .ContextNil )
110+ ctx = context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
111+ bucket string
112+ )
104113
105114 if v , ok := d .GetOk ("bucket" ); ok {
106115 bucket = v .(string )
@@ -115,19 +124,24 @@ func resourceTencentCloudCosBucketDomainCertificateAttachmentCreate(d *schema.Re
115124 if v , ok := certMap ["cert_type" ]; ok {
116125 certificateInfo .CertType = v .(string )
117126 }
127+
118128 if CustomCertMap , ok := helper .InterfaceToMap (certMap , "custom_cert" ); ok {
119129 customCert := cos.BucketDomainCustomCert {}
120130 if v , ok := CustomCertMap ["cert_id" ]; ok {
121131 customCert .CertId = v .(string )
122132 }
133+
123134 if v , ok := CustomCertMap ["cert" ]; ok {
124135 customCert .Cert = v .(string )
125136 }
137+
126138 if v , ok := CustomCertMap ["private_key" ]; ok {
127139 customCert .PrivateKey = v .(string )
128140 }
141+
129142 certificateInfo .CustomCert = & customCert
130143 }
144+
131145 option .CertificateInfo = & certificateInfo
132146 }
133147
@@ -141,10 +155,14 @@ func resourceTencentCloudCosBucketDomainCertificateAttachmentCreate(d *schema.Re
141155 if e != nil {
142156 return tccommon .RetryError (e )
143157 } else {
158+ if result == nil || result .Response == nil {
159+ return resource .NonRetryableError (fmt .Errorf ("Create cos domain certificate failed, Response is nil." ))
160+ }
161+
144162 request , _ := xml .Marshal (option )
145- log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " ,
146- logId , "PutDomainCertificate" , request , result .Response .Body )
163+ log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " , logId , "PutDomainCertificate" , request , result .Response .Body )
147164 }
165+
148166 return nil
149167 })
150168
@@ -153,25 +171,23 @@ func resourceTencentCloudCosBucketDomainCertificateAttachmentCreate(d *schema.Re
153171 return err
154172 }
155173
156- ids := strings .Join ([]string {bucket , option .DomainList [0 ]}, tccommon .FILED_SP )
157- d .SetId (ids )
158-
174+ d .SetId (strings .Join ([]string {bucket , option .DomainList [0 ]}, tccommon .FILED_SP ))
159175 return nil
160176}
161177
162178func resourceTencentCloudCosBucketDomainCertificateAttachmentRead (d * schema.ResourceData , meta interface {}) error {
163179 defer tccommon .LogElapsed ("resource.tencentcloud_cos_bucket_domain_certificate_attachment.read" )()
164180 defer tccommon .InconsistentCheck (d , meta )()
165181
166- logId := tccommon . GetLogId ( tccommon . ContextNil )
167- ctx := context . WithValue ( context . TODO (), tccommon .LogIdKey , logId )
168-
169- service : = CosService {client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
170-
171- id := d . Id ( )
182+ var (
183+ logId = tccommon . GetLogId ( tccommon .ContextNil )
184+ ctx = context . WithValue ( context . TODO (), tccommon . LogIdKey , logId )
185+ service = CosService {client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
186+ id = d . Id ()
187+ )
172188
173189 certResult , bucket , err := service .DescribeCosBucketDomainCertificate (ctx , id )
174- log .Printf ("[DEBUG] resource `bucketDomainCertificate certResult:%s`\n " , certResult )
190+ log .Printf ("[DEBUG] resource `bucketDomainCertificate certResult: %s`\n " , certResult )
175191 if err != nil {
176192 return err
177193 }
@@ -187,14 +203,15 @@ func resourceTencentCloudCosBucketDomainCertificateAttachmentRead(d *schema.Reso
187203}
188204
189205func resourceTencentCloudCosBucketDomainCertificateAttachmentDelete (d * schema.ResourceData , meta interface {}) error {
190- id := d .Id ()
191- defer tccommon .LogElapsed ("resource.tencentcloud_cos_bucket_domain_certificate_attachment.delete id:" , id )()
206+ defer tccommon .LogElapsed ("resource.tencentcloud_cos_bucket_domain_certificate_attachment.delete" )()
192207 defer tccommon .InconsistentCheck (d , meta )()
193208
194- logId := tccommon .GetLogId (tccommon .ContextNil )
195- ctx := context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
196-
197- service := CosService {client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
209+ var (
210+ logId = tccommon .GetLogId (tccommon .ContextNil )
211+ ctx = context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
212+ service = CosService {client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
213+ id = d .Id ()
214+ )
198215
199216 if err := service .DeleteCosBucketDomainCertificate (ctx , id ); err != nil {
200217 return err
0 commit comments