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 e007250
Show file tree
Hide file tree
Showing 23 changed files with 604 additions and 121 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
6 changes: 3 additions & 3 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 Expand Up @@ -83,7 +83,7 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v3 v3.2.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/cloudfoundry/jibber_jabber v0.0.0-20151120183258-bcc4c8345a21 // indirect
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
github.com/coreos/pkg v0.0.0-20220810130054-c7d1c02cb6cf // indirect
Expand Down
11 changes: 6 additions & 5 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 Expand Up @@ -314,8 +314,9 @@ github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6D
github.com/circonus-labs/circonusllhist v0.1.3 h1:TJH+oke8D16535+jHExHj4nQvzlZrj7ug5D7I/orNUA=
github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs=
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
github.com/cloudfoundry-community/go-cfclient v0.0.0-20190201205600-f136f9222381/go.mod h1:e5+USP2j8Le2M0Jo3qKPFnNhuo1wueU4nWHCXBOfQ14=
github.com/cloudfoundry/jibber_jabber v0.0.0-20151120183258-bcc4c8345a21 h1:tuijfIjZyjZaHq9xDUh0tNitwXshJpbLkqMOJv4H3do=
github.com/cloudfoundry/jibber_jabber v0.0.0-20151120183258-bcc4c8345a21/go.mod h1:po7NpZ/QiTKzBKyrsEAxwnTamCoh8uDk/egRpQ7siIc=
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright IBM Corp. 2023 All Rights Reserved.
// Copyright IBM Corp. 2024 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0

package cdtoolchain
Expand Down Expand Up @@ -94,12 +94,12 @@ func DataSourceIBMCdToolchainToolSecuritycompliance() *schema.Resource {
"evidence_namespace": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The kind of pipeline evidence to be displayed in Security and Compliance Center for this toolchain. The values are; `cd` which will use evidence generated by a Continuous Deployment pipeline, or `cc` which will use evidence generated by a Continuous Compliance pipeline.",
Description: "The kind of pipeline evidence to be displayed in Security and Compliance Center for this toolchain. The values are; `cd` which will use evidence generated by a Continuous Deployment (CD) pipeline, or `cc` which will use evidence generated by a Continuous Compliance (CC) pipeline. The default behavior is to use the CD evidence.",
},
"use_profile_attachment": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Set to `enabled` to enable use profile with attachment, so that the scripts in the pipeline can interact with the Security and Compliance Center service. When enabled, other parameters become relevant; `scc_api_key`, `instance_crn`, `profile_name`, `profile_version`, `attachment_id`.",
Description: "Set to `enabled` to enable use profile with attachment, so that the scripts in the pipeline can interact with the Security and Compliance Center service to perform pre-deploy validation against compliance rules for Continuous Deployment (CD) and compliance monitoring for Continuous Compliance (CC). When enabled, other parameters become relevant; `scc_api_key`, `instance_crn`, `profile_name`, `profile_version`, `attachment_id`.",
},
"scc_api_key": &schema.Schema{
Type: schema.TypeString,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright IBM Corp. 2023 All Rights Reserved.
// Copyright IBM Corp. 2024 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0

package cdtoolchain
Expand Down Expand Up @@ -58,12 +58,12 @@ func ResourceIBMCdToolchainToolSecuritycompliance() *schema.Resource {
"evidence_namespace": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Description: "The kind of pipeline evidence to be displayed in Security and Compliance Center for this toolchain. The values are; `cd` which will use evidence generated by a Continuous Deployment pipeline, or `cc` which will use evidence generated by a Continuous Compliance pipeline.",
Description: "The kind of pipeline evidence to be displayed in Security and Compliance Center for this toolchain. The values are; `cd` which will use evidence generated by a Continuous Deployment (CD) pipeline, or `cc` which will use evidence generated by a Continuous Compliance (CC) pipeline. The default behavior is to use the CD evidence.",
},
"use_profile_attachment": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Description: "Set to `enabled` to enable use profile with attachment, so that the scripts in the pipeline can interact with the Security and Compliance Center service. When enabled, other parameters become relevant; `scc_api_key`, `instance_crn`, `profile_name`, `profile_version`, `attachment_id`.",
Description: "Set to `enabled` to enable use profile with attachment, so that the scripts in the pipeline can interact with the Security and Compliance Center service to perform pre-deploy validation against compliance rules for Continuous Deployment (CD) and compliance monitoring for Continuous Compliance (CC). When enabled, other parameters become relevant; `scc_api_key`, `instance_crn`, `profile_name`, `profile_version`, `attachment_id`.",
},
"scc_api_key": &schema.Schema{
Type: schema.TypeString,
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 e007250

Please sign in to comment.