@@ -46,34 +46,40 @@ func ResourceTencentCloudCosBucketDomainCertificateAttachment() *schema.Resource
46
46
Type : schema .TypeList ,
47
47
MaxItems : 1 ,
48
48
Required : true ,
49
+ ForceNew : true ,
49
50
Description : "Certificate info." ,
50
51
Elem : & schema.Resource {
51
52
Schema : map [string ]* schema.Schema {
52
53
"cert_type" : {
53
54
Type : schema .TypeString ,
54
55
Required : true ,
56
+ ForceNew : true ,
55
57
Description : "Certificate type." ,
56
58
},
57
59
"custom_cert" : {
58
60
Type : schema .TypeList ,
59
61
MaxItems : 1 ,
60
62
Required : true ,
63
+ ForceNew : true ,
61
64
Description : "Custom certificate." ,
62
65
Elem : & schema.Resource {
63
66
Schema : map [string ]* schema.Schema {
64
67
"cert_id" : {
65
68
Type : schema .TypeString ,
66
69
Optional : true ,
70
+ ForceNew : true ,
67
71
Description : "ID of certificate." ,
68
72
},
69
73
"cert" : {
70
74
Type : schema .TypeString ,
71
75
Required : true ,
76
+ ForceNew : true ,
72
77
Description : "Public key of certificate." ,
73
78
},
74
79
"private_key" : {
75
80
Type : schema .TypeString ,
76
81
Required : true ,
82
+ ForceNew : true ,
77
83
Description : "Private key of certificate." ,
78
84
},
79
85
},
@@ -85,6 +91,7 @@ func ResourceTencentCloudCosBucketDomainCertificateAttachment() *schema.Resource
85
91
"domain" : {
86
92
Type : schema .TypeString ,
87
93
Required : true ,
94
+ ForceNew : true ,
88
95
Description : "The name of domain." ,
89
96
},
90
97
},
@@ -98,9 +105,11 @@ func resourceTencentCloudCosBucketDomainCertificateAttachmentCreate(d *schema.Re
98
105
defer tccommon .LogElapsed ("resource.tencentcloud_cos_bucket_domain_certificate_attachment.create" )()
99
106
defer tccommon .InconsistentCheck (d , meta )()
100
107
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
+ )
104
113
105
114
if v , ok := d .GetOk ("bucket" ); ok {
106
115
bucket = v .(string )
@@ -115,19 +124,24 @@ func resourceTencentCloudCosBucketDomainCertificateAttachmentCreate(d *schema.Re
115
124
if v , ok := certMap ["cert_type" ]; ok {
116
125
certificateInfo .CertType = v .(string )
117
126
}
127
+
118
128
if CustomCertMap , ok := helper .InterfaceToMap (certMap , "custom_cert" ); ok {
119
129
customCert := cos.BucketDomainCustomCert {}
120
130
if v , ok := CustomCertMap ["cert_id" ]; ok {
121
131
customCert .CertId = v .(string )
122
132
}
133
+
123
134
if v , ok := CustomCertMap ["cert" ]; ok {
124
135
customCert .Cert = v .(string )
125
136
}
137
+
126
138
if v , ok := CustomCertMap ["private_key" ]; ok {
127
139
customCert .PrivateKey = v .(string )
128
140
}
141
+
129
142
certificateInfo .CustomCert = & customCert
130
143
}
144
+
131
145
option .CertificateInfo = & certificateInfo
132
146
}
133
147
@@ -141,10 +155,14 @@ func resourceTencentCloudCosBucketDomainCertificateAttachmentCreate(d *schema.Re
141
155
if e != nil {
142
156
return tccommon .RetryError (e )
143
157
} else {
158
+ if result == nil || result .Response == nil {
159
+ return resource .NonRetryableError (fmt .Errorf ("Create cos domain certificate failed, Response is nil." ))
160
+ }
161
+
144
162
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 )
147
164
}
165
+
148
166
return nil
149
167
})
150
168
@@ -153,25 +171,23 @@ func resourceTencentCloudCosBucketDomainCertificateAttachmentCreate(d *schema.Re
153
171
return err
154
172
}
155
173
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 ))
159
175
return nil
160
176
}
161
177
162
178
func resourceTencentCloudCosBucketDomainCertificateAttachmentRead (d * schema.ResourceData , meta interface {}) error {
163
179
defer tccommon .LogElapsed ("resource.tencentcloud_cos_bucket_domain_certificate_attachment.read" )()
164
180
defer tccommon .InconsistentCheck (d , meta )()
165
181
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
+ )
172
188
173
189
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 )
175
191
if err != nil {
176
192
return err
177
193
}
@@ -187,14 +203,15 @@ func resourceTencentCloudCosBucketDomainCertificateAttachmentRead(d *schema.Reso
187
203
}
188
204
189
205
func 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" )()
192
207
defer tccommon .InconsistentCheck (d , meta )()
193
208
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
+ )
198
215
199
216
if err := service .DeleteCosBucketDomainCertificate (ctx , id ); err != nil {
200
217
return err
0 commit comments