@@ -173,6 +173,32 @@ func resourceTencentCloudDcdbDbInstance() *schema.Resource {
173173 Description : "Whether to open the extranet access." ,
174174 },
175175
176+ "rs_access_strategy" : {
177+ Optional : true ,
178+ Type : schema .TypeInt ,
179+ Description : "RS nearest access mode, 0-no policy, 1-nearest access." ,
180+ },
181+
182+ "vip" : {
183+ Optional : true ,
184+ ForceNew : true ,
185+ Type : schema .TypeString ,
186+ Description : "The field is required to specify VIP." ,
187+ },
188+
189+ "vipv6" : {
190+ Optional : true ,
191+ ForceNew : true ,
192+ Type : schema .TypeString ,
193+ Description : "The field is required to specify VIPv6." ,
194+ },
195+
196+ "vport" : {
197+ Type : schema .TypeInt ,
198+ Computed : true ,
199+ Description : "Intranet port." ,
200+ },
201+
176202 "resource_tags" : {
177203 Optional : true ,
178204 Type : schema .TypeList ,
@@ -255,6 +281,8 @@ func resourceTencentCloudDcdbDbInstanceCreate(d *schema.ResourceData, meta inter
255281 response = dcdb .NewCreateDCDBInstanceResponse ()
256282 instanceId string
257283 dcnInstanceId string
284+ vpcId string
285+ subnetId string
258286 ipv6Flag int
259287 service = DcdbService {client : meta .(* TencentCloudClient ).apiV3Conn }
260288 )
@@ -442,6 +470,37 @@ func resourceTencentCloudDcdbDbInstanceCreate(d *schema.ResourceData, meta inter
442470 }
443471 }
444472
473+ if v , ok := d .GetOkExists ("rs_access_strategy" ); ok && v != nil {
474+ rsStrategy := v .(int )
475+ err := service .SetRealServerAccessStrategy (ctx , instanceId , rsStrategy )
476+ if err != nil {
477+ return err
478+ }
479+ }
480+
481+ var (
482+ vip string
483+ vipv6 string
484+ )
485+
486+ if v , ok := d .GetOk ("vip" ); ok {
487+ vip = v .(string )
488+ }
489+ if v , ok := d .GetOk ("vipv6" ); ok {
490+ vipv6 = v .(string )
491+ }
492+
493+ if vip != "" || vipv6 != "" {
494+ if vpcId == "" || subnetId == "" {
495+ return fmt .Errorf ("`vpc_id` and `subnet_id` cannot be empty when setting `vip` or `vipv6` fields!" )
496+ }
497+
498+ err := service .SetNetworkVip (ctx , instanceId , vpcId , subnetId , vip , vipv6 )
499+ if err != nil {
500+ return err
501+ }
502+ }
503+
445504 return resourceTencentCloudDcdbDbInstanceRead (d , meta )
446505}
447506
@@ -617,6 +676,17 @@ func resourceTencentCloudDcdbDbInstanceRead(d *schema.ResourceData, meta interfa
617676 return err
618677 }
619678
679+ // set vip and vipv6
680+ if detail , err := service .DescribeDcdbDbInstanceDetailById (ctx , instanceId ); detail != nil {
681+ if detail != nil {
682+ _ = d .Set ("vip" , detail .Vip )
683+ _ = d .Set ("vipv6" , detail .Vip6 )
684+ _ = d .Set ("vport" , detail .Vport )
685+ }
686+ } else {
687+ return err
688+ }
689+
620690 return nil
621691}
622692
@@ -703,6 +773,15 @@ func resourceTencentCloudDcdbDbInstanceUpdate(d *schema.ResourceData, meta inter
703773 }
704774 // }
705775
776+ if v , ok := d .GetOkExists ("rs_access_strategy" ); ok && v != nil {
777+ rsStrategy := v .(int )
778+ err := service .SetRealServerAccessStrategy (ctx , instanceId , rsStrategy )
779+ if err != nil {
780+ return err
781+ }
782+ time .Sleep (2 * time .Second )
783+ }
784+
706785 if d .HasChange ("project_id" ) {
707786 if projectId , ok := d .GetOk ("project_id" ); ok {
708787 request := dcdb .NewModifyDBInstancesProjectRequest ()
@@ -726,6 +805,37 @@ func resourceTencentCloudDcdbDbInstanceUpdate(d *schema.ResourceData, meta inter
726805 }
727806 time .Sleep (2 * time .Second )
728807 }
808+
809+ if d .HasChange ("vip" ) || d .HasChange ("vipv6" ) {
810+ var (
811+ vip string
812+ vipv6 string
813+ vpcId string
814+ subnetId string
815+ )
816+ if v , ok := d .GetOk ("vip" ); ok {
817+ vip = v .(string )
818+ }
819+ if v , ok := d .GetOk ("vipv6" ); ok {
820+ vipv6 = v .(string )
821+ }
822+ if v , ok := d .GetOk ("vpc_id" ); ok {
823+ vpcId = v .(string )
824+ }
825+ if v , ok := d .GetOk ("subnet_id" ); ok {
826+ subnetId = v .(string )
827+ }
828+
829+ if vpcId == "" || subnetId == "" {
830+ return fmt .Errorf ("`vpc_id` and `subnet_id` cannot be empty when updating `vip` or `vipv6` fields!" )
831+ }
832+
833+ err := service .SetNetworkVip (ctx , instanceId , vpcId , subnetId , vip , vipv6 )
834+ if err != nil {
835+ return err
836+ }
837+ }
838+
729839 if d .HasChange ("vpc_id" ) {
730840 return fmt .Errorf ("`vpc_id` do not support change now." )
731841 }
0 commit comments