Skip to content

Commit

Permalink
Add satellite features and add support to the user can direct which s…
Browse files Browse the repository at this point in the history
…ecurity groups are added to their workers
  • Loading branch information
Blintmester committed Jan 10, 2024
1 parent b991118 commit 0e399e7
Show file tree
Hide file tree
Showing 18 changed files with 580 additions and 98 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ vendor/
!command/test-fixtures/**/*.tfstate
!command/test-fixtures/**/.terraform/

*.sh
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/IBM-Cloud/terraform-provider-ibm
go 1.19

require (
github.com/IBM-Cloud/bluemix-go v0.0.0-20231204080125-462fa9e436bc
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20231116055201-2a84da7b9bd6
github.com/IBM-Cloud/bluemix-go v0.0.0-20240110132033-6ead1f81a985
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20231207111718-a3b74cc935fa
github.com/IBM-Cloud/power-go-client v1.5.8
github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca
github.com/IBM/appconfiguration-go-admin-sdk v0.3.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ github.com/DataDog/datadog-go v2.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3
github.com/DataDog/datadog-go v3.2.0+incompatible h1:qSG2N4FghB1He/r2mFrWKCaL7dXCilEuNEeAn20fdD4=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/DataDog/zstd v1.4.4/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/IBM-Cloud/bluemix-go v0.0.0-20231204080125-462fa9e436bc h1:AeooCa6UMWycgKJ9n0do9PEZaNlYZZHqspfwUzPvopc=
github.com/IBM-Cloud/bluemix-go v0.0.0-20231204080125-462fa9e436bc/go.mod h1:jIGLnIfj+uBv2ALz3rVHzNbNwt0V/bEWNeJKECa8Q+k=
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20231116055201-2a84da7b9bd6 h1:QXU1Atl/JSI3ZtYB9tHbWLhrFYE1E+5Iww1sjQ7mqdo=
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20231116055201-2a84da7b9bd6/go.mod h1:xUQL9SGAjoZFd4GNjrjjtEpjpkgU7RFXRyHesbKTjiY=
github.com/IBM-Cloud/bluemix-go v0.0.0-20240110132033-6ead1f81a985 h1:Rsi0y9dJZNkF9zIa0Yjf9rdYHb5UqMMGbZvOcsESq90=
github.com/IBM-Cloud/bluemix-go v0.0.0-20240110132033-6ead1f81a985/go.mod h1:jIGLnIfj+uBv2ALz3rVHzNbNwt0V/bEWNeJKECa8Q+k=
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20231207111718-a3b74cc935fa h1:tsgTFGt4j1V3PQmzZbA4wJAeT5rz24OgY4AvY2QGek0=
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20231207111718-a3b74cc935fa/go.mod h1:xUQL9SGAjoZFd4GNjrjjtEpjpkgU7RFXRyHesbKTjiY=
github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.5.3/go.mod h1:RiUvKuHKTBmBApDMUQzBL14pQUGKcx/IioKQPIcRQjs=
github.com/IBM-Cloud/power-go-client v1.5.8 h1:4l9PmnYRXV/KfVNBRuc9hya6kW5cQZhN4UMUMdpn1JU=
github.com/IBM-Cloud/power-go-client v1.5.8/go.mod h1:y4WDw/l9+29CKX98ngCCvGoHdzX49LL00B1euoAbWzQ=
Expand Down
29 changes: 25 additions & 4 deletions ibm/flex/structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,14 @@ func FlattenUsersSet(userList *schema.Set) []string {
return users
}

func FlattenSet(set *schema.Set) []string {
elems := make([]string, 0)
for _, elem := range set.List() {
elems = append(elems, elem.(string))
}
return elems
}

func ExpandMembers(configured []interface{}) []datatypes.Network_LBaaS_LoadBalancerServerInstanceInfo {
members := make([]datatypes.Network_LBaaS_LoadBalancerServerInstanceInfo, 0, len(configured))
for _, lRaw := range configured {
Expand Down Expand Up @@ -429,6 +437,19 @@ func FlattenZones(list []containerv1.WorkerPoolZoneResponse) []map[string]interf
return zones
}

func FlattenZonesv2(list []containerv2.ZoneResp) []map[string]interface{} {
zones := make([]map[string]interface{}, len(list))
for i, zone := range list {
l := map[string]interface{}{
"zone": zone.ID,
"subnets": zone.Subnets,
"worker_count": zone.WorkerCount,
}
zones[i] = l
}
return zones
}

func FlattenWorkerPools(list []containerv1.WorkerPoolResponse) []map[string]interface{} {
workerPools := make([]map[string]interface{}, len(list))
for i, workerPool := range list {
Expand Down Expand Up @@ -3242,13 +3263,13 @@ func FlattenOpaqueSecret(fields containerv2.Fields) []map[string]interface{} {
return flattenedOpaqueSecret
}

// flattenHostLabels ..
func FlattenHostLabels(hostLabels []interface{}) map[string]string {
// flatten the provided key-value pairs
func FlattenKeyValues(keyValues []interface{}) map[string]string {
labels := make(map[string]string)
for _, v := range hostLabels {
for _, v := range keyValues {
parts := strings.Split(v.(string), ":")
if len(parts) != 2 {
log.Fatal("Entered label " + v.(string) + "is in incorrect format.")
log.Fatal("Entered key-value " + v.(string) + "is in incorrect format.")
}
labels[parts[0]] = parts[1]
}
Expand Down
13 changes: 13 additions & 0 deletions ibm/service/kubernetes/resource_ibm_container_vpc_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,14 @@ func ResourceIBMContainerVpcCluster() *schema.Resource {
RequiredWith: []string{"kms_instance_id", "crk"},
},

"security_groups": {
Type: schema.TypeSet,
Optional: true,
Description: "Allow user to set which security groups added to their workers",
Elem: &schema.Schema{Type: schema.TypeString},
Set: flex.ResourceIBMVPCHash,
},

//Get Cluster info Request
"state": {
Type: schema.TypeString,
Expand Down Expand Up @@ -587,6 +595,11 @@ func resourceIBMContainerVpcClusterCreate(d *schema.ResourceData, meta interface
params.CosInstanceCRN = v.(string)
}

if v, ok := d.GetOk("security_groups"); ok {
securityGroups := flex.FlattenSet(v.(*schema.Set))
params.SecurityGroupIDs = securityGroups
}

targetEnv, err := getVpcClusterTargetHeader(d, meta)
if err != nil {
return err
Expand Down
90 changes: 90 additions & 0 deletions ibm/service/kubernetes/resource_ibm_container_vpc_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,34 @@ func TestAccIBMContainerVpcClusterDedicatedHost(t *testing.T) {
)
}

func TestAccIBMContainerVpcClusterSecurityGroups(t *testing.T) {
name := fmt.Sprintf("tf-vpc-cluster-%d", acctest.RandIntRange(10, 100))
var conf *v2.ClusterInfo

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
// CheckDestroy: testAccCheckIBMContainerVpcClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMContainerVpcClusterSecurityGroups(name),
Check: resource.ComposeTestCheckFunc(
testAccCheckIBMContainerVpcExists("ibm_container_vpc_cluster.cluster", conf),
resource.TestCheckResourceAttr(
"ibm_container_vpc_cluster.cluster", "name", name),
),
},
{
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"},
},
},
})
}

func testAccCheckIBMContainerVpcClusterDestroy(s *terraform.State) error {
csClient, err := acc.TestAccProvider.Meta().(conns.ClientSession).VpcContainerAPI()
if err != nil {
Expand Down Expand Up @@ -275,6 +303,68 @@ resource "ibm_container_vpc_cluster" "cluster" {
}`, name)
}

// preveously you have to create securitygroups and use them instead
func testAccCheckIBMContainerVpcClusterSecurityGroups(name string) string {
return fmt.Sprintf(`
data "ibm_resource_group" "resource_group" {
is_default = "true"
//name = "Default"
}
resource "ibm_is_vpc" "vpc" {
name = "%[1]s"
}
resource "ibm_is_security_group" "security_group" {
name = "example-security-group"
vpc = ibm_is_vpc.vpc.id
}
resource "ibm_is_subnet" "subnet" {
name = "%[1]s"
vpc = ibm_is_vpc.vpc.id
zone = "us-south-1"
total_ipv4_address_count = 256
}
resource "ibm_resource_instance" "kms_instance" {
name = "%[1]s"
service = "kms"
plan = "tiered-pricing"
location = "eu-de"
}
resource "ibm_kms_key" "test" {
instance_id = ibm_resource_instance.kms_instance.guid
key_name = "%[1]s"
standard_key = false
force_delete = true
}
resource "ibm_container_vpc_cluster" "cluster" {
name = "%[1]s"
vpc_id = ibm_is_vpc.vpc.id
flavor = "cx2.2x4"
worker_count = 1
wait_till = "OneWorkerNodeReady"
resource_group_id = data.ibm_resource_group.resource_group.id
zones {
subnet_id = ibm_is_subnet.subnet.id
name = "us-south-1"
}
kms_config {
instance_id = ibm_resource_instance.kms_instance.guid
crk_id = ibm_kms_key.test.key_id
private_endpoint = false
}
worker_labels = {
"test" = "test-default-pool"
"test1" = "test-default-pool1"
"test2" = "test-default-pool2"
}
security_groups = [
ibm_is_security_group.security_group.id,
"cluster",
]
}`, name)
}

func testAccCheckIBMContainerVpcClusterUpdate(name string) string {
return fmt.Sprintf(`
provider "ibm" {
Expand Down
Loading

0 comments on commit 0e399e7

Please sign in to comment.