Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alb fix and add Ingress status report #5160

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/IBM-Cloud/terraform-provider-ibm
go 1.19

require (
github.com/IBM-Cloud/bluemix-go v0.0.0-20240110132033-6ead1f81a985
github.com/IBM-Cloud/bluemix-go v0.0.0-20240226130409-ce92adb39a22
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240216115622-a311507b4b5b
github.com/IBM-Cloud/power-go-client v1.5.8
github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca
Expand Down Expand Up @@ -128,7 +128,7 @@ require (
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.5.1 // indirect
github.com/hashicorp/go-plugin v1.6.0 // indirect
github.com/hashicorp/go-retryablehttp v0.7.5 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.7 // indirect
Expand All @@ -141,9 +141,9 @@ require (
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hashicorp/terraform-exec v0.19.0 // indirect
github.com/hashicorp/terraform-json v0.17.1 // indirect
github.com/hashicorp/terraform-plugin-go v0.19.0 // indirect
github.com/hashicorp/terraform-plugin-go v0.20.0 // indirect
github.com/hashicorp/terraform-plugin-log v0.9.0 // indirect
github.com/hashicorp/terraform-registry-address v0.2.2 // indirect
github.com/hashicorp/terraform-registry-address v0.2.3 // indirect
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
github.com/hashicorp/vault v1.13.7 // indirect
github.com/hashicorp/vault/api v1.9.2 // indirect
Expand Down Expand Up @@ -199,7 +199,7 @@ require (
github.com/stretchr/objx v0.5.0 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/zclconf/go-cty v1.14.1 // indirect
go.mongodb.org/mongo-driver v1.14.0 // indirect
Expand All @@ -208,17 +208,15 @@ require (
go.uber.org/ratelimit v0.2.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/oauth2 v0.7.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/oauth2 v0.13.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/term v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.16.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
google.golang.org/grpc v1.57.1 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 // indirect
google.golang.org/grpc v1.60.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/go-playground/validator.v9 v9.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
Expand Down
60 changes: 36 additions & 24 deletions go.sum

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions ibm/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,13 +537,13 @@ func init() {
PublicVlanID = os.Getenv("IBM_PUBLIC_VLAN_ID")
if PublicVlanID == "" {
PublicVlanID = "2393319"
fmt.Println("[WARN] Set the environment variable IBM_PUBLIC_VLAN_ID for testing ibm_container_cluster resource else it is set to default value '2393319'")
fmt.Println("[WARN] Set the environment variable IBM_PUBLIC_VLAN_ID for testing ibm_container_cluster resource or ibm_container_alb_create resource else it is set to default value '2393319'")
}

PrivateVlanID = os.Getenv("IBM_PRIVATE_VLAN_ID")
if PrivateVlanID == "" {
PrivateVlanID = "2393321"
fmt.Println("[WARN] Set the environment variable IBM_PRIVATE_VLAN_ID for testing ibm_container_cluster resource else it is set to default value '2393321'")
fmt.Println("[WARN] Set the environment variable IBM_PRIVATE_VLAN_ID for testing ibm_container_cluster resource or ibm_container_alb_create resource else it is set to default value '2393321'")
}

KubeVersion = os.Getenv("IBM_KUBE_VERSION")
Expand Down Expand Up @@ -1392,17 +1392,17 @@ func init() {

IksClusterVpcID = os.Getenv("IBM_CLUSTER_VPC_ID")
if IksClusterVpcID == "" {
fmt.Println("[WARN] Set the environment variable IBM_CLUSTER_VPC_ID for testing ibm_container_vpc_alb_create resources, ibm_container_vpc_alb_create tests will fail if this is not set")
fmt.Println("[WARN] Set the environment variable IBM_CLUSTER_VPC_ID for testing ibm_container_vpc_alb_create resources or ibm_container_vpc_cluster resource, ibm_container_vpc_alb_create tests will fail if this is not set")
}

IksClusterSubnetID = os.Getenv("IBM_CLUSTER_VPC_SUBNET_ID")
if IksClusterSubnetID == "" {
fmt.Println("[WARN] Set the environment variable IBM_CLUSTER_VPC_SUBNET_ID for testing ibm_container_vpc_alb_create resources, ibm_container_vpc_alb_creates tests will fail if this is not set")
fmt.Println("[WARN] Set the environment variable IBM_CLUSTER_VPC_SUBNET_ID for testing ibm_container_vpc_alb_create resources or ibm_container_vpc_cluster resource, ibm_container_vpc_alb_create, ibm_container_vpc_alb_creates tests will fail if this is not set")
}

IksClusterResourceGroupID = os.Getenv("IBM_CLUSTER_VPC_RESOURCE_GROUP_ID")
if IksClusterResourceGroupID == "" {
fmt.Println("[WARN] Set the environment variable IBM_CLUSTER_VPC_RESOURCE_GROUP_ID for testing ibm_container_vpc_alb_create resources, ibm_container_vpc_alb_creates tests will fail if this is not set")
fmt.Println("[WARN] Set the environment variable IBM_CLUSTER_VPC_RESOURCE_GROUP_ID for testing ibm_container_vpc_alb_create resources or ibm_container_vpc_cluster resource, ibm_container_vpc_alb_creates tests will fail if this is not set")
}

ClusterName = os.Getenv("IBM_CONTAINER_CLUSTER_NAME")
Expand Down
13 changes: 13 additions & 0 deletions ibm/flex/structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -4293,3 +4293,16 @@ func Listdifference(a, b []string) []string {
}
return ab
}

func FlattenGeneralIngressStatus(list []containerv2.V2IngressComponentStatus) []map[string]interface{} {
componentStatusList := make([]map[string]interface{}, len(list))

for i, component := range list {
actualComponent := make(map[string]interface{})
actualComponent["component"] = component.Component
actualComponent["status"] = component.Status
componentStatusList[i] = actualComponent
}

return componentStatusList
}
37 changes: 30 additions & 7 deletions ibm/service/kubernetes/data_source_ibm_container_alb.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,42 @@ func DataSourceIBMContainerALB() *schema.Resource {
Computed: true,
Description: "set to true if ALB needs to be enabled",
},
"zone": {
Type: schema.TypeString,
Computed: true,
Description: "ALB zone",
},
"state": {
Type: schema.TypeString,
Computed: true,
Description: "ALB state",
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "Status of the ALB",
},
"version": {
Type: schema.TypeString,
Computed: true,
Description: "The type of Ingress image that you want to use for your ALB deployment.",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type is either public or private so I do not think this a valid wording.

Suggested change
Description: "The type of Ingress image that you want to use for your ALB deployment.",
Description: "the version of the ALB image",

Maybe a pointer could be nice to acquire the current supported images, in the description.

And I believe we should change the alb_type description to a more meaningful one like: the type of ALB, available options: public, private but since it is not part of this change I can't comment there.

},
"resource_group_id": {
Type: schema.TypeString,
Computed: true,
Description: "ID of the resource group.",
},
"disable_deployment": {
Type: schema.TypeBool,
Computed: true,
Description: "Set to true if ALB needs to be disabled",
Deprecated: "This field deprecated and no longer supported",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "ALB name",
},
"zone": {
Type: schema.TypeString,
Computed: true,
Description: "ALB zone",
Deprecated: "This field deprecated and no longer supported",
},
},
}
Expand Down Expand Up @@ -81,9 +103,10 @@ func dataSourceIBMContainerALBRead(d *schema.ResourceData, meta interface{}) err
d.Set("name", &albConfig.Name)
d.Set("enable", &albConfig.Enable)
d.Set("disable_deployment", &albConfig.DisableDeployment)
d.Set("replicas", &albConfig.NumOfInstances)
d.Set("resize", &albConfig.Resize)
d.Set("user_ip", &albConfig.ALBIP)
d.Set("zone", &albConfig.Zone)
d.Set("state", &albConfig.State)
d.Set("status", &albConfig.Status)
d.Set("version", &albConfig.ALBBuild)
return nil
}
65 changes: 65 additions & 0 deletions ibm/service/kubernetes/data_source_ibm_container_alb_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright IBM Corp. 2017, 2024 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0

package kubernetes_test

import (
"fmt"
"regexp"
"testing"

acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccIBMContainerALBDataSource_Basic(t *testing.T) {
clusterName := fmt.Sprintf("terraform_%d", acctest.RandIntRange(10, 100))

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
CheckDestroy: testAccCheckIBMContainerALBDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMContainerALBDataSourceBasic(clusterName, true),
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr(
"data.ibm_container_alb.alb", "alb_id", regexp.MustCompile("^(public|private)-cr.*-alb[1-10]$")),
resource.TestMatchResourceAttr(
"data.ibm_container_alb.alb", "enable", regexp.MustCompile("^true|false$")),
resource.TestMatchResourceAttr(
"data.ibm_container_alb.alb", "alb_type", regexp.MustCompile("^public|private$")),
resource.TestMatchResourceAttr(
"data.ibm_container_alb.alb", "state", regexp.MustCompile("^enabled|disabled$")),
resource.TestCheckResourceAttr(
"data.ibm_container_alb.alb", "zone", acc.Zone),
resource.TestMatchResourceAttr(
"data.ibm_container_alb.alb", "status", regexp.MustCompile("^healthy|warning|disabled$")),
),
},
},
})
}

func testAccCheckIBMContainerALBDataSourceBasic(clusterName string, enable bool) string {
config := fmt.Sprintf(`resource "ibm_container_cluster" "testacc_cluster" {
name = "%s"
datacenter = "%s"
default_pool_size = 1
machine_type = "%s"
hardware = "shared"
public_vlan_id = "%s"
private_vlan_id = "%s"
timeouts {
create = "120m"
update = "120m"
}
}

data "ibm_container_alb" "alb" {
alb_id = ibm_container_cluster.testacc_cluster.albs[0].id
}`, clusterName, acc.Datacenter, acc.MachineType, acc.PublicVlanID, acc.PrivateVlanID)

return config
}
Loading