1
1
package tcr
2
2
3
3
import (
4
- tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
5
- svctag "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/tag"
6
-
7
4
"context"
8
5
"fmt"
6
+ tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
7
+ svctag "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/tag"
9
8
"log"
10
9
"strings"
11
10
"time"
@@ -98,6 +97,11 @@ func ResourceTencentCloudTcrInstance() *schema.Resource {
98
97
Optional : true ,
99
98
Description : "Replication region ID, check the example at the top of page to find out id of region." ,
100
99
},
100
+ "region_name" : {
101
+ Type : schema .TypeString ,
102
+ Optional : true ,
103
+ Description : "Copy instance region name." ,
104
+ },
101
105
"syn_tag" : {
102
106
Type : schema .TypeBool ,
103
107
Optional : true ,
@@ -189,9 +193,15 @@ func resourceTencentCloudTcrInstanceCreate(d *schema.ResourceData, meta interfac
189
193
providerRegionId := RegionIdMap [client .Region ]
190
194
for i := range v {
191
195
rep := v [i ].(map [string ]interface {})
192
- repRegion := fmt .Sprintf ("%d" , rep ["region_id" ].(int ))
193
- if repRegion == providerRegionId {
194
- return fmt .Errorf ("replication %s region is same with instance region %s (%s)" , repRegion , providerRegionId , client .Region )
196
+ repRegionId := fmt .Sprintf ("%d" , rep ["region_id" ].(int ))
197
+ repRegionName := rep ["region_name" ].(string )
198
+
199
+ if repRegionId != "0" && repRegionId == providerRegionId {
200
+ return fmt .Errorf ("replication region id:%s region is same with instance region %s (%s)" , repRegionId , providerRegionId , client .Region )
201
+ }
202
+
203
+ if repRegionName != "" && repRegionName == client .Region {
204
+ return fmt .Errorf ("replication region name:%s region is same with instance region %s" , repRegionName , client .Region )
195
205
}
196
206
}
197
207
}
@@ -776,7 +786,12 @@ func resourceTencentCloudTcrReplicationSet(ctx context.Context, d *schema.Resour
776
786
if ! ok {
777
787
return 0
778
788
}
779
- return item ["region_id" ].(int )
789
+ regionId := item ["region_id" ].(int )
790
+ regionName := item ["region_name" ].(string )
791
+ if regionId == 0 && regionName != "" {
792
+ regionId = helper .StrToInt (RegionIdMap [regionName ])
793
+ }
794
+ return regionId
780
795
}
781
796
782
797
oSet := schema .NewSet (setFunc , ov )
@@ -792,7 +807,14 @@ func resourceTencentCloudTcrReplicationSet(ctx context.Context, d *schema.Resour
792
807
request := tcr .NewCreateReplicationInstanceRequest ()
793
808
replica := list [i ].(map [string ]interface {})
794
809
request .RegistryId = helper .String (d .Id ())
795
- request .ReplicationRegionId = helper .IntUint64 (replica ["region_id" ].(int ))
810
+ regionId := replica ["region_id" ].(int )
811
+ regionName := replica ["region_name" ].(string )
812
+ if regionId != 0 {
813
+ request .ReplicationRegionId = helper .IntUint64 (regionId )
814
+ }
815
+ if regionName != "" {
816
+ request .ReplicationRegionName = helper .String (regionName )
817
+ }
796
818
if synTag , ok := replica ["syn_tag" ].(bool ); ok {
797
819
request .SyncTag = & synTag
798
820
}
@@ -832,6 +854,11 @@ func resourceTencentCloudTcrReplicationSet(ctx context.Context, d *schema.Resour
832
854
replica := list [i ].(map [string ]interface {})
833
855
id , ok := replica ["id" ].(string )
834
856
regionId := replica ["region_id" ].(int )
857
+ regionName := replica ["region_name" ].(string )
858
+ if regionId == 0 && regionName != "" {
859
+ tmpRegionId := helper .StrToInt (RegionIdMap [regionName ])
860
+ regionId = tmpRegionId
861
+ }
835
862
if ! ok || id == "" {
836
863
errs = * multierror .Append (fmt .Errorf ("replication region %d has no id" , regionId ))
837
864
continue
@@ -863,6 +890,13 @@ func ResourceTencentCloudTcrFillReplicas(replicas []interface{}, registries []*t
863
890
for i := range replicas {
864
891
item := replicas [i ].(map [string ]interface {})
865
892
regionId := item ["region_id" ].(int )
893
+ regionName := item ["region_name" ].(string )
894
+
895
+ if regionId == 0 && regionName != "" {
896
+ tmpRegionId := helper .StrToInt (RegionIdMap [regionName ])
897
+ regionId = tmpRegionId
898
+ }
899
+
866
900
replicaRegionIndexes [regionId ] = i
867
901
}
868
902
@@ -871,12 +905,14 @@ func ResourceTencentCloudTcrFillReplicas(replicas []interface{}, registries []*t
871
905
item := registries [i ]
872
906
id := * item .ReplicationRegistryId
873
907
regionId := * item .ReplicationRegionId
908
+ regionName := * item .ReplicationRegionName
874
909
if index , ok := replicaRegionIndexes [int (regionId )]; ok && index >= 0 {
875
910
replicas [index ].(map [string ]interface {})["id" ] = id
876
911
} else {
877
912
newReplicas = append (newReplicas , map [string ]interface {}{
878
- "id" : id ,
879
- "region_id" : int (regionId ),
913
+ "id" : id ,
914
+ "region_id" : int (regionId ),
915
+ "region_name" : regionName ,
880
916
})
881
917
}
882
918
}
0 commit comments