Skip to content

Commit

Permalink
Add mtu and accessConfig flags to subnet create commands for terraform (
Browse files Browse the repository at this point in the history
#4690)

* Add mtu and accessConfig flags to subnet create commands for terraform

* Fix terraform compile errors

* Fix terraform compile error from yaml changes

* Clean up warnings in powervs provider

* Fix bug checking region instead of zone for satellite check

* Hide shared processor pool and IBMi license arguments from being set in satellite location

* Fix typing issues in MTU and access config

Three issues here:
- There is no schema.TypeInt64, so I have to set this field to schema.TypeInt.
Pretend this value is an int and then cast it back to an int64. This an
issue with the terraform sdk.
- I accidentally set schema.Int on access config where it should be
schema.TypeString
- All passed in variables by the user need to be set or else the sdk
and/or service broker can't safeguard against bad values correctly

* Update new network field satellite documentation

* Revert nullable name change

Due to incompatibility between to the two service brokers,
this change has to be undone to maintain consistency.

* Update go mod files for new sdk version

* Add satellite network acceptance test

* Update mtu and jumbo descriptions

* Add access-config validation to terraform
  • Loading branch information
ismirlia authored Dec 12, 2023
1 parent d7a0611 commit 17b8132
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 20 deletions.
14 changes: 7 additions & 7 deletions ibm/service/power/data_source_ibm_pi_catalog_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,25 +163,25 @@ func dataSourceIBMPICatalogImagesRead(ctx context.Context, d *schema.ResourceDat
}
if i.Specifications != nil {
s := i.Specifications
if &s.ImageType != nil {
if s.ImageType != "" {
image["image_type"] = s.ImageType
}
if &s.ContainerFormat != nil {
if s.ContainerFormat != "" {
image["container_format"] = s.ContainerFormat
}
if &s.DiskFormat != nil {
if s.DiskFormat != "" {
image["disk_format"] = s.DiskFormat
}
if &s.OperatingSystem != nil {
if s.OperatingSystem != "" {
image["operating_system"] = s.OperatingSystem
}
if &s.HypervisorType != nil {
if s.HypervisorType != "" {
image["hypervisor_type"] = s.HypervisorType
}
if &s.Architecture != nil {
if s.Architecture != "" {
image["architecture"] = s.Architecture
}
if &s.Endianness != nil {
if s.Endianness != "" {
image["endianness"] = s.Endianness
}
}
Expand Down
4 changes: 0 additions & 4 deletions ibm/service/power/data_source_ibm_pi_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ func dataSourceIBMPIInstancesRead(ctx context.Context, d *schema.ResourceData, m
if powervmdata.Addresses != nil {
pvmaddress := make([]map[string]interface{}, len(powervmdata.Addresses))
for i, pvmip := range powervmdata.Addresses {

p := make(map[string]interface{})
p["ip"] = pvmip.IPAddress
p["network_name"] = pvmip.NetworkName
Expand All @@ -257,13 +256,10 @@ func dataSourceIBMPIInstancesRead(ctx context.Context, d *schema.ResourceData, m
pvmaddress[i] = p
}
d.Set("addresses", pvmaddress)

}

if powervmdata.Health != nil {

d.Set("health_status", powervmdata.Health.Status)

}

return nil
Expand Down
12 changes: 10 additions & 2 deletions ibm/service/power/data_source_ibm_pi_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ func DataSourceIBMPINetwork() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"type": {
Type: schema.TypeString,
Computed: true,
},

"vlan_id": {
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -79,6 +77,14 @@ func DataSourceIBMPINetwork() *schema.Resource {
Type: schema.TypeBool,
Computed: true,
},
"mtu": {
Type: schema.TypeInt,
Computed: true,
},
"access_config": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -124,6 +130,8 @@ func dataSourceIBMPINetworkRead(ctx context.Context, d *schema.ResourceData, met
d.Set("dns", networkdata.DNSServers)
}
d.Set("jumbo", networkdata.Jumbo)
d.Set("mtu", networkdata.Mtu)
d.Set("access_config", networkdata.AccessConfig)

return nil

Expand Down
33 changes: 29 additions & 4 deletions ibm/service/power/resource_ibm_pi_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,26 @@ func ResourceIBMPINetwork() *schema.Resource {
Description: "PI network gateway",
},
helpers.PINetworkJumbo: {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "PI network enable MTU Jumbo option",
Type: schema.TypeBool,
Optional: true,
Computed: true,
Deprecated: "deprecated use pi_network_mtu instead",
ExactlyOneOf: []string{helpers.PINetworkMtu, helpers.PINetworkJumbo},
Description: "PI network enable MTU Jumbo option",
},
helpers.PINetworkMtu: {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ExactlyOneOf: []string{helpers.PINetworkMtu, helpers.PINetworkJumbo},
Description: "PI Maximum Transmission Unit",
},
helpers.PINetworkAccessConfig: {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validate.ValidateAllowedStringValues([]string{"internal-only", "outbound-only", "bidirectional-static-route", "bidirectional-bgp", "bidirectional-l2out"}),
Description: "PI network communication configuration",
},
helpers.PICloudInstanceId: {
Type: schema.TypeString,
Expand Down Expand Up @@ -145,6 +161,13 @@ func resourceIBMPINetworkCreate(ctx context.Context, d *schema.ResourceData, met
if v, ok := d.GetOk(helpers.PINetworkJumbo); ok {
body.Jumbo = v.(bool)
}
if v, ok := d.GetOk(helpers.PINetworkMtu); ok {
var mtu int64 = int64(v.(int))
body.Mtu = &mtu
}
if v, ok := d.GetOk(helpers.PINetworkAccessConfig); ok {
body.AccessConfig = models.AccessConfig(v.(string))
}

if networktype == "vlan" {
var networkcidr string
Expand Down Expand Up @@ -216,6 +239,8 @@ func resourceIBMPINetworkRead(ctx context.Context, d *schema.ResourceData, meta
d.Set(helpers.PINetworkName, networkdata.Name)
d.Set(helpers.PINetworkType, networkdata.Type)
d.Set(helpers.PINetworkJumbo, networkdata.Jumbo)
d.Set(helpers.PINetworkMtu, networkdata.Mtu)
d.Set(helpers.PINetworkAccessConfig, networkdata.AccessConfig)
d.Set(helpers.PINetworkGateway, networkdata.Gateway)
ipRangesMap := []map[string]interface{}{}
if networkdata.IPAddressRanges != nil {
Expand Down
2 changes: 1 addition & 1 deletion ibm/service/power/resource_ibm_pi_network_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func isIBMPINetworkPortRefreshFunc(client *st.IBMPINetworkClient, id, networknam
return nil, "", err
}

if &network.PortID != nil {
if network.PortID != nil {
//if network.State == "available" {
log.Printf(" The port has been created with the following ip address and attached to an instance ")
return network, "DOWN", nil
Expand Down
50 changes: 50 additions & 0 deletions ibm/service/power/resource_ibm_pi_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,43 @@ func TestAccIBMPINetworkGatewaybasic(t *testing.T) {
},
})
}

func TestAccIBMPINetworkGatewaybasicSatellite(t *testing.T) {
name := fmt.Sprintf("tf-pi-network-%d", acctest.RandIntRange(10, 100))
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
CheckDestroy: testAccCheckIBMPINetworkDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMPINetworkGatewayConfigSatellite(name),
Check: resource.ComposeTestCheckFunc(
testAccCheckIBMPINetworkExists("ibm_pi_network.power_networks"),
resource.TestCheckResourceAttr(
"ibm_pi_network.power_networks", "pi_network_name", name),
resource.TestCheckResourceAttrSet("ibm_pi_network.power_networks", "pi_gateway"),
resource.TestCheckResourceAttrSet("ibm_pi_network.power_networks", "id"),
resource.TestCheckResourceAttrSet("ibm_pi_network.power_networks", "pi_ipaddress_range.#"),
),
},
{
Config: testAccCheckIBMPINetworkConfigGatewayUpdateDNS(name),
Check: resource.ComposeTestCheckFunc(
testAccCheckIBMPINetworkExists("ibm_pi_network.power_networks"),
resource.TestCheckResourceAttr(
"ibm_pi_network.power_networks", "pi_network_name", name),
resource.TestCheckResourceAttr(
"ibm_pi_network.power_networks", "pi_gateway", "192.168.17.2"),
resource.TestCheckResourceAttr(
"ibm_pi_network.power_networks", "pi_ipaddress_range.0.pi_ending_ip_address", "192.168.17.254"),
resource.TestCheckResourceAttr(
"ibm_pi_network.power_networks", "pi_ipaddress_range.0.pi_starting_ip_address", "192.168.17.3"),
),
},
},
})
}

func testAccCheckIBMPINetworkDestroy(s *terraform.State) error {

sess, err := acc.TestAccProvider.Meta().(conns.ClientSession).IBMPISession()
Expand Down Expand Up @@ -190,3 +227,16 @@ func testAccCheckIBMPINetworkConfigGatewayUpdateDNS(name string) string {
}
`, acc.Pi_cloud_instance_id, name)
}

func testAccCheckIBMPINetworkGatewayConfigSatellite(name string) string {
return fmt.Sprintf(`
resource "ibm_pi_network" "power_networks" {
pi_cloud_instance_id = "%s"
pi_network_name = "%s"
pi_network_type = "vlan"
pi_cidr = "192.168.17.0/24"
pi_network_mtu = 6500
pi_network_access_config = "outbound-only"
}
`, acc.Pi_cloud_instance_id, name)
}
4 changes: 3 additions & 1 deletion website/docs/d/pi_network.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ In addition to all argument reference list, you can access the following attribu
- `used_ip_count` - (Float) The number of used IP addresses.
- `used_ip_percent` - (Float) The percentage of IP addresses used.
- `vlan_id` - (String) The VLAN ID that the network is connected to.
- `jumbo` - (Bool) MTU Jumbo option of the network.
- `jumbo` - (Bool) MTU Jumbo option of the network (for multi-zone locations only). `deprecated`
- `mtu` - (Bool) Maximum Transmission Unit option of the network.
- `access_config` - (String) The network communication configuration option of the network (for satellite locations only).
4 changes: 3 additions & 1 deletion website/docs/r/pi_network.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ Review the argument references that you can specify for your resource.
The `pi_ipaddress_range` block supports:
- `pi_ending_ip_address` - (Required, String) The ending ip address.
- `pi_starting_ip_address` - (Required, String) The staring ip address. **Note** if the `pi_gateway` or `pi_ipaddress_range` is not provided, it will calculate the value based on CIDR respectively.
- `pi_network_jumbo` - (Optional, Bool) MTU Jumbo option of the network.
- `pi_network_jumbo` - (Optional, Bool) MTU Jumbo option of the network (for multi-zone locations only). `deprecated` use `pi_network_mtu` instead.
- `pi_network_mtu` - (Optional, Integer) Maximum Transmission Unit option of the network, min size = 1450 & max size = 9000.
- `pi_network_access_config` - (Optional, String) The network communication configuration option of the network (for satellite locations only).

## Attribute reference

Expand Down

0 comments on commit 17b8132

Please sign in to comment.