From 5c3d3b99846400d2cba93dfa961a43a94078afd1 Mon Sep 17 00:00:00 2001 From: "hkantare@in.ibm.com" Date: Wed, 30 Oct 2019 18:46:05 +0530 Subject: [PATCH] Fix VPC cluster example and docs --- .../ibm-cluster/vpc-classic-cluster/README.md | 1 + .../ibm-cluster/vpc-classic-cluster/main.tf | 85 +++++++++++++------ .../vpc-classic-cluster/variables.tf | 30 ++++--- .../d/container_vpc_cluster.html.markdown | 6 +- ...container_vpc_cluster_worker.html.markdown | 31 +++---- 5 files changed, 89 insertions(+), 64 deletions(-) diff --git a/examples/ibm-cluster/vpc-classic-cluster/README.md b/examples/ibm-cluster/vpc-classic-cluster/README.md index bf2cd20a99..f8ff3d7114 100644 --- a/examples/ibm-cluster/vpc-classic-cluster/README.md +++ b/examples/ibm-cluster/vpc-classic-cluster/README.md @@ -2,6 +2,7 @@ This example shows how to create a Kubernetes VPC Cluster under a specified resource group id, with default worker node with given zone and subnets. To have a multizone cluster, update the zones with new zone-name and subnet-id. +It also creates a additional worker pool on different zone. After successfull creation of cluster it binds the cloud-object-storage service. To run, configure your IBM Cloud provider Running the example diff --git a/examples/ibm-cluster/vpc-classic-cluster/main.tf b/examples/ibm-cluster/vpc-classic-cluster/main.tf index ec8e7341b3..70cc6e41f8 100644 --- a/examples/ibm-cluster/vpc-classic-cluster/main.tf +++ b/examples/ibm-cluster/vpc-classic-cluster/main.tf @@ -1,55 +1,86 @@ -provider "ibm" {} +provider "ibm" { + generation = 1 +} + +resource "random_id" "name1" { + byte_length = 2 +} + +resource "random_id" "name2" { + byte_length = 2 +} + +locals { + ZONE1 = "${var.region}-1" + ZONE2 = "${var.region}-2" +} -data "ibm_org" "org" { - org = "${var.org}" +resource "ibm_is_vpc" "vpc1" { + name = "vpc-${random_id.name1.hex}" } -data "ibm_space" "space" { - org = "${var.org}" - space = "${var.space}" +resource "ibm_is_subnet" "subnet1" { + name = "subnet-${random_id.name1.hex}" + vpc = "${ibm_is_vpc.vpc1.id}" + zone = "${local.ZONE1}" + total_ipv4_address_count = 256 +} + +resource "ibm_is_subnet" "subnet2" { + name = "subnet-${random_id.name2.hex}" + vpc = "${ibm_is_vpc.vpc1.id}" + zone = "${local.ZONE2}" + total_ipv4_address_count = 256 } data "ibm_resource_group" "resource_group" { - name = "Default" + name = "${var.resource_group}" } resource "ibm_container_vpc_cluster" "cluster" { - name = "${var.cluster_name}${random_id.name.hex}" - vpc_id = "${var.vpc_id}" + name = "${var.cluster_name}${random_id.name1.hex}" + vpc_id = "${ibm_is_vpc.vpc1.id}" flavor = "${var.flavor}" worker_count = "${var.worker_count}" resource_group_id = "${data.ibm_resource_group.resource_group.id}" + zones = [ - { - subnet_id = "${var.subnet_id}" - name = "${var.zone_name}" - } + { + subnet_id = "${ibm_is_subnet.subnet1.id}" + name = "${local.ZONE1}" + }, ] } -resource "ibm_service_instance" "service" { - name = "${var.service_instance_name}${random_id.name.hex}" - space_guid = "${data.ibm_space.space.id}" - service = "${var.service_offering}" - plan = "${var.plan}" - tags = ["my-service"] +resource "ibm_container_vpc_worker_pool" "cluster_pool" { + cluster = "${ibm_container_vpc_cluster.cluster.id}" + worker_pool_name = "${var.worker_pool_name}${random_id.name1.hex}" + flavor = "${var.flavor}" + vpc_id = "${ibm_is_vpc.vpc1.id}" + worker_count = "${var.worker_count}" + resource_group_id = "${data.ibm_resource_group.resource_group.id}" + zones = [ + { + name = "${local.ZONE2}" + subnet_id = "${ibm_is_subnet.subnet2.id}" + }, + ] } -resource "ibm_service_key" "key" { - name = "${var.service_key}" - service_instance_guid = "${ibm_service_instance.service.id}" +resource "ibm_resource_instance" "cos_instance" { + name = "${var.service_instance_name}" + service = "cloud-object-storage" + plan = "standard" + location = "global" } resource "ibm_container_bind_service" "bind_service" { cluster_name_id = "${ibm_container_vpc_cluster.cluster.id}" - service_instance_id = "${ibm_service_instance.service.id}" + service_instance_id = "${element(split(":",ibm_resource_instance.cos_instance.id),7)}" namespace_id = "default" + role = "Writer" } data "ibm_container_cluster_config" "cluster_config" { cluster_name_id = "${ibm_container_vpc_cluster.cluster.id}" } - -resource "random_id" "name" { - byte_length = 4 -} diff --git a/examples/ibm-cluster/vpc-classic-cluster/variables.tf b/examples/ibm-cluster/vpc-classic-cluster/variables.tf index 619ccd3720..76818b28fc 100644 --- a/examples/ibm-cluster/vpc-classic-cluster/variables.tf +++ b/examples/ibm-cluster/vpc-classic-cluster/variables.tf @@ -1,27 +1,29 @@ -variable "org" {} - -variable "space"{} - -variable "subnet_id" {} - -variable "vpc_id" {} +variable "flavor" { + default = "c2.2x4" +} -variable "flavor" {} +variable "worker_count" { + default = "1" +} -variable "worker_count" {} +variable "region" { + default = "us-south" +} -variable "zone_name" {} +variable "resource_group" { + default = "default" +} variable "cluster_name" { default = "cluster" } -variable "service_instance_name" { - default = "myservice" +variable "worker_pool_name" { + default = "workerpool" } -variable "service_key" { - default = "myservicekey" +variable "service_instance_name" { + default = "myservice" } variable "service_offering" { diff --git a/website/docs/d/container_vpc_cluster.html.markdown b/website/docs/d/container_vpc_cluster.html.markdown index fb572178c1..19fa92103b 100644 --- a/website/docs/d/container_vpc_cluster.html.markdown +++ b/website/docs/d/container_vpc_cluster.html.markdown @@ -11,21 +11,19 @@ description: |- Import the details of a Kubernetes VPC cluster on IBM Cloud as a read-only data source. ​ ## Example Usage -​ -​ -``` +```hcl data "ibm_container_vpc_cluster" "cluster" { ​ cluster_name_id = "no-zones-tf" resource_group_id = "${data.ibm_resource_group.group.id}" ​ } -​ ``` ​ ## Argument Reference ​ The following arguments are supported: + * `cluster_name_id` - (Required, string) Name of the Cluster * `resource_group_id` - (Optional, string) The ID of the resource group. You can retrieve the value from data source `ibm_resource_group`. If not provided defaults to default resource group. * `alb_type` - (Optional, string) ALB type of a Cluster diff --git a/website/docs/d/container_vpc_cluster_worker.html.markdown b/website/docs/d/container_vpc_cluster_worker.html.markdown index 6b1e99045c..25fc90dbb3 100644 --- a/website/docs/d/container_vpc_cluster_worker.html.markdown +++ b/website/docs/d/container_vpc_cluster_worker.html.markdown @@ -6,43 +6,36 @@ description: |- Manages IBM VPC container cluster worker. --- ​ -# ibm\_container_vpc_cluster +# ibm\_container_vpc_cluster_worker ​ Import details of a worker node of a Kubernetes VPC cluster as a read-only data source. -​ -​ + ## Example Usage -​ -​ ```hcl data "ibm_container_cluster_worker" "worker_foo" { - worker_id = "dev-mex10-pa70c4414695c041518603bfd0cd6e333a-w1" + worker_id = "dev-mex10-pa70c4414695c041518603bfd0cd6e333a-w1" cluster_name_id = "test" } -​ ``` -​ + ## Argument Reference -​ -The following arguments are supported: -​ + +The following arguments are supported: + * `worker_id` - (Required, string) The name of the worker pool. * `cluster_name_id` - (Required, string) The name or id of the cluster. * `flavor` - (Required, string) The flavour of the worker node. * `kube_version` - (Required, string) The Kubernetes version, including at least the major.minor version.To see available versions, run 'ibmcloud ks versions'. * `resource_group_id` - (Optional, string) The ID of the resource group. You can retrieve the value from data source `ibm_resource_group`. If not provided defaults to default resource group. -​ -​ -​ -​ + ## Attribute Reference ​ The following attributes are exported: -​ + * `State` - State of worker. * `pool_id` - Id of Worker pool. * `pool_name`- Name of the worker pool * `network_interfaces`- Network Interface of the cluster - * `cidr`- cidr of the network - * `ip_address`- Ip Address of the worker pool - * `subnet_id`- The worker pool subnet id to assign the cluster. \ No newline at end of file + * `cidr`- cidr of the network + * `ip_address`- Ip Address of the worker pool + * `subnet_id`- The worker pool subnet id to assign the cluster. \ No newline at end of file