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

add optional secondary storage fields to IKS cluster and workerpool #4255

Merged
merged 6 commits into from
Jan 24, 2023
Merged
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
4 changes: 2 additions & 2 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.18

require (
github.com/IBM-Cloud/bluemix-go v0.0.0-20221026143540-4d6050d2dbc5
github.com/IBM-Cloud/bluemix-go v0.0.0-20230120122421-afb48116b8f1
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20220922071204-21813161c36f
github.com/IBM-Cloud/power-go-client v1.2.2
github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca
Expand Down Expand Up @@ -171,4 +171,4 @@ require (

replace github.com/softlayer/softlayer-go v1.0.3 => github.com/IBM-Cloud/softlayer-go v1.0.5-tf

replace github.com/dgrijalva/jwt-go v3.2.0+incompatible => github.com/golang-jwt/jwt v3.2.1+incompatible
replace github.com/dgrijalva/jwt-go v3.2.0+incompatible => github.com/golang-jwt/jwt v3.2.1+incompatible
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/IBM-Cloud/bluemix-go v0.0.0-20221026143540-4d6050d2dbc5 h1:pIPDTYytM117G4BZBpxPLF40rqvSYDnhLkFDz0/1/MM=
github.com/IBM-Cloud/bluemix-go v0.0.0-20221026143540-4d6050d2dbc5/go.mod h1:cO5KCpiop9eP/pM/5W07TprYUkv/kHtajW1FiZgE59k=
github.com/IBM-Cloud/bluemix-go v0.0.0-20230120122421-afb48116b8f1 h1:5cVMU5MglJjwzoBsDOk3yuH6T/1EeDZyYbQDowL4nW8=
github.com/IBM-Cloud/bluemix-go v0.0.0-20230120122421-afb48116b8f1/go.mod h1:cO5KCpiop9eP/pM/5W07TprYUkv/kHtajW1FiZgE59k=
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20220922071204-21813161c36f h1:VMMqaAUXrNQH84ba/EDbfe8lvQJF9FBUnaQbIa1iKZ0=
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20220922071204-21813161c36f/go.mod h1:xUQL9SGAjoZFd4GNjrjjtEpjpkgU7RFXRyHesbKTjiY=
github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.5.3/go.mod h1:RiUvKuHKTBmBApDMUQzBL14pQUGKcx/IioKQPIcRQjs=
Expand Down
6 changes: 6 additions & 0 deletions ibm/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ var ZonePrivateVlan string
var ZonePublicVlan string
var ZoneUpdatePrivateVlan string
var ZoneUpdatePublicVlan string
var WorkerPoolSecondaryStorage string
var CsRegion string
var ExtendedHardwareTesting bool
var err error
Expand Down Expand Up @@ -459,6 +460,11 @@ func init() {
fmt.Println("[WARN] Set the environment variable IBM_WORKER_POOL_ZONE_UPDATE_PUBLIC_VLAN for testing ibm_container_worker_pool_zone_attachment resource else it is set to default value '2388375'")
}

WorkerPoolSecondaryStorage = os.Getenv("IBM_WORKER_POOL_SECONDARY_STORAGE")
if WorkerPoolSecondaryStorage == "" {
fmt.Println("[WARN] Set the environment variable IBM_WORKER_POOL_SECONDARY_STORAGE for testing secondary_storage attachment to IKS workerpools")
}

placementGroupName = os.Getenv("IBM_PLACEMENT_GROUP_NAME")
if placementGroupName == "" {
placementGroupName = "terraform_group"
Expand Down
16 changes: 16 additions & 0 deletions ibm/flex/structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,19 @@ func FlattenProtocols(list []datatypes.Network_LBaaS_Listener) []map[string]inte
return result
}

func FlattenVpcWorkerPoolSecondaryDisk(secondaryDisk containerv2.DiskConfigResp) []map[string]interface{} {
storageList := make([]map[string]interface{}, 1)
secondary_storage := map[string]interface{}{
"name": secondaryDisk.Name,
"count": secondaryDisk.Count,
"size": secondaryDisk.Size,
"device_type": secondaryDisk.DeviceType,
"raid_configuration": secondaryDisk.RAIDConfiguration,
"profile": secondaryDisk.Profile,
}
storageList[0] = secondary_storage
return storageList
}
func FlattenVpcWorkerPools(list []containerv2.GetWorkerPoolResponse) []map[string]interface{} {
workerPools := make([]map[string]interface{}, len(list))
for i, workerPool := range list {
Expand Down Expand Up @@ -342,6 +355,9 @@ func FlattenVpcWorkerPools(list []containerv2.GetWorkerPoolResponse) []map[strin
zonesConfig[j] = z
}
l["zones"] = zonesConfig
if workerPool.SecondaryStorageOption != nil {
l["secondary_storage"] = FlattenVpcWorkerPoolSecondaryDisk(*workerPool.SecondaryStorageOption)
}
workerPools[i] = l
}

Expand Down
38 changes: 38 additions & 0 deletions ibm/service/kubernetes/data_source_ibm_container_vpc_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,44 @@ func DataSourceIBMContainerVPCCluster() *schema.Resource {
Type: schema.TypeMap,
Computed: true,
},
"operating_system": {
Type: schema.TypeString,
Computed: true,
Description: "The operating system of the workers in the worker pool",
},
"secondary_storage": {
Type: schema.TypeList,
Computed: true,
Description: "The optional secondary storage configuration of the workers in the worker pool.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},
"count": {
Type: schema.TypeInt,
Computed: true,
},
"size": {
Type: schema.TypeInt,
Computed: true,
},
"device_type": {
Type: schema.TypeString,
Computed: true,
},
"raid_configuration": {
Type: schema.TypeString,
Computed: true,
},
"profile": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"state": {
Type: schema.TypeString,
Computed: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,35 @@ data "ibm_container_vpc_cluster" "testacc_cluster_dedicatedhost" {
}
`
}

func testAccCheckIBMContainerVPCClusterDatasourceEnvvar(name string) string {
return testAccCheckIBMContainerVpcClusterEnvvar(name) + `
data "ibm_container_vpc_cluster" "testacc_ds_cluster" {
cluster_name_id = ibm_container_vpc_cluster.cluster.id
}
`
}

func TestAccIBMContainerVPCClusterDataSourceEnvvar(t *testing.T) {
name := fmt.Sprintf("tf-vpc-cluster-%d", acctest.RandIntRange(10, 100))
testChecks := []resource.TestCheckFunc{
resource.TestCheckResourceAttrSet(
"data.ibm_container_vpc_cluster.testacc_ds_cluster", "id"),
resource.TestCheckResourceAttr(
"data.ibm_container_vpc_cluster.testacc_ds_cluster", "worker_pools.#", "1"),
}
if acc.WorkerPoolSecondaryStorage != "" {
testChecks = append(testChecks, resource.TestCheckResourceAttr(
"data.ibm_container_vpc_cluster.testacc_ds_cluster", "worker_pools.0.secondary_storage.0.name", acc.WorkerPoolSecondaryStorage))
}
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMContainerVPCClusterDatasourceEnvvar(name),
Check: resource.ComposeTestCheckFunc(testChecks...),
},
},
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package kubernetes

import (
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down Expand Up @@ -57,6 +58,39 @@ func DataSourceIBMContainerVpcClusterWorkerPool() *schema.Resource {
Computed: true,
Description: "The operating system of the workers in the worker pool",
},
"secondary_storage": {
Type: schema.TypeList,
Computed: true,
Description: "The optional secondary storage configuration of the workers in the worker pool.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},
"count": {
Type: schema.TypeInt,
Computed: true,
},
"size": {
Type: schema.TypeInt,
Computed: true,
},
"device_type": {
Type: schema.TypeString,
Computed: true,
},
"raid_configuration": {
Type: schema.TypeString,
Computed: true,
},
"profile": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"resource_group_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -152,6 +186,11 @@ func dataSourceIBMContainerVpcClusterWorkerPoolRead(d *schema.ResourceData, meta
d.Set("kms_account_id", workerPool.WorkerVolumeEncryption.KMSAccountID)
}
}

if workerPool.SecondaryStorageOption != nil {
d.Set("secondary_storage", flex.FlattenVpcWorkerPoolSecondaryDisk(*workerPool.SecondaryStorageOption))
}

d.SetId(workerPool.ID)
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,26 @@ func testAccCheckIBMContainerVPCClusterWorkerPoolDataSourceConfig(name string) s

func TestAccIBMContainerVPCClusterWorkerPoolDataSourceEnvvar(t *testing.T) {
name := fmt.Sprintf("tf-vpc-wp-%d", acctest.RandIntRange(10, 100))
testChecks := []resource.TestCheckFunc{
resource.TestCheckResourceAttrSet("data.ibm_container_vpc_cluster_worker_pool.testacc_ds_worker_pool", "id"),
}
if acc.CrkID != "" {
testChecks = append(testChecks,
resource.TestCheckResourceAttr("data.ibm_container_vpc_cluster_worker_pool.testacc_ds_worker_pool", "crk", acc.CrkID),
resource.TestCheckResourceAttr("data.ibm_container_vpc_cluster_worker_pool.testacc_ds_worker_pool", "kms_instance_id", acc.KmsInstanceID),
)
}
if acc.WorkerPoolSecondaryStorage != "" {
testChecks = append(testChecks, resource.TestCheckResourceAttr(
"data.ibm_container_vpc_cluster_worker_pool.testacc_ds_worker_pool", "secondary_storage.0.name", acc.WorkerPoolSecondaryStorage))
}
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMContainerVPCClusterWorkerPoolDataSourceEnvvar(name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.ibm_container_vpc_cluster_worker_pool.testacc_ds_worker_pool", "id"),
resource.TestCheckResourceAttr("data.ibm_container_vpc_cluster_worker_pool.testacc_ds_worker_pool", "crk", acc.CrkID),
resource.TestCheckResourceAttr("data.ibm_container_vpc_cluster_worker_pool.testacc_ds_worker_pool", "kms_instance_id", acc.KmsInstanceID),
),
Check: resource.ComposeTestCheckFunc(testChecks...),
},
},
})
Expand Down
15 changes: 15 additions & 0 deletions ibm/service/kubernetes/resource_ibm_container_vpc_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ func ResourceIBMContainerVpcCluster() *schema.Resource {
Description: "The operating system of the workers in the default worker pool.",
},

"secondary_storage": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this computed also? If user doesn't create any secondary storage does API set back any default value

ForceNew: true,
Description: "The secondary storage option for the default worker pool.",
},

"taints": {
Type: schema.TypeSet,
Optional: true,
Expand Down Expand Up @@ -530,6 +538,10 @@ func resourceIBMContainerVpcClusterCreate(d *schema.ResourceData, meta interface
workerpool.OperatingSystem = os.(string)
}

if secondarystorage, ok := d.GetOk("secondary_storage"); ok {
workerpool.SecondaryStorageOption = secondarystorage.(string)
}

if kmsid, ok := d.GetOk("kms_instance_id"); ok {
crk := d.Get("crk").(string)
wve := v2.WorkerVolumeEncryption{
Expand Down Expand Up @@ -1043,6 +1055,9 @@ func resourceIBMContainerVpcClusterRead(d *schema.ResourceData, meta interface{}
d.Set("image_security_enforcement", cls.ImageSecurityEnabled)
d.Set("host_pool_id", workerPool.HostPoolID)
d.Set("operating_system", workerPool.OperatingSystem)
if workerPool.SecondaryStorageOption != nil {
d.Set("secondary_storage", workerPool.SecondaryStorageOption.Name)
}

tags, err := flex.GetTagsUsingCRN(meta, cls.CRN)
if err != nil {
Expand Down
31 changes: 22 additions & 9 deletions ibm/service/kubernetes/resource_ibm_container_vpc_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ func testAccCheckIBMContainerVpcClusterDestroy(s *terraform.State) error {

return nil
}

func testAccCheckIBMContainerVpcExists(n string, conf *v2.ClusterInfo) resource.TestCheckFunc {

return func(s *terraform.State) error {
Expand Down Expand Up @@ -204,6 +205,7 @@ func testAccCheckIBMContainerVpcExists(n string, conf *v2.ClusterInfo) resource.
return nil
}
}

func getVpcClusterTargetHeaderTestACC() v2.ClusterTargetHeader {
c := new(bluemix.Config)
sess, err := session.New(c)
Expand All @@ -216,6 +218,7 @@ func getVpcClusterTargetHeaderTestACC() v2.ClusterTargetHeader {
}
return targetEnv
}

func testAccCheckIBMContainerVpcClusterBasic(name string) string {
return fmt.Sprintf(`
provider "ibm" {
Expand Down Expand Up @@ -271,6 +274,7 @@ resource "ibm_container_vpc_cluster" "cluster" {

}`, name)
}

func testAccCheckIBMContainerVpcClusterUpdate(name string) string {
return fmt.Sprintf(`
provider "ibm" {
Expand Down Expand Up @@ -334,6 +338,7 @@ resource "ibm_container_vpc_cluster" "cluster" {

}`, name)
}

func testAccCheckIBMContainerOcpClusterBasic(name, openshiftFlavour, openShiftworkerCount, operatingSystem string) string {
return fmt.Sprintf(`
data "ibm_resource_instance" "cos_instance" {
Expand Down Expand Up @@ -399,27 +404,34 @@ func TestAccIBMContainerVpcClusterEnvvar(t *testing.T) {
name := fmt.Sprintf("tf-vpc-cluster-%d", acctest.RandIntRange(10, 100))
var conf *v2.ClusterInfo

testChecks := []resource.TestCheckFunc{
testAccCheckIBMContainerVpcExists("ibm_container_vpc_cluster.cluster", conf),
resource.TestCheckResourceAttr(
"ibm_container_vpc_cluster.cluster", "name", name),
resource.TestCheckResourceAttr(
"ibm_container_vpc_cluster.cluster", "worker_count", "1"),
}
if acc.WorkerPoolSecondaryStorage != "" {
testChecks = append(testChecks, resource.TestCheckResourceAttr(
"ibm_container_vpc_cluster.cluster", "secondary_storage", acc.WorkerPoolSecondaryStorage))
}
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
CheckDestroy: testAccCheckIBMContainerVpcClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMContainerVpcClusterEnvvar(name),
Check: resource.ComposeTestCheckFunc(
testAccCheckIBMContainerVpcExists("ibm_container_vpc_cluster.cluster", conf),
resource.TestCheckResourceAttr(
"ibm_container_vpc_cluster.cluster", "name", name),
resource.TestCheckResourceAttr(
"ibm_container_vpc_cluster.cluster", "worker_count", "1"),
),
Check: resource.ComposeTestCheckFunc(testChecks...),
},
{
ResourceName: "ibm_container_vpc_cluster.cluster",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"wait_till", "update_all_workers", "kms_config", "force_delete_storage", "wait_for_worker_update"},
"wait_till", "update_all_workers", "kms_config", "force_delete_storage", "wait_for_worker_update",
"crk", "kms_account_id", "kms_instance_id",
},
},
},
})
Expand Down Expand Up @@ -482,8 +494,9 @@ func testAccCheckIBMContainerVpcClusterEnvvar(name string) string {
kms_instance_id = "%[5]s"
crk = "%[6]s"
kms_account_id = "%[7]s"
secondary_storage = "%[8]s"
}
`, name, acc.IksClusterVpcID, acc.IksClusterResourceGroupID, acc.IksClusterSubnetID, acc.KmsInstanceID, acc.CrkID, acc.KmsAccountID)
`, name, acc.IksClusterVpcID, acc.IksClusterResourceGroupID, acc.IksClusterSubnetID, acc.KmsInstanceID, acc.CrkID, acc.KmsAccountID, acc.WorkerPoolSecondaryStorage)
fmt.Println(config)
return config
}
Expand Down
Loading