@@ -54,6 +54,7 @@ func (vpcs *VPCSession) CreateVolumeAccessPoint(volumeAccessPointRequest provide
5454 var varp * provider.VolumeAccessPointResponse
5555
5656 var subnet * models.Subnet
57+ var subnetID string
5758
5859 volumeAccessPoint := models .NewShareTarget (volumeAccessPointRequest )
5960
@@ -78,20 +79,32 @@ func (vpcs *VPCSession) CreateVolumeAccessPoint(volumeAccessPointRequest provide
7879 ResourceGroup : volumeAccessPointRequest .ResourceGroup ,
7980 }
8081
82+ // If primaryIP.ID is provided subnet is not mandatory for rest of the cases it is mandatory
8183 if volumeAccessPointRequest .PrimaryIP == nil || len (volumeAccessPointRequest .PrimaryIP .ID ) == 0 {
82- vpcs .Logger .Info ("Getting subnet from VPC provider..." )
83- subnet , err = vpcs .getSubnet (volumeAccessPointRequest )
84- // Keep retry, until we get the proper volumeAccessPointResult object
85- if err != nil && subnet == nil {
86- return err , skipRetryForObviousErrors (err )
84+
85+ if len (volumeAccessPointRequest .SubnetID ) == 0 {
86+ vpcs .Logger .Info ("Getting subnet from VPC provider..." )
87+ subnet , err = vpcs .getSubnet (volumeAccessPointRequest )
88+ // Keep retry, until we get the proper volumeAccessPointResult object
89+ if err != nil && subnet == nil {
90+ return err , skipRetryForObviousErrors (err )
91+ }
92+ subnetID = subnet .ID
93+
94+ } else {
95+ vpcs .Logger .Info ("Using subnet provided by user..." , zap .Reflect ("subnetID" , volumeAccessPointRequest .SubnetID ))
96+ subnetID = volumeAccessPointRequest .SubnetID
8797 }
8898
8999 volumeAccessPoint .VirtualNetworkInterface .Subnet = & models.SubnetRef {
90- ID : subnet . ID ,
100+ ID : subnetID ,
91101 }
92102 }
93- vpcs .Logger .Info ("Primary IP ID provided using it for virtual network interface..." )
94- volumeAccessPoint .VirtualNetworkInterface .PrimaryIP = (* models .PrimaryIP )(volumeAccessPointRequest .PrimaryIP )
103+
104+ if volumeAccessPointRequest .PrimaryIP != nil {
105+ vpcs .Logger .Info ("Primary IP ID provided using it for virtual network interface..." )
106+ volumeAccessPoint .VirtualNetworkInterface .PrimaryIP = (* models .PrimaryIP )(volumeAccessPointRequest .PrimaryIP )
107+ }
95108 }
96109
97110 //Try creating volume accessPoint if it's not already created or there is error in getting current volume accessPoint
@@ -162,7 +175,7 @@ func (vpcs *VPCSession) getSubnetByVPCIDAndZone(volumeAccessPointRequest provide
162175
163176 if err != nil {
164177 // API call is failed
165- userErr := userError .GetUserError (string ( userError . AccessPointWithVPCIDFindFailed ) , err , volumeAccessPointRequest . Zone , volumeAccessPointRequest . VPCID )
178+ userErr := userError .GetUserError ("ListSubnetsFailed" , err )
166179 return nil , userErr
167180 }
168181
@@ -185,23 +198,23 @@ func (vpcs *VPCSession) getSubnetByVPCIDAndZone(volumeAccessPointRequest provide
185198 startUrl , err := url .Parse (subnets .Next .Href )
186199 if err != nil {
187200 // API call is failed
188- userErr := userError .GetUserError (string ( userError . AccessPointWithVPCIDFindFailed ) , err , volumeAccessPointRequest . Zone , volumeAccessPointRequest . VPCID )
201+ userErr := userError .GetUserError ("NextSubnetPageParsingError" , err , subnets . Next . Href )
189202 return nil , userErr
190203 }
191204
192205 vpcs .Logger .Info ("startUrl" , zap .Reflect ("startUrl" , startUrl ))
193206 start = startUrl .Query ().Get ("start" ) //parse query param into map
194207 if start == "" {
195208 // API call is failed
196- userErr := userError .GetUserError (string ( userError . AccessPointWithVPCIDFindFailed ) , err , volumeAccessPointRequest . Zone , volumeAccessPointRequest . VPCID )
209+ userErr := userError .GetUserError ("StartSubnetIDEmpty" , err , startUrl )
197210 return nil , userErr
198211 }
199212
200213 }
201214 }
202215
203216 // No volume Subnet found in the list. So return error
204- userErr := userError .GetUserError (string (userError . AccessPointWithVPCIDFindFailed ), errors .New ("no subnet found" ), volumeAccessPointRequest .Zone , volumeAccessPointRequest .VPCID )
217+ userErr := userError .GetUserError (string ("SubnetFindFailedWithZoneAndVPC" ), errors .New ("no subnet found" ), volumeAccessPointRequest .Zone , volumeAccessPointRequest .VPCID )
205218 vpcs .Logger .Error ("Subnet not found" , zap .Error (err ))
206219 return nil , userErr
207220}
0 commit comments