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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add entitlement option to Satellite cluster/workerpool create #4894

Merged
merged 5 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,5 @@ exclude (
k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible
k8s.io/client-go v12.0.0+incompatible
)

replace github.com/IBM-Cloud/container-services-go-sdk => ../container-services-go-sdk
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ func DataSourceIBMSatelliteClusterWorkerPool() *schema.Resource {
Computed: true,
Description: "Enable auto scalling for worker pool",
},
"openshift_license_source": {
Type: schema.TypeString,
Computed: true,
Description: "License source for Openshift",
},
},
}
}
Expand Down Expand Up @@ -154,6 +159,7 @@ func dataSourceIBMSatelliteClusterWorkerPoolRead(d *schema.ResourceData, meta in
d.Set("auto_scale_enabled", *workerPool.AutoscaleEnabled)
d.Set("state", *workerPool.Lifecycle.ActualState)
d.Set("isolation", *workerPool.Isolation)
d.Set("openshift_license_source", *workerPool.OpenshiftLicense)
d.SetId(*workerPool.ID)

return nil
Expand Down
11 changes: 11 additions & 0 deletions ibm/service/satellite/resource_ibm_satellite_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ func ResourceIBMSatelliteCluster() *schema.Resource {
},
Description: "The OpenShift Container Platform version",
},
"entitlement": {
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: flex.ApplyOnce,
Description: "Entitlement option reduces additional OCP Licence cost in Openshift Clusters",
},
"operating_system": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -390,6 +396,11 @@ func resourceIBMSatelliteClusterCreate(d *schema.ResourceData, meta interface{})
createClusterOptions.Labels = hostLabels
}

if v, ok := d.GetOk("entitlement"); ok {
entitlement := v.(string)
createClusterOptions.DefaultWorkerPoolEntitlement = &entitlement
}

if v, ok := d.GetOk("crn_token"); ok {
crnToken := v.(string)
createRemoteClusterOptions := &kubernetesserviceapiv1.CreateSatelliteClusterRemoteOptions{}
Expand Down
141 changes: 141 additions & 0 deletions ibm/service/satellite/resource_ibm_satellite_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,38 @@ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVE
})
}

func TestAccSatelliteCluster_Entitlement(t *testing.T) {
var instance string
clusterName := fmt.Sprintf("tf-satellitecluster-%d", acctest.RandIntRange(10, 100))
locationName := fmt.Sprintf("tf-satellitelocation-%d", acctest.RandIntRange(10, 100))
managed_from := "dal10"
operatingSystem := "REDHAT_8_64"
zones := []string{"us-south-1", "us-south-2", "us-south-3"}
resource_group := "default"
region := "us-south"
resource_prefix := "tf-satellite"
host_provider := "ibm"
publicKey := strings.TrimSpace(`
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVERRN7/9484SOBJ3HSKxxNG5JN8owAjy5f9yYwcUg+JaUVuytn5Pv3aeYROHGGg+5G346xaq3DAwX6Y5ykr2fvjObgncQBnuU5KHWCECO/4h8uWuwh/kfniXPVjFToc+gnkqA+3RKpAecZhFXwfalQ9mMuYGFxn+fwn8cYEApsJbsEmb0iJwPiZ5hjFC8wREuiTlhPHDgkBLOiycd20op2nXzDbHfCHInquEe/gYxEitALONxm0swBOwJZwlTDOB7C6y2dzlrtxr1L59m7pCkWI4EtTRLvleehBoj3u7jB4usR
`)

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
CheckDestroy: testAccCheckSatelliteClusterDestroy,
Steps: []resource.TestStep{

{
Config: testAccCheckSatelliteEntitlementClusterCreate(clusterName, locationName, managed_from, operatingSystem, resource_group, resource_prefix, region, publicKey, host_provider, zones),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckSatelliteClusterExists("ibm_satellite_cluster.create_cluster", instance),
resource.TestCheckResourceAttr("data.ibm_satellite_cluster_worker_pool.read_default_wp", "openshift_license_source", "cloud_pak"),
),
},
},
})
}

func TestAccSatelliteCluster_Import(t *testing.T) {
var instance string
clusterName := fmt.Sprintf("tf-satellitecluster-%d", acctest.RandIntRange(10, 100))
Expand Down Expand Up @@ -382,3 +414,112 @@ func testAccCheckSatelliteSingleNodeClusterCreate(clusterName, locationName, man

`, locationName, managed_from, resource_group, resource_prefix, resource_prefix, region, resource_prefix, publicKey, resource_prefix, region, resource_prefix, host_provider, clusterName)
}

func testAccCheckSatelliteEntitlementClusterCreate(clusterName, locationName, managed_from, operatingSystem, resource_group, resource_prefix, region, publicKey, host_provider string, zones []string) string {
return fmt.Sprintf(`

variable "location_zones" {
description = "Allocate your hosts across these three zones"
type = list(string)
default = ["us-south-1", "us-south-2", "us-south-3"]
}

data "ibm_is_image" "rhel8" {
name = "ibm-redhat-8-8-minimal-amd64-2"
}

resource "ibm_satellite_location" "location" {
location = "%s"
managed_from = "%s"
zones = var.location_zones
coreos_enabled = true
}

data "ibm_satellite_attach_host_script" "script" {
location = ibm_satellite_location.location.id
labels = ["env:prod"]
host_provider = "ibm"
}

data "ibm_resource_group" "resource_group" {
name = "%s"
}

resource "ibm_is_vpc" "satellite_vpc" {
name = "%s-vpc-1"
}

resource "ibm_is_subnet" "satellite_subnet" {
count = 3

name = "%s-subnet-${count.index}"
vpc = ibm_is_vpc.satellite_vpc.id
total_ipv4_address_count = 256
zone = "%s-${count.index + 1}"
}

resource "ibm_is_ssh_key" "satellite_ssh" {
name = "%s-ibm-ssh"
public_key = "%s"
}

resource "ibm_is_instance" "satellite_instance" {
count = 3

name = "%s-instance-${count.index}"
vpc = ibm_is_vpc.satellite_vpc.id
zone = "%s-${count.index + 1}"
image = data.ibm_is_image.rhel8.id
profile = "mx2-8x64"
keys = [ibm_is_ssh_key.satellite_ssh.id]
resource_group = data.ibm_resource_group.resource_group.id
user_data = data.ibm_satellite_attach_host_script.script.host_script

primary_network_interface {
subnet = ibm_is_subnet.satellite_subnet[count.index].id
}
}

resource "ibm_is_floating_ip" "satellite_ip" {
count = 3

name = "%s-fip-${count.index}"
target = ibm_is_instance.satellite_instance[count.index].primary_network_interface[0].id
}

resource "ibm_satellite_host" "assign_host" {
count = 3

location = ibm_satellite_location.location.id
host_id = element(ibm_is_instance.satellite_instance[*].name, count.index)
labels = ["env:prod"]
zone = element(var.location_zones, count.index)
host_provider = "%s"
}

resource "ibm_satellite_cluster" "create_cluster" {
name = "%s"
location = ibm_satellite_host.assign_host.0.location
enable_config_admin = true
kube_version = "4.13_openshift"
operating_system = "%s"
entitlement = "cloud_pak"
wait_for_worker_update = true
dynamic "zones" {
for_each = var.location_zones
content {
id = zones.value
}
}
default_worker_pool_labels = {
"test" = "test-pool1"
"test1" = "test-pool2"
}
}

data "ibm_satellite_cluster_worker_pool" "read_default_wp" {
name = "default"
cluster = ibm_satellite_cluster.create_cluster.id
}
`, locationName, managed_from, resource_group, resource_prefix, resource_prefix, region, resource_prefix, publicKey, resource_prefix, region, resource_prefix, host_provider, clusterName, operatingSystem)
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@ func ResourceIBMSatelliteClusterWorkerPool() *schema.Resource {
Computed: true,
},
"entitlement": {
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: flex.ApplyOnce,
Description: "Entitlement option reduces additional OCP Licence cost in Openshift Clusters",
},
"operating_system": {
Type: schema.TypeString,
Expand Down Expand Up @@ -261,6 +263,11 @@ func resourceIBMSatelliteClusterWorkerPoolCreate(d *schema.ResourceData, meta in
createWorkerPoolOptions.Isolation = &isolation
}

if v, ok := d.GetOk("entitlement"); ok {
entitlement := v.(string)
createWorkerPoolOptions.Entitlement = &entitlement
}

instance, response, err := satClient.CreateSatelliteWorkerPool(createWorkerPoolOptions)
if err != nil {
return fmt.Errorf("[ERROR] Error Creating Satellite cluster worker pool: %s\n%s", err, response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,34 @@ func TestAccSatelliteClusterWorkerPool_Basic(t *testing.T) {
})
}

func TestAccSatelliteClusterWorkerPool_Entitlement(t *testing.T) {
var instance string
clusterName := fmt.Sprintf("tf-satellitecluster-%d", acctest.RandIntRange(10, 100))
locationName := fmt.Sprintf("tf-satellitelocation-%d", acctest.RandIntRange(10, 100))
operatingSystem := "REDHAT_8_64"
workerPoolName := fmt.Sprintf("tf-wp-%d", acctest.RandIntRange(10, 100))
resource_prefix := "tf-satellite"

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
CheckDestroy: testAccCheckSatelliteClusterWorkerPoolDestroy,
Steps: []resource.TestStep{

{
Config: testAccCheckSatelliteClusterWorkerPoolCreateEntitlement(clusterName, locationName, operatingSystem, workerPoolName, resource_prefix),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckSatelliteClusterWorkerPoolExists("ibm_satellite_cluster_worker_pool.create_wp", instance),
resource.TestCheckResourceAttr("ibm_satellite_cluster.create_cluster", "name", clusterName),
resource.TestCheckResourceAttr("ibm_satellite_cluster_worker_pool.create_wp", "name", workerPoolName),
resource.TestCheckResourceAttr("ibm_satellite_cluster_worker_pool.create_wp", "operating_system", operatingSystem),
resource.TestCheckResourceAttr("data.ibm_satellite_cluster_worker_pool.read_created_wp", "openshift_license_source", "cloud_pak"),
),
},
},
})
}

func TestAccSatelliteClusterWorkerPool_Import(t *testing.T) {
var instance string
clusterName := fmt.Sprintf("tf-satellitecluster-%d", acctest.RandIntRange(10, 100))
Expand Down Expand Up @@ -262,3 +290,130 @@ func testAccCheckSatelliteClusterWorkerPoolCreate(clusterName, locationName, ope

`, locationName, resource_prefix, resource_prefix, resource_prefix, resource_prefix, resource_prefix, clusterName, workerPoolName, operatingSystem)
}

func testAccCheckSatelliteClusterWorkerPoolCreateEntitlement(clusterName, locationName, operatingSystem, workerPoolName, resource_prefix string) string {
return fmt.Sprintf(`

variable "location_zones" {
description = "Allocate your hosts across these three zones"
type = list(string)
default = ["us-south-1", "us-south-2", "us-south-3"]
}

resource "ibm_satellite_location" "location" {
location = "%s"
managed_from = "dal10"
zones = var.location_zones
coreos_enabled = true
}

data "ibm_is_image" "rhel8" {
name = "ibm-redhat-8-8-minimal-amd64-2"
}

data "ibm_satellite_attach_host_script" "script" {
location = ibm_satellite_location.location.id
labels = ["env:prod"]
host_provider = "ibm"
}

data "ibm_resource_group" "resource_group" {
is_default = true
}

resource "ibm_is_vpc" "satellite_vpc" {
name = "%s-vpc-1"
}

resource "ibm_is_subnet" "satellite_subnet" {
count = 3

name = "%s-subnet-${count.index}"
vpc = ibm_is_vpc.satellite_vpc.id
total_ipv4_address_count = 256
zone = "us-south-${count.index + 1}"
}

resource "ibm_is_ssh_key" "satellite_ssh" {
name = "%s-ibm-ssh"
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVERRN7/9484SOBJ3HSKxxNG5JN8owAjy5f9yYwcUg+JaUVuytn5Pv3aeYROHGGg+5G346xaq3DAwX6Y5ykr2fvjObgncQBnuU5KHWCECO/4h8uWuwh/kfniXPVjFToc+gnkqA+3RKpAecZhFXwfalQ9mMuYGFxn+fwn8cYEApsJbsEmb0iJwPiZ5hjFC8wREuiTlhPHDgkBLOiycd20op2nXzDbHfCHInquEe/gYxEitALONxm0swBOwJZwlTDOB7C6y2dzlrtxr1L59m7pCkWI4EtTRLvleehBoj3u7jB4usR"
}

resource "ibm_is_instance" "satellite_instance" {
count = 3

name = "%s-instance-${count.index}"
vpc = ibm_is_vpc.satellite_vpc.id
zone = "us-south-${count.index + 1}"
image = data.ibm_is_image.rhel8.id
profile = "mx2-8x64"
keys = [ibm_is_ssh_key.satellite_ssh.id]
resource_group = data.ibm_resource_group.resource_group.id
user_data = data.ibm_satellite_attach_host_script.script.host_script

primary_network_interface {
subnet = ibm_is_subnet.satellite_subnet[count.index].id
}
}

resource "ibm_is_floating_ip" "satellite_ip" {
count = 3

name = "%s-fip-${count.index}"
target = ibm_is_instance.satellite_instance[count.index].primary_network_interface[0].id
}

resource "ibm_satellite_host" "assign_host" {
count = 3

location = ibm_satellite_location.location.id
host_id = element(ibm_is_instance.satellite_instance[*].name, count.index)
labels = ["env:prod"]
zone = element(var.location_zones, count.index)
host_provider = "ibm"
}

resource "ibm_satellite_cluster" "create_cluster" {
name = "%s"
location = ibm_satellite_location.location.id
enable_config_admin = true
kube_version = "4.13_openshift"
wait_for_worker_update = true
dynamic "zones" {
for_each = var.location_zones
content {
id = zones.value
}
}
default_worker_pool_labels = {
"test" = "test-pool1"
"test1" = "test-pool2"
}
}

resource "ibm_satellite_cluster_worker_pool" "create_wp" {
name = "%s"
cluster = ibm_satellite_cluster.create_cluster.id
worker_count = 1
host_labels = ["env:dev"]
operating_system = "%s"
entitlement = "cloud_pak"
dynamic "zones" {
for_each = var.location_zones
content {
id = zones.value
}
}
worker_pool_labels = {
"test" = "test-pool1"
"test1" = "test-pool2"
}
}

data "ibm_satellite_cluster_worker_pool" "read_created_wp" {
name = ibm_satellite_cluster_worker_pool.create_wp.name
cluster = ibm_satellite_cluster.create_cluster.id
}

`, locationName, resource_prefix, resource_prefix, resource_prefix, resource_prefix, resource_prefix, clusterName, workerPoolName, operatingSystem)
}
1 change: 1 addition & 0 deletions website/docs/d/satellite_cluster_worker_pool.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ In addition to all argument references list, you can access the following attrib
- `isolation` - (String) Isolation of the worker node.
- `auto_scale_enabled` - (String) Enable auto scalling for worker pool.
- `worker_count` - (String) The number of workers that are attached.
- `openshift_license_source` - (String) The license source for OpenShift.