@@ -135,13 +135,15 @@ func resourceTencentCloudDPrivateDnsZoneCreate(d *schema.ResourceData, meta inte
135135 defer tccommon .LogElapsed ("resource.tencentcloud_private_dns_zone.create" )()
136136
137137 var (
138- logId = tccommon .GetLogId (tccommon .ContextNil )
139- ctx = context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
140- request = privatedns .NewCreatePrivateZoneRequest ()
138+ logId = tccommon .GetLogId (tccommon .ContextNil )
139+ ctx = context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
140+ request = privatedns .NewCreatePrivateZoneRequest ()
141+ response = privatedns .NewCreatePrivateZoneResponse ()
141142 )
142143
143- domain := d .Get ("domain" ).(string )
144- request .Domain = & domain
144+ if v , ok := d .GetOk ("domain" ); ok {
145+ request .Domain = helper .String (v .(string ))
146+ }
145147
146148 if v , ok := d .GetOk ("tag_set" ); ok {
147149 tagSet := make ([]* privatedns.TagInfo , 0 , 10 )
@@ -151,8 +153,10 @@ func resourceTencentCloudDPrivateDnsZoneCreate(d *schema.ResourceData, meta inte
151153 TagKey : helper .String (m ["tag_key" ].(string )),
152154 TagValue : helper .String (m ["tag_value" ].(string )),
153155 }
156+
154157 tagSet = append (tagSet , & tagInfo )
155158 }
159+
156160 request .TagSet = tagSet
157161 }
158162
@@ -164,19 +168,19 @@ func resourceTencentCloudDPrivateDnsZoneCreate(d *schema.ResourceData, meta inte
164168 UniqVpcId : helper .String (m ["uniq_vpc_id" ].(string )),
165169 Region : helper .String (m ["region" ].(string )),
166170 }
171+
167172 vpcSet = append (vpcSet , & vpcInfo )
168173 }
174+
169175 request .VpcSet = vpcSet
170176 }
171177
172178 if v , ok := d .GetOk ("remark" ); ok {
173- remark := v .(string )
174- request .Remark = helper .String (remark )
179+ request .Remark = helper .String (v .(string ))
175180 }
176181
177182 if v , ok := d .GetOk ("dns_forward_status" ); ok {
178- dnsForwardStatus := v .(string )
179- request .DnsForwardStatus = helper .String (dnsForwardStatus )
183+ request .DnsForwardStatus = helper .String (v .(string ))
180184 }
181185
182186 if v , ok := d .GetOk ("account_vpc_set" ); ok {
@@ -189,32 +193,45 @@ func resourceTencentCloudDPrivateDnsZoneCreate(d *schema.ResourceData, meta inte
189193 Region : helper .String (m ["region" ].(string )),
190194 VpcName : helper .String (m ["vpc_name" ].(string )),
191195 }
196+
192197 accountVpcSet = append (accountVpcSet , & accountVpcInfo )
193198 }
199+
194200 request .AccountVpcSet = accountVpcSet
195201 }
196202
197203 if v , ok := d .GetOk ("cname_speedup_status" ); ok {
198- cnameSpeedupStatus := v .(string )
199- request .CnameSpeedupStatus = helper .String (cnameSpeedupStatus )
204+ request .CnameSpeedupStatus = helper .String (v .(string ))
200205 }
201206
202- result , err := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UsePrivateDnsClient ().CreatePrivateZone (request )
207+ err := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
208+ result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UsePrivateDnsClient ().CreatePrivateZone (request )
209+ if e != nil {
210+ return tccommon .RetryError (e )
211+ } else {
212+ log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " , logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
213+ }
214+
215+ if result == nil {
216+ e = fmt .Errorf ("create PrivateDns failed" )
217+ return resource .NonRetryableError (e )
218+ }
219+
220+ response = result
221+ return nil
222+ })
203223
204224 if err != nil {
205225 log .Printf ("[CRITAL]%s create PrivateDns failed, reason:%s\n " , logId , err .Error ())
206226 return err
207227 }
208228
209- response := result
210-
211229 id := * response .Response .ZoneId
212230 d .SetId (id )
213231
214232 client := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()
215233 tagService := svctag .NewTagService (client )
216234 region := client .Region
217-
218235 if tags := helper .GetTags (d , "tags" ); len (tags ) > 0 {
219236 resourceName := tccommon .BuildTagResourceName ("privatedns" , "zone" , region , id )
220237 if err := tagService .ModifyTags (ctx , resourceName , tags , nil ); err != nil {
0 commit comments