@@ -56,6 +56,11 @@ func DataSourceTencentCloudVpcSubnets() *schema.Resource {
5656 Optional : true ,
5757 Description : "Filter subnet with this CIDR." ,
5858 },
59+ "cdc_id" : {
60+ Type : schema .TypeString ,
61+ Optional : true ,
62+ Description : "ID of CDC instance." ,
63+ },
5964 "is_remote_vpc_snat" : {
6065 Type : schema .TypeBool ,
6166 Optional : true ,
@@ -103,6 +108,11 @@ func DataSourceTencentCloudVpcSubnets() *schema.Resource {
103108 Computed : true ,
104109 Description : "A network address block of the subnet." ,
105110 },
111+ "cdc_id" : {
112+ Type : schema .TypeString ,
113+ Computed : true ,
114+ Description : "ID of CDC instance." ,
115+ },
106116 "is_default" : {
107117 Type : schema .TypeBool ,
108118 Computed : true ,
@@ -143,14 +153,12 @@ func DataSourceTencentCloudVpcSubnets() *schema.Resource {
143153func dataSourceTencentCloudVpcSubnetsRead (d * schema.ResourceData , meta interface {}) error {
144154 defer tccommon .LogElapsed ("data_source.tencentcloud_vpc_subnets.read" )()
145155
146- logId := tccommon .GetLogId (tccommon .ContextNil )
147- ctx := context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
148-
149- vpcService := VpcService {client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
150- tagService := svctag .NewTagService (meta .(tccommon.ProviderMeta ).GetAPIV3Conn ())
151- region := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().Region
152-
153156 var (
157+ logId = tccommon .GetLogId (tccommon .ContextNil )
158+ ctx = context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
159+ vpcService = VpcService {client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
160+ tagService = svctag .NewTagService (meta .(tccommon.ProviderMeta ).GetAPIV3Conn ())
161+ region = meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().Region
154162 vpcId string
155163 subnetId string
156164 name string
@@ -159,7 +167,9 @@ func dataSourceTencentCloudVpcSubnetsRead(d *schema.ResourceData, meta interface
159167 isRemoteVpcSNAT * bool
160168 tagKey string
161169 cidrBlock string
170+ cdcId string
162171 )
172+
163173 if temp , ok := d .GetOk ("vpc_id" ); ok {
164174 vpcId = temp .(string )
165175 }
@@ -192,6 +202,10 @@ func dataSourceTencentCloudVpcSubnetsRead(d *schema.ResourceData, meta interface
192202 cidrBlock = temp .(string )
193203 }
194204
205+ if temp , ok := d .GetOk ("cdc_id" ); ok {
206+ cdcId = temp .(string )
207+ }
208+
195209 var (
196210 tags = helper .GetTags (d , "tags" )
197211 infos []VpcSubnetBasicInfo
@@ -202,10 +216,12 @@ func dataSourceTencentCloudVpcSubnetsRead(d *schema.ResourceData, meta interface
202216 infos , err = vpcService .DescribeSubnets (ctx , subnetId , vpcId ,
203217 name , availabilityZone , tags ,
204218 isDefault , isRemoteVpcSNAT , tagKey ,
205- cidrBlock )
219+ cidrBlock , cdcId )
220+
206221 if err != nil {
207222 return tccommon .RetryError (err , tccommon .InternalError )
208223 }
224+
209225 return nil
210226 })
211227
@@ -214,15 +230,13 @@ func dataSourceTencentCloudVpcSubnetsRead(d *schema.ResourceData, meta interface
214230 }
215231
216232 var infoList = make ([]map [string ]interface {}, 0 , len (infos ))
217-
218233 for _ , item := range infos {
219234 respTags , err := tagService .DescribeResourceTags (ctx , "vpc" , "subnet" , region , item .subnetId )
220235 if err != nil {
221236 return err
222237 }
223238
224239 var infoMap = make (map [string ]interface {})
225-
226240 infoMap ["availability_zone" ] = item .zone
227241 infoMap ["vpc_id" ] = item .vpcId
228242 infoMap ["subnet_id" ] = item .subnetId
@@ -234,7 +248,6 @@ func dataSourceTencentCloudVpcSubnetsRead(d *schema.ResourceData, meta interface
234248 infoMap ["available_ip_count" ] = item .availableIpCount
235249 infoMap ["create_time" ] = item .createTime
236250 infoMap ["tags" ] = respTags
237-
238251 infoList = append (infoList , infoMap )
239252 }
240253
@@ -254,6 +267,7 @@ func dataSourceTencentCloudVpcSubnetsRead(d *schema.ResourceData, meta interface
254267 "cidrBlock" : cidrBlock ,
255268 "tags" : tags ,
256269 })
270+
257271 if err != nil {
258272 log .Printf ("[CRITAL]%s create data source id error, reason:%s\n " , logId , err .Error ())
259273 return err
@@ -271,5 +285,6 @@ func dataSourceTencentCloudVpcSubnetsRead(d *schema.ResourceData, meta interface
271285 return err
272286 }
273287 }
288+
274289 return nil
275290}
0 commit comments