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

Support: VPC cluster worker pool Data Source #1773

Merged
merged 1 commit into from
Aug 5, 2020
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
106 changes: 106 additions & 0 deletions ibm/data_source_ibm_container_vpc_worker_pool.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package ibm

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

func dataSourceIBMContainerVpcClusterWorkerPool() *schema.Resource {
return &schema.Resource{
Read: dataSourceIBMContainerVpcClusterWorkerPoolRead,
Schema: map[string]*schema.Schema{
"cluster": {
Type: schema.TypeString,
Required: true,
Description: "Cluster name",
},
"worker_pool_name": {
Type: schema.TypeString,
Required: true,
Description: "worker pool name",
},
"flavor": {
Type: schema.TypeString,
Computed: true,
},
"zones": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},

"subnet_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"labels": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"resource_group_id": {
Type: schema.TypeString,
Computed: true,
},
"vpc_id": {
Type: schema.TypeString,
Computed: true,
},
"worker_count": {
Type: schema.TypeInt,
Computed: true,
},
"isolation": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
func dataSourceIBMContainerVpcClusterWorkerPoolRead(d *schema.ResourceData, meta interface{}) error {
wpClient, err := meta.(ClientSession).VpcContainerAPI()
if err != nil {
return err
}
clusterName := d.Get("cluster").(string)
workerPoolName := d.Get("worker_pool_name").(string)
workerPoolsAPI := wpClient.WorkerPools()
targetEnv, err := getVpcClusterTargetHeader(d, meta)
if err != nil {
return err
}

workerPool, err := workerPoolsAPI.GetWorkerPool(clusterName, workerPoolName, targetEnv)
if err != nil {
return err
}

var zones = make([]map[string]interface{}, 0)
for _, zone := range workerPool.Zones {
for _, subnet := range zone.Subnets {
zoneInfo := map[string]interface{}{
"name": zone.ID,
"subnet_id": subnet.ID,
}
zones = append(zones, zoneInfo)
}
}
d.Set("worker_pool_name", workerPool.PoolName)
d.Set("flavor", workerPool.Flavor)
d.Set("worker_count", workerPool.WorkerCount)
d.Set("provider", workerPool.Provider)
d.Set("labels", workerPool.Labels)
d.Set("zones", zones)
d.Set("cluster", clusterName)
d.Set("vpc_id", workerPool.VpcID)
d.Set("isolation", workerPool.Isolation)
d.Set("resource_group_id", targetEnv.ResourceGroup)
d.SetId(workerPool.ID)
return nil
}
37 changes: 37 additions & 0 deletions ibm/data_source_ibm_container_vpc_worker_pool_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package ibm

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccIBMContainerVPCClusterWorkerPoolDataSource_basic(t *testing.T) {
flavor := "c2.2x4"
worker_count := 1
name1 := acctest.RandIntRange(10, 100)
name2 := acctest.RandIntRange(10, 100)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccCheckIBMContainerVPCClusterWorkerPoolDataSourceConfig(flavor, worker_count, name1, name2),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.ibm_container_vpc_cluster_worker_pool.testacc_ds_worker_pool", "id"),
),
},
},
})
}

func testAccCheckIBMContainerVPCClusterWorkerPoolDataSourceConfig(flavor string, worker_count, name1, name2 int) string {
return testAccCheckIBMVpcContainerWorkerPool_basic(flavor, worker_count, name1, name2) + fmt.Sprintf(`
data "ibm_container_vpc_cluster_worker_pool" "testacc_ds_worker_pool" {
cluster = "${ibm_container_vpc_cluster.cluster.id}"
worker_pool_name = "${ibm_container_vpc_worker_pool.test_pool.worker_pool_name}"
}
`)
}
153 changes: 77 additions & 76 deletions ibm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,82 +154,83 @@ func Provider() terraform.ResourceProvider {
},

DataSourcesMap: map[string]*schema.Resource{
"ibm_api_gateway": dataSourceIBMApiGateway(),
"ibm_account": dataSourceIBMAccount(),
"ibm_app": dataSourceIBMApp(),
"ibm_app_domain_private": dataSourceIBMAppDomainPrivate(),
"ibm_app_domain_shared": dataSourceIBMAppDomainShared(),
"ibm_app_route": dataSourceIBMAppRoute(),
"ibm_function_action": dataSourceIBMFunctionAction(),
"ibm_function_package": dataSourceIBMFunctionPackage(),
"ibm_function_rule": dataSourceIBMFunctionRule(),
"ibm_function_trigger": dataSourceIBMFunctionTrigger(),
"ibm_certificate_manager_certificates": dataIBMCertificateManagerCertificates(),
"ibm_certificate_manager_certificate": dataIBMCertificateManagerCertificate(),
"ibm_cis": dataSourceIBMCISInstance(),
"ibm_cis_domain": dataSourceIBMCISDomain(),
"ibm_cis_firewall": dataIBMCISFirewallRecord(),
"ibm_cis_rate_limit": dataSourceIBMCISRateLimit(),
"ibm_cis_ip_addresses": dataSourceIBMCISIP(),
"ibm_database": dataSourceIBMDatabaseInstance(),
"ibm_compute_bare_metal": dataSourceIBMComputeBareMetal(),
"ibm_compute_image_template": dataSourceIBMComputeImageTemplate(),
"ibm_compute_placement_group": dataSourceIBMComputePlacementGroup(),
"ibm_compute_ssh_key": dataSourceIBMComputeSSHKey(),
"ibm_compute_vm_instance": dataSourceIBMComputeVmInstance(),
"ibm_container_cluster": dataSourceIBMContainerCluster(),
"ibm_container_cluster_config": dataSourceIBMContainerClusterConfig(),
"ibm_container_cluster_versions": dataSourceIBMContainerClusterVersions(),
"ibm_container_cluster_worker": dataSourceIBMContainerClusterWorker(),
"ibm_container_vpc_cluster_alb": dataSourceIBMContainerVPCClusterALB(),
"ibm_container_vpc_cluster": dataSourceIBMContainerVPCCluster(),
"ibm_container_vpc_cluster_worker": dataSourceIBMContainerVPCClusterWorker(),
"ibm_container_worker_pool": dataSourceIBMContainerWorkerPool(),
"ibm_cos_bucket": dataSourceIBMCosBucket(),
"ibm_dns_domain_registration": dataSourceIBMDNSDomainRegistration(),
"ibm_dns_domain": dataSourceIBMDNSDomain(),
"ibm_dns_secondary": dataSourceIBMDNSSecondary(),
"ibm_iam_access_group": dataSourceIBMIAMAccessGroup(),
"ibm_iam_auth_token": dataSourceIBMIAMAuthToken(),
"ibm_iam_role_actions": datasourceIBMIAMRoleAction(),
"ibm_iam_users": dataSourceIBMIAMUsers(),
"ibm_iam_roles": datasourceIBMIAMRole(),
"ibm_iam_user_policy": dataSourceIBMIAMUserPolicy(),
"ibm_iam_user_profile": dataSourceIBMIAMUserProfile(),
"ibm_iam_service_id": dataSourceIBMIAMServiceID(),
"ibm_iam_service_policy": dataSourceIBMIAMServicePolicy(),
"ibm_is_image": dataSourceIBMISImage(),
"ibm_is_images": dataSourceIBMISImages(),
"ibm_is_instance_profile": dataSourceIBMISInstanceProfile(),
"ibm_is_instance_profiles": dataSourceIBMISInstanceProfiles(),
"ibm_is_instance": dataSourceIBMISInstance(),
"ibm_is_instances": dataSourceIBMISInstances(),
"ibm_is_region": dataSourceIBMISRegion(),
"ibm_is_ssh_key": dataSourceIBMISSSHKey(),
"ibm_is_subnet": dataSourceIBMISSubnet(),
"ibm_is_subnets": dataSourceIBMISSubnets(),
"ibm_is_security_group": dataSourceIBMISSecurityGroup(),
"ibm_is_vpc": dataSourceIBMISVPC(),
"ibm_is_zone": dataSourceIBMISZone(),
"ibm_is_zones": dataSourceIBMISZones(),
"ibm_lbaas": dataSourceIBMLbaas(),
"ibm_network_vlan": dataSourceIBMNetworkVlan(),
"ibm_org": dataSourceIBMOrg(),
"ibm_org_quota": dataSourceIBMOrgQuota(),
"ibm_kp_key": dataSourceIBMkey(),
"ibm_kms_keys": dataSourceIBMKMSkeys(),
"ibm_resource_quota": dataSourceIBMResourceQuota(),
"ibm_resource_group": dataSourceIBMResourceGroup(),
"ibm_resource_instance": dataSourceIBMResourceInstance(),
"ibm_resource_key": dataSourceIBMResourceKey(),
"ibm_security_group": dataSourceIBMSecurityGroup(),
"ibm_service_instance": dataSourceIBMServiceInstance(),
"ibm_service_key": dataSourceIBMServiceKey(),
"ibm_service_plan": dataSourceIBMServicePlan(),
"ibm_space": dataSourceIBMSpace(),
"ibm_schematics_workspace": dataSourceSchematicsWorkspace(),
"ibm_schematics_output": dataSourceSchematicsOut(),
"ibm_schematics_state": dataSourceSchematicsState(),
"ibm_api_gateway": dataSourceIBMApiGateway(),
"ibm_account": dataSourceIBMAccount(),
"ibm_app": dataSourceIBMApp(),
"ibm_app_domain_private": dataSourceIBMAppDomainPrivate(),
"ibm_app_domain_shared": dataSourceIBMAppDomainShared(),
"ibm_app_route": dataSourceIBMAppRoute(),
"ibm_function_action": dataSourceIBMFunctionAction(),
"ibm_function_package": dataSourceIBMFunctionPackage(),
"ibm_function_rule": dataSourceIBMFunctionRule(),
"ibm_function_trigger": dataSourceIBMFunctionTrigger(),
"ibm_certificate_manager_certificates": dataIBMCertificateManagerCertificates(),
"ibm_certificate_manager_certificate": dataIBMCertificateManagerCertificate(),
"ibm_cis": dataSourceIBMCISInstance(),
"ibm_cis_domain": dataSourceIBMCISDomain(),
"ibm_cis_firewall": dataIBMCISFirewallRecord(),
"ibm_cis_rate_limit": dataSourceIBMCISRateLimit(),
"ibm_cis_ip_addresses": dataSourceIBMCISIP(),
"ibm_database": dataSourceIBMDatabaseInstance(),
"ibm_compute_bare_metal": dataSourceIBMComputeBareMetal(),
"ibm_compute_image_template": dataSourceIBMComputeImageTemplate(),
"ibm_compute_placement_group": dataSourceIBMComputePlacementGroup(),
"ibm_compute_ssh_key": dataSourceIBMComputeSSHKey(),
"ibm_compute_vm_instance": dataSourceIBMComputeVmInstance(),
"ibm_container_cluster": dataSourceIBMContainerCluster(),
"ibm_container_cluster_config": dataSourceIBMContainerClusterConfig(),
"ibm_container_cluster_versions": dataSourceIBMContainerClusterVersions(),
"ibm_container_cluster_worker": dataSourceIBMContainerClusterWorker(),
"ibm_container_vpc_cluster_alb": dataSourceIBMContainerVPCClusterALB(),
"ibm_container_vpc_cluster": dataSourceIBMContainerVPCCluster(),
"ibm_container_vpc_cluster_worker": dataSourceIBMContainerVPCClusterWorker(),
"ibm_container_vpc_cluster_worker_pool": dataSourceIBMContainerVpcClusterWorkerPool(),
"ibm_container_worker_pool": dataSourceIBMContainerWorkerPool(),
"ibm_cos_bucket": dataSourceIBMCosBucket(),
"ibm_dns_domain_registration": dataSourceIBMDNSDomainRegistration(),
"ibm_dns_domain": dataSourceIBMDNSDomain(),
"ibm_dns_secondary": dataSourceIBMDNSSecondary(),
"ibm_iam_access_group": dataSourceIBMIAMAccessGroup(),
"ibm_iam_auth_token": dataSourceIBMIAMAuthToken(),
"ibm_iam_role_actions": datasourceIBMIAMRoleAction(),
"ibm_iam_users": dataSourceIBMIAMUsers(),
"ibm_iam_roles": datasourceIBMIAMRole(),
"ibm_iam_user_policy": dataSourceIBMIAMUserPolicy(),
"ibm_iam_user_profile": dataSourceIBMIAMUserProfile(),
"ibm_iam_service_id": dataSourceIBMIAMServiceID(),
"ibm_iam_service_policy": dataSourceIBMIAMServicePolicy(),
"ibm_is_image": dataSourceIBMISImage(),
"ibm_is_images": dataSourceIBMISImages(),
"ibm_is_instance_profile": dataSourceIBMISInstanceProfile(),
"ibm_is_instance_profiles": dataSourceIBMISInstanceProfiles(),
"ibm_is_instance": dataSourceIBMISInstance(),
"ibm_is_instances": dataSourceIBMISInstances(),
"ibm_is_region": dataSourceIBMISRegion(),
"ibm_is_ssh_key": dataSourceIBMISSSHKey(),
"ibm_is_subnet": dataSourceIBMISSubnet(),
"ibm_is_subnets": dataSourceIBMISSubnets(),
"ibm_is_security_group": dataSourceIBMISSecurityGroup(),
"ibm_is_vpc": dataSourceIBMISVPC(),
"ibm_is_zone": dataSourceIBMISZone(),
"ibm_is_zones": dataSourceIBMISZones(),
"ibm_lbaas": dataSourceIBMLbaas(),
"ibm_network_vlan": dataSourceIBMNetworkVlan(),
"ibm_org": dataSourceIBMOrg(),
"ibm_org_quota": dataSourceIBMOrgQuota(),
"ibm_kp_key": dataSourceIBMkey(),
"ibm_kms_keys": dataSourceIBMKMSkeys(),
"ibm_resource_quota": dataSourceIBMResourceQuota(),
"ibm_resource_group": dataSourceIBMResourceGroup(),
"ibm_resource_instance": dataSourceIBMResourceInstance(),
"ibm_resource_key": dataSourceIBMResourceKey(),
"ibm_security_group": dataSourceIBMSecurityGroup(),
"ibm_service_instance": dataSourceIBMServiceInstance(),
"ibm_service_key": dataSourceIBMServiceKey(),
"ibm_service_plan": dataSourceIBMServicePlan(),
"ibm_space": dataSourceIBMSpace(),
"ibm_schematics_workspace": dataSourceSchematicsWorkspace(),
"ibm_schematics_output": dataSourceSchematicsOut(),
"ibm_schematics_state": dataSourceSchematicsState(),

// Added for Power Resources

Expand Down
2 changes: 1 addition & 1 deletion ibm/resource_ibm_container_vpc_worker_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func testAccCheckIBMVpcContainerWorkerPool_basic(flavor string, worker_count, na
flavor = "%s"
worker_count = "%d"
resource_group_id = "${data.ibm_resource_group.resource_group.id}"
wait_till = "oneWorkerNodeReady"
zones {
subnet_id = "${ibm_is_subnet.subnet1.id}"
name = "${local.ZONE1}"
Expand Down
46 changes: 46 additions & 0 deletions website/docs/d/container_vpc_cluster_worker_pool.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
layout: "ibm"
page_title: "IBM: container_vpc_cluster_worker_pool"
sidebar_current: "docs-ibm-datasource-container-vpc-cluster-worker-pool"
description: |-
Get information about a Kubernetes container vpc worker pool.
---

# ibm\_container_vpc_worker_pool

Import the details of a Kubernetes cluster worker pool on IBM Cloud as a read-only data source. You can then reference the fields of the data source in other resources within the same configuration using interpolation syntax.

## Example Usage

In the following example, you can create a worker pool for a vpc cluster:

```hcl
data "ibm_container_vpc_cluster_worker_pool" "testacc_ds_worker_pool" {
cluster = "cluster_name"
worker_pool_name = i"worker_pool_name
}
```


## Argument Reference

The following arguments are supported:

* `worker_pool_name` - (Required, string) The name of the worker pool.
* `cluster` - (Required, string) The name or id of the cluster.

## Attribute Reference

The following attributes are exported:

* `id` - The unique identifier of the worker pool resource. The id is composed of \<cluster_name_id\>/\<worker_pool_id\>.<br/>
* `vpc_id` - The Id of VPC
* `worker_count` - The number of worker nodes per zone in the worker pool.
* `flavor` - The flavour of the worker node.
* `zones` - A nested block describing the zones of this worker_pool. Nested zones blocks have the following structure:
* `subnet-id` - The worker pool subnet to assign the cluster.
* `name` - Name of the zone.
* `labels` - Labels on all the workers in the worker pool.
* `resource_group_id` - The ID of the resource group.
* `provider` - Provider Details of the worker Pool.
* `isolation` - Isolation for the worker node
3 changes: 3 additions & 0 deletions website/ibm.erb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
<li<%= sidebar_current("docs-ibm-datasource-container-vpc-cluster-worker") %>>
<a href="/docs/providers/ibm/d/container_vpc_cluster_worker.html">container_vpc_cluster_worker</a>
</li>
<li<%= sidebar_current("docs-ibm-datasource-container-vpc-cluster-worker-pool") %>>
<a href="/docs/providers/ibm/d/container_vpc_cluster_worker_pool.html">container_vpc_cluster_worker_pool</a>
</li>
</ul>
</li>
<li<%= sidebar_current("docs-ibm-datasource-database") %>>
Expand Down