Skip to content

Commit 7b84489

Browse files
deepaksibmuibm
andauthored
Vni phase 2 shares enhancement (#283)
* vni crud changes * sdk update * beta sdk updates * Removed share target resources and datasources following deprecation * ips validation * share inline ips schema * read update * bm sdk fix * build error fix * vni id enhancement * removed beta * minor data source additions * replica doc update * test update * dummy * updated mount target and shares * updates to schema * added development maturity * added development maturity * sdk update * Revert "sdk update" This reverts commit b50f59e. * ga * vni auto delete patch * fixed review comments * test updates * doc updates * added notes --------- Co-authored-by: Ujjwal Kumar <[email protected]>
1 parent 0eaba69 commit 7b84489

10 files changed

+596
-55
lines changed

ibm/service/vpc/data_source_ibm_is_share_mount_target.go

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,54 @@ func DataSourceIBMIsShareTarget() *schema.Resource {
8080
Computed: true,
8181
Description: "The type of resource referenced.",
8282
},
83+
"primary_ip": {
84+
Type: schema.TypeList,
85+
Computed: true,
86+
Description: "The primary IP address of the virtual network interface for the share mount target.",
87+
Elem: &schema.Resource{
88+
Schema: map[string]*schema.Schema{
89+
"address": {
90+
Type: schema.TypeString,
91+
Computed: true,
92+
Description: "The IP address..",
93+
},
94+
"deleted": {
95+
Type: schema.TypeList,
96+
Computed: true,
97+
Description: "If present, this property indicates the referenced resource has been deleted and providessome supplementary information.",
98+
Elem: &schema.Resource{
99+
Schema: map[string]*schema.Schema{
100+
"more_info": {
101+
Type: schema.TypeString,
102+
Computed: true,
103+
Description: "Link to documentation about deleted resources.",
104+
},
105+
},
106+
},
107+
},
108+
"href": {
109+
Type: schema.TypeString,
110+
Computed: true,
111+
Description: "The URL for this reserved IP.",
112+
},
113+
"id": {
114+
Type: schema.TypeString,
115+
Computed: true,
116+
Description: "The unique identifier for this reserved IP.",
117+
},
118+
"name": {
119+
Type: schema.TypeString,
120+
Computed: true,
121+
Description: "The user-defined name for this reserved IP.",
122+
},
123+
"resource_type": {
124+
Type: schema.TypeString,
125+
Computed: true,
126+
Description: "The resource type.",
127+
},
128+
},
129+
},
130+
},
83131
"subnet": {
84132
Type: schema.TypeList,
85133
Computed: true,
@@ -311,6 +359,13 @@ func dataSourceIBMIsShareTargetRead(context context.Context, d *schema.ResourceD
311359
}
312360
}
313361

362+
if shareTarget.PrimaryIP != nil {
363+
err = d.Set("primary_ip", dataSourceShareMountTargetFlattenPrimaryIP(*shareTarget.PrimaryIP))
364+
if err != nil {
365+
return diag.FromErr(fmt.Errorf("Error setting vpc %s", err))
366+
}
367+
}
368+
314369
if shareTarget.VPC != nil {
315370
err = d.Set("vpc", dataSourceShareMountTargetFlattenVpc(*shareTarget.VPC))
316371
if err != nil {
@@ -382,6 +437,53 @@ func dataSourceShareMountTargetVpcDeletedToMap(deletedItem vpcv1.VPCReferenceDel
382437
return deletedMap
383438
}
384439

440+
func dataSourceShareMountTargetFlattenPrimaryIP(result vpcv1.ReservedIPReference) (finalList []map[string]interface{}) {
441+
finalList = []map[string]interface{}{}
442+
finalMap := dataSourceShareTargetPrimaryIPToMap(result)
443+
finalList = append(finalList, finalMap)
444+
445+
return finalList
446+
}
447+
448+
func dataSourceShareTargetPrimaryIPToMap(primaryIPItem vpcv1.ReservedIPReference) (primaryIPMap map[string]interface{}) {
449+
primaryIPMap = map[string]interface{}{}
450+
451+
if primaryIPItem.Address != nil {
452+
primaryIPMap["address"] = primaryIPItem.Address
453+
}
454+
if primaryIPItem.Deleted != nil {
455+
deletedList := []map[string]interface{}{}
456+
deletedMap := dataSourceShareTargetPrimaryIPDeletedToMap(*primaryIPItem.Deleted)
457+
deletedList = append(deletedList, deletedMap)
458+
primaryIPMap["deleted"] = deletedList
459+
}
460+
if primaryIPItem.Href != nil {
461+
primaryIPMap["href"] = primaryIPItem.Href
462+
}
463+
if primaryIPItem.ID != nil {
464+
primaryIPMap["id"] = primaryIPItem.ID
465+
}
466+
if primaryIPItem.Name != nil {
467+
primaryIPMap["name"] = primaryIPItem.Name
468+
}
469+
470+
if primaryIPItem.ResourceType != nil {
471+
primaryIPMap["resource_type"] = primaryIPItem.ResourceType
472+
}
473+
474+
return primaryIPMap
475+
}
476+
477+
func dataSourceShareTargetPrimaryIPDeletedToMap(deletedItem vpcv1.ReservedIPReferenceDeleted) (deletedMap map[string]interface{}) {
478+
deletedMap = map[string]interface{}{}
479+
480+
if deletedItem.MoreInfo != nil {
481+
deletedMap["more_info"] = deletedItem.MoreInfo
482+
}
483+
484+
return deletedMap
485+
}
486+
385487
func dataSourceShareMountTargetFlattenSubnet(result vpcv1.SubnetReference) (finalList []map[string]interface{}) {
386488
finalList = []map[string]interface{}{}
387489
finalMap := dataSourceShareTargetSubnetToMap(result)

ibm/service/vpc/data_source_ibm_is_share_mount_targets.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,54 @@ func DataSourceIBMIsShareTargets() *schema.Resource {
7878
Computed: true,
7979
Description: "The type of resource referenced.",
8080
},
81+
"primary_ip": {
82+
Type: schema.TypeList,
83+
Computed: true,
84+
Description: "The primary IP address of the virtual network interface for the share mount target.",
85+
Elem: &schema.Resource{
86+
Schema: map[string]*schema.Schema{
87+
"address": {
88+
Type: schema.TypeString,
89+
Computed: true,
90+
Description: "The IP address..",
91+
},
92+
"deleted": {
93+
Type: schema.TypeList,
94+
Computed: true,
95+
Description: "If present, this property indicates the referenced resource has been deleted and providessome supplementary information.",
96+
Elem: &schema.Resource{
97+
Schema: map[string]*schema.Schema{
98+
"more_info": {
99+
Type: schema.TypeString,
100+
Computed: true,
101+
Description: "Link to documentation about deleted resources.",
102+
},
103+
},
104+
},
105+
},
106+
"href": {
107+
Type: schema.TypeString,
108+
Computed: true,
109+
Description: "The URL for this reserved IP.",
110+
},
111+
"id": {
112+
Type: schema.TypeString,
113+
Computed: true,
114+
Description: "The unique identifier for this reserved IP.",
115+
},
116+
"name": {
117+
Type: schema.TypeString,
118+
Computed: true,
119+
Description: "The user-defined name for this reserved IP.",
120+
},
121+
"resource_type": {
122+
Type: schema.TypeString,
123+
Computed: true,
124+
Description: "The resource type.",
125+
},
126+
},
127+
},
128+
},
81129
"subnet": {
82130
Type: schema.TypeList,
83131
Computed: true,
@@ -319,6 +367,10 @@ func dataSourceShareMountTargetCollectionTargetsToMap(targetsItem vpcv1.ShareMou
319367
targetsMap["transit_encryption"] = *targetsItem.TransitEncryption
320368
}
321369

370+
if targetsItem.PrimaryIP != nil {
371+
targetsMap["primary_ip"] = dataSourceShareMountTargetFlattenPrimaryIP(*targetsItem.PrimaryIP)
372+
}
373+
322374
if targetsItem.VPC != nil {
323375
targetsMap["vpc"] = dataSourceShareMountTargetFlattenVpc(*targetsItem.VPC)
324376
}

ibm/service/vpc/resource_ibm_is_share.go

Lines changed: 66 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ func ResourceIbmIsShare() *schema.Resource {
156156
},
157157
"id": {
158158
Type: schema.TypeString,
159+
Optional: true,
159160
Computed: true,
160161
Description: "ID of this VNI",
161162
},
@@ -165,6 +166,22 @@ func ResourceIbmIsShare() *schema.Resource {
165166
Computed: true,
166167
Description: "Name of this VNI",
167168
},
169+
"allow_ip_spoofing": &schema.Schema{
170+
Type: schema.TypeBool,
171+
Computed: true,
172+
Description: "Indicates whether source IP spoofing is allowed on this interface. If `false`, source IP spoofing is prevented on this interface. If `true`, source IP spoofing is allowed on this interface.",
173+
},
174+
"auto_delete": &schema.Schema{
175+
Type: schema.TypeBool,
176+
Optional: true,
177+
Computed: true,
178+
Description: "Indicates whether this virtual network interface will be automatically deleted when`target` is deleted.",
179+
},
180+
"enable_infrastructure_nat": &schema.Schema{
181+
Type: schema.TypeBool,
182+
Computed: true,
183+
Description: "If `true`:- The VPC infrastructure performs any needed NAT operations.- `floating_ips` must not have more than one floating IP.If `false`:- Packets are passed unchanged to/from the network interface, allowing the workload to perform any needed NAT operations.- `allow_ip_spoofing` must be `false`.- If the virtual network interface is attached: - The target `resource_type` must be `bare_metal_server_network_attachment`. - The target `interface_type` must not be `hipersocket`.",
184+
},
168185
"primary_ip": {
169186
Type: schema.TypeList,
170187
Optional: true,
@@ -231,6 +248,7 @@ func ResourceIbmIsShare() *schema.Resource {
231248
"subnet": {
232249
Type: schema.TypeString,
233250
Optional: true,
251+
Computed: true,
234252
Description: "The associated subnet. Required if primary_ip is not specified.",
235253
},
236254
},
@@ -389,6 +407,7 @@ func ResourceIbmIsShare() *schema.Resource {
389407
},
390408
"id": {
391409
Type: schema.TypeString,
410+
Optional: true,
392411
Computed: true,
393412
Description: "ID of this VNI",
394413
},
@@ -398,6 +417,22 @@ func ResourceIbmIsShare() *schema.Resource {
398417
Computed: true,
399418
Description: "Name of this VNI",
400419
},
420+
"allow_ip_spoofing": &schema.Schema{
421+
Type: schema.TypeBool,
422+
Computed: true,
423+
Description: "Indicates whether source IP spoofing is allowed on this interface. If `false`, source IP spoofing is prevented on this interface. If `true`, source IP spoofing is allowed on this interface.",
424+
},
425+
"auto_delete": &schema.Schema{
426+
Type: schema.TypeBool,
427+
Optional: true,
428+
Computed: true,
429+
Description: "Indicates whether this virtual network interface will be automatically deleted when`target` is deleted.",
430+
},
431+
"enable_infrastructure_nat": &schema.Schema{
432+
Type: schema.TypeBool,
433+
Computed: true,
434+
Description: "If `true`:- The VPC infrastructure performs any needed NAT operations.- `floating_ips` must not have more than one floating IP.If `false`:- Packets are passed unchanged to/from the network interface, allowing the workload to perform any needed NAT operations.- `allow_ip_spoofing` must be `false`.- If the virtual network interface is attached: - The target `resource_type` must be `bare_metal_server_network_attachment`. - The target `interface_type` must not be `hipersocket`.",
435+
},
401436
"primary_ip": {
402437
Type: schema.TypeList,
403438
Optional: true,
@@ -464,6 +499,7 @@ func ResourceIbmIsShare() *schema.Resource {
464499
"subnet": {
465500
Type: schema.TypeString,
466501
Optional: true,
502+
Computed: true,
467503
Description: "The associated subnet. Required if primary_ip is not specified.",
468504
},
469505
},
@@ -786,9 +822,10 @@ func resourceIbmIsShareCreate(context context.Context, d *schema.ResourceData, m
786822
if ok {
787823
var targets []vpcv1.ShareMountTargetPrototypeIntf
788824
targetsIntf := replicaTargets.([]interface{})
789-
for _, targetIntf := range targetsIntf {
825+
for tergetIdx, targetIntf := range targetsIntf {
790826
target := targetIntf.(map[string]interface{})
791-
targetsItem, err := resourceIbmIsShareMapToShareMountTargetPrototype(d, target)
827+
autoDeleteSchema := fmt.Sprintf("replica_share.0.mount_targets.%d.virtual_network_interface.0.auto_delete", tergetIdx)
828+
targetsItem, err := resourceIbmIsShareMapToShareMountTargetPrototype(d, target, autoDeleteSchema)
792829
if err != nil {
793830
return diag.FromErr(err)
794831
}
@@ -846,9 +883,10 @@ func resourceIbmIsShareCreate(context context.Context, d *schema.ResourceData, m
846883

847884
if shareTargetPrototypeIntf, ok := d.GetOk("mount_targets"); ok {
848885
var targets []vpcv1.ShareMountTargetPrototypeIntf
849-
for _, e := range shareTargetPrototypeIntf.([]interface{}) {
886+
for targetIdx, e := range shareTargetPrototypeIntf.([]interface{}) {
850887
value := e.(map[string]interface{})
851-
targetsItem, err := resourceIbmIsShareMapToShareMountTargetPrototype(d, value)
888+
autoDeleteSchema := fmt.Sprintf("mount_targets.%d.virtual_network_interface.0.auto_delete", targetIdx)
889+
targetsItem, err := resourceIbmIsShareMapToShareMountTargetPrototype(d, value, autoDeleteSchema)
852890
if err != nil {
853891
return diag.FromErr(err)
854892
}
@@ -921,7 +959,7 @@ func resourceIbmIsShareCreate(context context.Context, d *schema.ResourceData, m
921959
return resourceIbmIsShareRead(context, d, meta)
922960
}
923961

924-
func resourceIbmIsShareMapToShareMountTargetPrototype(d *schema.ResourceData, shareTargetPrototypeMap map[string]interface{}) (vpcv1.ShareMountTargetPrototype, error) {
962+
func resourceIbmIsShareMapToShareMountTargetPrototype(d *schema.ResourceData, shareTargetPrototypeMap map[string]interface{}, autoDeleteSchema string) (vpcv1.ShareMountTargetPrototype, error) {
925963
shareTargetPrototype := vpcv1.ShareMountTargetPrototype{}
926964

927965
if nameIntf, ok := shareTargetPrototypeMap["name"]; ok && nameIntf != "" {
@@ -936,11 +974,20 @@ func resourceIbmIsShareMapToShareMountTargetPrototype(d *schema.ResourceData, sh
936974
} else if vniIntf, ok := shareTargetPrototypeMap["virtual_network_interface"]; ok {
937975
vniPrototype := vpcv1.ShareMountTargetVirtualNetworkInterfacePrototype{}
938976
vniMap := vniIntf.([]interface{})[0].(map[string]interface{})
939-
vniPrototype, err := ShareMountTargetMapToShareMountTargetPrototype(d, vniMap)
940-
if err != nil {
941-
return shareTargetPrototype, err
977+
978+
VNIIdIntf, ok := vniMap["id"]
979+
VNIId := VNIIdIntf.(string)
980+
if ok && VNIId != "" {
981+
vniPrototype.ID = &VNIId
982+
shareTargetPrototype.VirtualNetworkInterface = &vniPrototype
983+
} else {
984+
vniPrototype, err := ShareMountTargetMapToShareMountTargetPrototype(d, vniMap, autoDeleteSchema)
985+
if err != nil {
986+
return shareTargetPrototype, err
987+
}
988+
shareTargetPrototype.VirtualNetworkInterface = &vniPrototype
942989
}
943-
shareTargetPrototype.VirtualNetworkInterface = &vniPrototype
990+
944991
}
945992
if transitEncryptionIntf, ok := shareTargetPrototypeMap["transit_encryption"]; ok && transitEncryptionIntf != "" {
946993
transitEncryption := transitEncryptionIntf.(string)
@@ -1614,6 +1661,7 @@ func shareUpdate(vpcClient *vpcv1.VpcV1, context context.Context, d *schema.Reso
16141661
for targetIdx := range target_prototype {
16151662
targetName := fmt.Sprintf("%s.%d.name", shareMountTargetSchema, targetIdx)
16161663
vniName := fmt.Sprintf("%s.%d.virtual_network_interface.0.name", shareMountTargetSchema, targetIdx)
1664+
vniAutoDelete := fmt.Sprintf("%s.%d.virtual_network_interface.0.auto_delete", shareMountTargetSchema, targetIdx)
16171665
vniId := fmt.Sprintf("%s.%d.virtual_network_interface.0.id", shareMountTargetSchema, targetIdx)
16181666
targetId := fmt.Sprintf("%s.%d.id", shareMountTargetSchema, targetIdx)
16191667
securityGroups := fmt.Sprintf("%s.%d.virtual_network_interface.0.security_groups", shareMountTargetSchema, targetIdx)
@@ -1650,10 +1698,15 @@ func shareUpdate(vpcClient *vpcv1.VpcV1, context context.Context, d *schema.Reso
16501698
}
16511699
}
16521700

1653-
if d.HasChange(vniName) {
1654-
vniNameStr := d.Get(vniName).(string)
1655-
vniPatchModel := &vpcv1.VirtualNetworkInterfacePatch{
1656-
Name: &vniNameStr,
1701+
if d.HasChange(vniName) || d.HasChange(vniAutoDelete) {
1702+
vniPatchModel := &vpcv1.VirtualNetworkInterfacePatch{}
1703+
if d.HasChange(vniName) {
1704+
vniNameStr := d.Get(vniName).(string)
1705+
vniPatchModel.Name = &vniNameStr
1706+
}
1707+
if d.HasChange(vniAutoDelete) {
1708+
autoDelete := d.Get(vniAutoDelete).(bool)
1709+
vniPatchModel.AutoDelete = &autoDelete
16571710
}
16581711
vniPatch, err := vniPatchModel.AsPatch()
16591712
if err != nil {

0 commit comments

Comments
 (0)