1
- // Code generated by iacg; DO NOT EDIT.
2
1
package postgresql
3
2
4
3
import (
@@ -68,41 +67,30 @@ func resourceTencentCloudPostgresqlInstanceNetworkAccessCreate(d *schema.Resourc
68
67
defer tccommon .LogElapsed ("resource.tencentcloud_postgresql_instance_network_access.create" )()
69
68
defer tccommon .InconsistentCheck (d , meta )()
70
69
71
- logId := tccommon .GetLogId (tccommon .ContextNil )
72
-
73
- ctx := tccommon .NewResourceLifeCycleHandleFuncContext (context .Background (), logId , d , meta )
74
-
75
70
var (
71
+ logId = tccommon .GetLogId (tccommon .ContextNil )
72
+ ctx = tccommon .NewResourceLifeCycleHandleFuncContext (context .Background (), logId , d , meta )
73
+ request = postgresqlv20170312 .NewCreateDBInstanceNetworkAccessRequest ()
74
+ response = postgresqlv20170312 .NewCreateDBInstanceNetworkAccessResponse ()
76
75
dbInsntaceId string
77
76
vpcId string
78
77
subnetId string
79
78
vip string
80
79
)
81
- var (
82
- request = postgresqlv20170312 .NewCreateDBInstanceNetworkAccessRequest ()
83
- response = postgresqlv20170312 .NewCreateDBInstanceNetworkAccessResponse ()
84
- )
85
-
86
- if v , ok := d .GetOk ("db_instance_id" ); ok {
87
- dbInsntaceId = v .(string )
88
- }
89
- if v , ok := d .GetOk ("vpc_id" ); ok {
90
- vpcId = v .(string )
91
- }
92
- if v , ok := d .GetOk ("subnet_id" ); ok {
93
- subnetId = v .(string )
94
- }
95
80
96
81
if v , ok := d .GetOk ("db_instance_id" ); ok {
97
82
request .DBInstanceId = helper .String (v .(string ))
83
+ dbInsntaceId = v .(string )
98
84
}
99
85
100
86
if v , ok := d .GetOk ("vpc_id" ); ok {
101
87
request .VpcId = helper .String (v .(string ))
88
+ vpcId = v .(string )
102
89
}
103
90
104
91
if v , ok := d .GetOk ("subnet_id" ); ok {
105
92
request .SubnetId = helper .String (v .(string ))
93
+ subnetId = v .(string )
106
94
}
107
95
108
96
if v , ok := d .GetOkExists ("is_assign_vip" ); ok {
@@ -111,6 +99,7 @@ func resourceTencentCloudPostgresqlInstanceNetworkAccessCreate(d *schema.Resourc
111
99
112
100
if v , ok := d .GetOk ("vip" ); ok {
113
101
request .Vip = helper .String (v .(string ))
102
+ vip = v .(string )
114
103
}
115
104
116
105
err := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
@@ -120,45 +109,46 @@ func resourceTencentCloudPostgresqlInstanceNetworkAccessCreate(d *schema.Resourc
120
109
} else {
121
110
log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " , logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
122
111
}
112
+
113
+ if result == nil || result .Response == nil {
114
+ return resource .NonRetryableError (fmt .Errorf ("Create postgresql instance network access failed, Response is nil." ))
115
+ }
116
+
123
117
response = result
124
118
return nil
125
119
})
120
+
126
121
if err != nil {
127
122
log .Printf ("[CRITAL]%s create postgresql instance network access failed, reason:%+v" , logId , err )
128
123
return err
129
124
}
130
125
131
- _ = response
132
-
133
- if _ , err := (& resource.StateChangeConf {
134
- Delay : 10 * time .Second ,
135
- MinTimeout : 3 * time .Second ,
136
- Pending : []string {},
137
- Refresh : resourcePostgresqlInstanceNetworkAccessCreateStateRefreshFunc_0_0 (ctx , dbInsntaceId , vpcId , subnetId , vip ),
138
- Target : []string {"Running" },
139
- Timeout : 180 * time .Second ,
140
- }).WaitForStateContext (ctx ); err != nil {
141
- return err
126
+ if response .Response .FlowId == nil {
127
+ return fmt .Errorf ("FlowId is nil." )
142
128
}
143
129
144
- // get vip
145
- service := PostgresqlService {client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
146
- respData , err := service .DescribePostgresqlInstanceNetworkAccessById (ctx , dbInsntaceId )
147
- if err != nil {
148
- return err
149
- }
130
+ // wait & get vip
131
+ flowRequest := postgresqlv20170312 .NewDescribeTasksRequest ()
132
+ flowRequest .TaskId = response .Response .FlowId
133
+ err := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
134
+ result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UsePostgresqlV20170312Client ().DescribeTasksWithContext (ctx , request )
135
+ if e != nil {
136
+ return tccommon .RetryError (e )
137
+ } else {
138
+ log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " , logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
139
+ }
150
140
151
- if respData == nil {
152
- log .Printf ("[WARN]%s resource `postgresql_instance_network_access` [%s] not found, please check if it has been deleted.\n " , logId , d .Id ())
153
- return nil
154
- }
141
+ if result == nil || result .Response == nil {
142
+ return resource .NonRetryableError (fmt .Errorf ("Create postgresql instance network access failed, Response is nil." ))
143
+ }
155
144
156
- if respData . DBInstanceNetInfo != nil && len ( respData . DBInstanceNetInfo ) > 0 {
157
- for _ , item := range respData . DBInstanceNetInfo {
158
- if * item . VpcId == vpcId && * item . SubnetId == subnetId {
145
+ response = result
146
+ return nil
147
+ })
159
148
160
- }
161
- }
149
+ if err != nil {
150
+ log .Printf ("[CRITAL]%s create postgresql instance network access failed, reason:%+v" , logId , err )
151
+ return err
162
152
}
163
153
164
154
d .SetId (strings .Join ([]string {dbInsntaceId , vpcId , subnetId , vip }, tccommon .FILED_SP ))
0 commit comments