Skip to content

Commit 009f202

Browse files
committed
feat(vpn-gateway): Fix update logic of asn
1 parent 09e7b2f commit 009f202

File tree

8 files changed

+52
-12
lines changed

8 files changed

+52
-12
lines changed

common/github.com/IBM/vpc-go-sdk/vpcv1/vpc_v1.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ import (
3535
"github.com/go-openapi/strfmt"
3636
)
3737

38+
const (
39+
YYYYMMDD = "2006-01-02"
40+
)
41+
3842
// VpcV1 : The IBM Cloud Virtual Private Cloud (VPC) API can be used to programmatically provision and manage virtual
3943
// server instances, along with subnets, volumes, load balancers, and more.
4044
//
@@ -102,6 +106,10 @@ func NewVpcV1UsingExternalConfig(options *VpcV1Options) (vpc *VpcV1, err error)
102106
err = vpc.Service.SetServiceURL(options.URL)
103107
err = core.RepurposeSDKProblem(err, "url-set-error")
104108
}
109+
now := time.Now().UTC()
110+
if options.Version == nil {
111+
options.Version = core.StringPtr(now.Format(YYYYMMDD))
112+
}
105113
return
106114
}
107115

@@ -132,6 +140,11 @@ func NewVpcV1(options *VpcV1Options) (service *VpcV1, err error) {
132140
}
133141
}
134142

143+
now := time.Now().UTC()
144+
if options.Version == nil {
145+
options.Version = core.StringPtr(now.Format(YYYYMMDD))
146+
}
147+
135148
service = &VpcV1{
136149
Service: baseService,
137150
Generation: options.Generation,
@@ -237,7 +250,7 @@ func (vpc *VpcV1) CreateVPCWithContext(ctx context.Context, createVPCOptions *Cr
237250
builder.AddHeader("Accept", "application/json")
238251
builder.AddHeader("Content-Type", "application/json")
239252

240-
builder.AddQuery("version", fmt.Sprint(*vpc.Version))
253+
builder.AddQuery("version", fmt.Sprint("2025-08-05"))
241254
builder.AddQuery("generation", fmt.Sprint(*vpc.Generation))
242255

243256
body := make(map[string]interface{})

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ replace github.com/dgrijalva/jwt-go v3.2.0+incompatible => github.com/golang-jwt
238238
// add sdk changes.
239239
replace github.com/portworx/sched-ops v0.0.0-20200831185134-3e8010dc7056 => github.com/portworx/sched-ops v0.20.4-openstorage-rc3 // required by rook v1.7
240240

241-
replace github.com/IBM/vpc-go-sdk v0.64.0 => ./common/github.com/IBM/vpc-go-sdk
241+
replace github.com/IBM/vpc-go-sdk => ./common/github.com/IBM/vpc-go-sdk
242242
replace github.com/hashicorp/consul/api v1.1.0 => github.com/hashicorp/consul/api v1.30.0
243243

244244
replace github.com/hashicorp/vault => github.com/hashicorp/vault v1.18.2

ibm/service/vpc/data_source_ibm_is_vpn_gateway.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,13 @@ func DataSourceIBMISVPNGateway() *schema.Resource {
269269
},
270270
isVPNGatewayLocalAsn: {
271271
Type: schema.TypeInt,
272-
Optional: true,
272+
Computed: true,
273273
Description: "The local autonomous system number (ASN) for this VPN gateway and its connections.",
274274
},
275275

276276
isVPNGatewayAdvertisedCidrs: {
277277
Type: schema.TypeList,
278-
Optional: true,
278+
Computed: true,
279279
Description: "The additional CIDRs advertised through any enabled routing protocol (for example, BGP). The routing protocol will advertise routes with these CIDRs and VPC prefixes as route destinations.",
280280
Elem: &schema.Schema{
281281
Type: schema.TypeString,

ibm/service/vpc/data_source_ibm_is_vpn_gateway_connection.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,12 @@ func DataSourceIBMISVPNGatewayConnection() *schema.Resource {
281281
Type: schema.TypeString,
282282
},
283283
},
284+
"asn": &schema.Schema{
285+
Type: schema.TypeInt,
286+
Optional: true,
287+
Computed: true,
288+
Description: "The peer autonomous system number (ASN) for this VPN gateway connection.",
289+
},
284290
},
285291
},
286292
},

ibm/service/vpc/data_source_ibm_is_vpn_gateway_connections.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ func DataSourceIBMISVPNGatewayConnections() *schema.Resource {
200200
Computed: true,
201201
Description: "The FQDN of the peer VPN gateway for this connection.",
202202
},
203+
"asn": &schema.Schema{
204+
Type: schema.TypeInt,
205+
Optional: true,
206+
Computed: true,
207+
Description: "The peer autonomous system number (ASN) for this VPN gateway connection.",
208+
},
203209
},
204210
},
205211
},

ibm/service/vpc/data_source_ibm_is_vpn_gateways.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,12 @@ func DataSourceIBMISVPNGateways() *schema.Resource {
176176
},
177177
isVPNGatewayLocalAsn: {
178178
Type: schema.TypeInt,
179-
Optional: true,
179+
Computed: true,
180180
Description: "The local autonomous system number (ASN) for this VPN gateway and its connections.",
181181
},
182182
isVPNGatewayAdvertisedCidrs: {
183183
Type: schema.TypeList,
184-
Optional: true,
184+
Computed: true,
185185
Description: "The additional CIDRs advertised through any enabled routing protocol (for example, BGP). The routing protocol will advertise routes with these CIDRs and VPC prefixes as route destinations.",
186186
Elem: &schema.Schema{
187187
Type: schema.TypeString,

ibm/service/vpc/resource_ibm_is_vpn_gateway.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
1414
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate"
15+
"github.com/IBM/go-sdk-core/v5/core"
1516
"github.com/IBM/vpc-go-sdk/vpcv1"
1617
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
1718
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
@@ -687,9 +688,11 @@ func vpngwUpdate(d *schema.ResourceData, meta interface{}, id string, hasChanged
687688
}
688689

689690
if d.HasChange(isVPNGatewayLocalAsn) {
690-
localAsn := d.Get(isVPNGatewayLocalAsn).(int64)
691-
vpnGatewayPatchModel.LocalAsn = &localAsn
692-
hasChanged = true
691+
if localAsnIntf, ok := d.GetOk(isVPNGatewayLocalAsn); ok {
692+
localAsn := core.Int64Ptr(int64(localAsnIntf.(int)))
693+
vpnGatewayPatchModel.LocalAsn = localAsn
694+
hasChanged = true
695+
}
693696
}
694697

695698
if hasChanged {

ibm/service/vpc/resource_ibm_is_vpn_gateway_connections.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,17 @@ func vpngwconUpdate(d *schema.ResourceData, meta interface{}, gID, gConnID strin
920920

921921
if d.HasChange("tunnel") {
922922
log.Println("[INFO] inside tunnel block")
923+
options := &vpcv1.GetVPNGatewayConnectionOptions{
924+
VPNGatewayID: &gID,
925+
ID: &gConnID,
926+
}
927+
_, response, err := sess.GetVPNGatewayConnection(options)
928+
if err != nil {
929+
return fmt.Errorf("[ERROR] Error getting vpn conncetion: %s\n%s", err, response)
930+
}
931+
eTag := response.Headers.Get("ETag")
932+
updateVpnGatewayConnectionOptions.IfMatch = &eTag
933+
923934
tunnelModels := []vpcv1.VPNGatewayConnectionTunnel{}
924935
tunnelOk, _ := d.GetOk("tunnel")
925936
for _, tunnelItem := range tunnelOk.([]interface{}) {
@@ -1329,8 +1340,9 @@ func resourceIBMIsVPNGatewayConnectionMapToVPNGatewayConnectionPeerPatch(modelMa
13291340
if modelMap["fqdn"] != nil && modelMap["fqdn"].(string) != "" {
13301341
model.Fqdn = core.StringPtr(modelMap["fqdn"].(string))
13311342
}
1332-
if modelMap["asn"] != nil && modelMap["asn"].(string) != "" {
1333-
model.Asn = core.Int64Ptr(modelMap["asn"].(int64))
1343+
if modelMap["asn"] != nil {
1344+
localAsn := core.Int64Ptr(int64(modelMap["asn"].(int)))
1345+
model.Asn = localAsn
13341346
}
13351347
return model, nil
13361348
}
@@ -1768,7 +1780,7 @@ func setvpnGatewayConnectionIntfResource(d *schema.ResourceData, vpn_gateway_id
17681780
}
17691781
if !core.IsNil(vpnGatewayConnection.DistributeTraffic) {
17701782
if err = d.Set("distribute_traffic", vpnGatewayConnection.DistributeTraffic); err != nil {
1771-
return fmt.Errorf("Error setting distribute_traffic: %s", err)
1783+
return fmt.Errorf("[ERROR] setting distribute_traffic: %s", err)
17721784
}
17731785
}
17741786
if vpnGatewayConnection.DeadPeerDetection != nil {

0 commit comments

Comments
 (0)