Skip to content

Commit a237f69

Browse files
authored
fix(auto_delete): fixed default true on vni (IBM-Cloud#6210)
* fix(auto_delete): fixed default true on vni * validation of vni
1 parent 0f90e93 commit a237f69

7 files changed

+233
-206
lines changed

ibm/service/vpc/resource_ibm_is_bare_metal_server.go

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -592,10 +592,11 @@ func ResourceIBMIsBareMetalServer() *schema.Resource {
592592
Elem: &schema.Resource{
593593
Schema: map[string]*schema.Schema{
594594
"address": &schema.Schema{
595-
Type: schema.TypeString,
596-
Optional: true,
597-
Computed: true,
598-
Description: "The IP address.If the address has not yet been selected, the value will be `0.0.0.0`.This property may add support for IPv6 addresses in the future. When processing a value in this property, verify that the address is in an expected format. If it is not, log an error. Optionally halt processing and surface the error, or bypass the resource on which the unexpected IP address format was encountered.",
595+
Type: schema.TypeString,
596+
Optional: true,
597+
ConflictsWith: []string{"primary_network_attachment.0.virtual_network_interface.0.primary_ip.0.reserved_ip"},
598+
Computed: true,
599+
Description: "The IP address.If the address has not yet been selected, the value will be `0.0.0.0`.This property may add support for IPv6 addresses in the future. When processing a value in this property, verify that the address is in an expected format. If it is not, log an error. Optionally halt processing and surface the error, or bypass the resource on which the unexpected IP address format was encountered.",
599600
},
600601
"deleted": &schema.Schema{
601602
Type: schema.TypeList,
@@ -623,10 +624,11 @@ func ResourceIBMIsBareMetalServer() *schema.Resource {
623624
Description: "The unique identifier for this reserved IP.",
624625
},
625626
"name": &schema.Schema{
626-
Type: schema.TypeString,
627-
Optional: true,
628-
Computed: true,
629-
Description: "The name for this reserved IP. The name is unique across all reserved IPs in a subnet.",
627+
Type: schema.TypeString,
628+
Optional: true,
629+
ConflictsWith: []string{"primary_network_attachment.0.virtual_network_interface.0.primary_ip.0.reserved_ip"},
630+
Computed: true,
631+
Description: "The name for this reserved IP. The name is unique across all reserved IPs in a subnet.",
630632
},
631633
"resource_type": &schema.Schema{
632634
Type: schema.TypeString,
@@ -4546,7 +4548,7 @@ func resourceIBMIsBareMetalServerBareMetalServerNetworkAttachmentReferenceToMap(
45464548
ips := []map[string]interface{}{}
45474549
for _, ipsItem := range vniDetails.Ips {
45484550
if *ipsItem.ID != primaryipId {
4549-
ipsItemMap, err := resourceIBMIsVirtualNetworkInterfaceReservedIPReferenceToMap(&ipsItem, true)
4551+
ipsItemMap, err := resourceIBMIsVirtualNetworkInterfaceReservedIPReferenceToMap(&ipsItem, true, false)
45504552
if err != nil {
45514553
return nil, err
45524554
}
@@ -4636,39 +4638,39 @@ func resourceIBMIsBareMetalServerMapToBareMetalServerPrimaryNetworkAttachmentPro
46364638
}
46374639
func resourceIBMIsBareMetalServerMapToVirtualNetworkInterfaceIPsReservedIPPrototype(modelMap map[string]interface{}) (vpcv1.VirtualNetworkInterfaceIPPrototypeIntf, error) {
46384640
model := &vpcv1.VirtualNetworkInterfaceIPPrototype{}
4639-
if modelMap["id"] != nil && modelMap["id"].(string) != "" {
4640-
model.ID = core.StringPtr(modelMap["id"].(string))
4641-
}
4642-
if modelMap["href"] != nil && modelMap["href"].(string) != "" {
4641+
if modelMap["reserved_ip"] != nil && modelMap["reserved_ip"].(string) != "" {
4642+
model.ID = core.StringPtr(modelMap["reserved_ip"].(string))
4643+
} else if modelMap["href"] != nil && modelMap["href"].(string) != "" {
46434644
model.Href = core.StringPtr(modelMap["href"].(string))
4644-
}
4645-
if modelMap["address"] != nil && modelMap["address"].(string) != "" {
4646-
model.Address = core.StringPtr(modelMap["address"].(string))
4647-
}
4648-
if modelMap["auto_delete"] != nil {
4649-
model.AutoDelete = core.BoolPtr(modelMap["auto_delete"].(bool))
4650-
}
4651-
if modelMap["name"] != nil && modelMap["name"].(string) != "" {
4652-
model.Name = core.StringPtr(modelMap["name"].(string))
4645+
} else {
4646+
if modelMap["address"] != nil && modelMap["address"].(string) != "" {
4647+
model.Address = core.StringPtr(modelMap["address"].(string))
4648+
}
4649+
if modelMap["auto_delete"] != nil {
4650+
model.AutoDelete = core.BoolPtr(modelMap["auto_delete"].(bool))
4651+
}
4652+
if modelMap["name"] != nil && modelMap["name"].(string) != "" {
4653+
model.Name = core.StringPtr(modelMap["name"].(string))
4654+
}
46534655
}
46544656
return model, nil
46554657
}
46564658
func resourceIBMIsBareMetalServerMapToVirtualNetworkInterfacePrimaryIPReservedIPPrototype(modelMap map[string]interface{}) (vpcv1.VirtualNetworkInterfacePrimaryIPPrototypeIntf, error) {
46574659
model := &vpcv1.VirtualNetworkInterfacePrimaryIPPrototype{}
4658-
if modelMap["id"] != nil && modelMap["id"].(string) != "" {
4659-
model.ID = core.StringPtr(modelMap["id"].(string))
4660-
}
4661-
if modelMap["href"] != nil && modelMap["href"].(string) != "" {
4660+
if modelMap["reserved_ip"] != nil && modelMap["reserved_ip"].(string) != "" {
4661+
model.ID = core.StringPtr(modelMap["reserved_ip"].(string))
4662+
} else if modelMap["href"] != nil && modelMap["href"].(string) != "" {
46624663
model.Href = core.StringPtr(modelMap["href"].(string))
4663-
}
4664-
if modelMap["address"] != nil && modelMap["address"].(string) != "" {
4665-
model.Address = core.StringPtr(modelMap["address"].(string))
4666-
}
4667-
if modelMap["auto_delete"] != nil {
4668-
model.AutoDelete = core.BoolPtr(modelMap["auto_delete"].(bool))
4669-
}
4670-
if modelMap["name"] != nil && modelMap["name"].(string) != "" {
4671-
model.Name = core.StringPtr(modelMap["name"].(string))
4664+
} else {
4665+
if modelMap["address"] != nil && modelMap["address"].(string) != "" {
4666+
model.Address = core.StringPtr(modelMap["address"].(string))
4667+
}
4668+
if modelMap["auto_delete"] != nil {
4669+
model.AutoDelete = core.BoolPtr(modelMap["auto_delete"].(bool))
4670+
}
4671+
if modelMap["name"] != nil && modelMap["name"].(string) != "" {
4672+
model.Name = core.StringPtr(modelMap["name"].(string))
4673+
}
46724674
}
46734675
return model, nil
46744676
}

ibm/service/vpc/resource_ibm_is_bare_metal_server_network_attachment.go

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -181,17 +181,19 @@ func ResourceIBMIsBareMetalServerNetworkAttachment() *schema.Resource {
181181
},
182182
"primary_ip": &schema.Schema{
183183
Type: schema.TypeList,
184+
MaxItems: 1,
184185
Optional: true,
185186
Computed: true,
186187
ConflictsWith: []string{"virtual_network_interface.0.id"},
187188
Description: "The primary IP address of the virtual network interface for the bare metal server networkattachment.",
188189
Elem: &schema.Resource{
189190
Schema: map[string]*schema.Schema{
190191
"address": &schema.Schema{
191-
Type: schema.TypeString,
192-
Optional: true,
193-
Computed: true,
194-
Description: "The IP address.If the address has not yet been selected, the value will be `0.0.0.0`.This property may add support for IPv6 addresses in the future. When processing a value in this property, verify that the address is in an expected format. If it is not, log an error. Optionally halt processing and surface the error, or bypass the resource on which the unexpected IP address format was encountered.",
192+
Type: schema.TypeString,
193+
Optional: true,
194+
ConflictsWith: []string{"virtual_network_interface.0.primary_ip.0.reserved_ip"},
195+
Computed: true,
196+
Description: "The IP address.If the address has not yet been selected, the value will be `0.0.0.0`.This property may add support for IPv6 addresses in the future. When processing a value in this property, verify that the address is in an expected format. If it is not, log an error. Optionally halt processing and surface the error, or bypass the resource on which the unexpected IP address format was encountered.",
195197
},
196198
"deleted": &schema.Schema{
197199
Type: schema.TypeList,
@@ -219,10 +221,11 @@ func ResourceIBMIsBareMetalServerNetworkAttachment() *schema.Resource {
219221
Description: "The unique identifier for this reserved IP.",
220222
},
221223
"name": &schema.Schema{
222-
Type: schema.TypeString,
223-
Optional: true,
224-
Computed: true,
225-
Description: "The name for this reserved IP. The name is unique across all reserved IPs in a subnet.",
224+
Type: schema.TypeString,
225+
Optional: true,
226+
ConflictsWith: []string{"virtual_network_interface.0.primary_ip.0.reserved_ip"},
227+
Computed: true,
228+
Description: "The name for this reserved IP. The name is unique across all reserved IPs in a subnet.",
226229
},
227230
"resource_type": &schema.Schema{
228231
Type: schema.TypeString,
@@ -1133,28 +1136,28 @@ func resourceIBMIsBareMetalServerNetworkAttachmentMapToBareMetalServerNetworkAtt
11331136

11341137
func resourceIBMIsBareMetalServerNetworkAttachmentMapToVirtualNetworkInterfaceIPPrototype(modelMap map[string]interface{}) (vpcv1.VirtualNetworkInterfaceIPPrototypeIntf, error) {
11351138
model := &vpcv1.VirtualNetworkInterfaceIPPrototype{}
1136-
if modelMap["id"] != nil && modelMap["id"].(string) != "" {
1137-
model.ID = core.StringPtr(modelMap["id"].(string))
1139+
if modelMap["reserved_ip"] != nil && modelMap["reserved_ip"].(string) != "" {
1140+
model.ID = core.StringPtr(modelMap["reserved_ip"].(string))
11381141
}
11391142
return model, nil
11401143
}
11411144

11421145
func resourceIBMIsBareMetalServerNetworkAttachmentMapToVirtualNetworkInterfacePrimaryIPPrototype(modelMap map[string]interface{}) (vpcv1.VirtualNetworkInterfacePrimaryIPPrototypeIntf, error) {
11431146
model := &vpcv1.VirtualNetworkInterfacePrimaryIPPrototype{}
1144-
if modelMap["id"] != nil && modelMap["id"].(string) != "" {
1145-
model.ID = core.StringPtr(modelMap["id"].(string))
1146-
}
1147-
if modelMap["href"] != nil && modelMap["href"].(string) != "" {
1147+
if modelMap["reserved_ip"] != nil && modelMap["reserved_ip"].(string) != "" {
1148+
model.ID = core.StringPtr(modelMap["reserved_ip"].(string))
1149+
} else if modelMap["href"] != nil && modelMap["href"].(string) != "" {
11481150
model.Href = core.StringPtr(modelMap["href"].(string))
1149-
}
1150-
if modelMap["address"] != nil && modelMap["address"].(string) != "" {
1151-
model.Address = core.StringPtr(modelMap["address"].(string))
1152-
}
1153-
if modelMap["auto_delete"] != nil {
1154-
model.AutoDelete = core.BoolPtr(modelMap["auto_delete"].(bool))
1155-
}
1156-
if modelMap["name"] != nil && modelMap["name"].(string) != "" {
1157-
model.Name = core.StringPtr(modelMap["name"].(string))
1151+
} else {
1152+
if modelMap["address"] != nil && modelMap["address"].(string) != "" {
1153+
model.Address = core.StringPtr(modelMap["address"].(string))
1154+
}
1155+
if modelMap["auto_delete"] != nil {
1156+
model.AutoDelete = core.BoolPtr(modelMap["auto_delete"].(bool))
1157+
}
1158+
if modelMap["name"] != nil && modelMap["name"].(string) != "" {
1159+
model.Name = core.StringPtr(modelMap["name"].(string))
1160+
}
11581161
}
11591162
return model, nil
11601163
}
@@ -1210,7 +1213,7 @@ func resourceIBMIsBareMetalServerNetworkAttachmentVirtualNetworkInterfaceReferen
12101213
ips := []map[string]interface{}{}
12111214
for _, ipsItem := range vniDetails.Ips {
12121215
if *ipsItem.ID != primaryipId {
1213-
ipsItemMap, err := resourceIBMIsVirtualNetworkInterfaceReservedIPReferenceToMap(&ipsItem, true)
1216+
ipsItemMap, err := resourceIBMIsVirtualNetworkInterfaceReservedIPReferenceToMap(&ipsItem, true, false)
12141217
if err != nil {
12151218
return nil, err
12161219
}

0 commit comments

Comments
 (0)