From 93b532bbb3f21fd6391f7dd3c20d6f950d11cac5 Mon Sep 17 00:00:00 2001 From: Axel Ismirlian Date: Fri, 15 Dec 2023 14:14:29 -0600 Subject: [PATCH 1/4] Update powervs terraform example with workspace creation --- examples/ibm-power/main.tf | 77 +++++++++++++------- examples/ibm-power/variables.tf | 124 +++++++++++++++++++------------- examples/ibm-power/versions.tf | 7 +- 3 files changed, 131 insertions(+), 77 deletions(-) diff --git a/examples/ibm-power/main.tf b/examples/ibm-power/main.tf index bf6c35f70e..4c2ba12bc4 100644 --- a/examples/ibm-power/main.tf +++ b/examples/ibm-power/main.tf @@ -1,31 +1,42 @@ -data "ibm_pi_image" "data_source_image" { - pi_cloud_instance_id = var.cloud_instance_id - pi_image_name = var.image_name +# Create a workspace +resource "ibm_pi_workspace" "powervs_service_instance" { + pi_name = var.workspace_name + pi_datacenter = var.datacenter + pi_resource_group_id = var.resource_group_id + pi_plan = "public" } -resource "ibm_pi_key" "key" { - pi_cloud_instance_id = var.cloud_instance_id - pi_key_name = var.ssh_key_name - pi_ssh_key = var.ssh_key_rsa + +# Create an image +resource "ibm_pi_image" "image" { + pi_cloud_instance_id = ibm_pi_workspace.powervs_service_instance.id + pi_image_name = var.image_name + pi_image_id = var.image_id } -data "ibm_pi_key" "data_source_key" { - depends_on = [ibm_pi_key.key] +data "ibm_pi_image" "data_source_image" { + depends_on = [ibm_pi_image.image] - pi_cloud_instance_id = var.cloud_instance_id - pi_key_name = var.ssh_key_name + pi_cloud_instance_id = ibm_pi_workspace.powervs_service_instance.id + pi_image_name = var.image_name } -resource "ibm_pi_network" "network" { - pi_cloud_instance_id = var.cloud_instance_id + +# Create a network +resource "ibm_pi_network" "private_network" { + pi_cloud_instance_id = ibm_pi_workspace.powervs_service_instance.id pi_network_name = var.network_name pi_network_type = var.network_type - count = var.network_count + pi_cidr = var.network_cidr + pi_dns = [var.network_dns] } -data "ibm_pi_public_network" "data_source_network" { - depends_on = [ibm_pi_network.network] +data "ibm_pi_network" "data_source_private_network" { + depends_on = [ibm_pi_network.private_network] - pi_cloud_instance_id = var.cloud_instance_id + pi_cloud_instance_id = ibm_pi_workspace.powervs_service_instance.id + pi_network_name = var.network_name } + +# Create a volume resource "ibm_pi_volume" "volume" { - pi_cloud_instance_id = var.cloud_instance_id + pi_cloud_instance_id = ibm_pi_workspace.powervs_service_instance.id pi_volume_name = var.volume_name pi_volume_type = var.volume_type pi_volume_size = var.volume_size @@ -34,16 +45,18 @@ resource "ibm_pi_volume" "volume" { data "ibm_pi_volume" "data_source_volume" { depends_on = [ibm_pi_volume.volume] - pi_cloud_instance_id = var.cloud_instance_id + pi_cloud_instance_id = ibm_pi_workspace.powervs_service_instance.id pi_volume_name = var.volume_name } + +# Create an instance resource "ibm_pi_instance" "instance" { depends_on = [data.ibm_pi_image.data_source_image, data.ibm_pi_key.data_source_key, data.ibm_pi_volume.data_source_volume, - data.ibm_pi_public_network.data_source_network] + data.ibm_pi_network.data_source_private_network] - pi_cloud_instance_id = var.cloud_instance_id + pi_cloud_instance_id = ibm_pi_workspace.powervs_service_instance.id pi_instance_name = var.instance_name pi_memory = var.memory pi_processors = var.processors @@ -52,13 +65,27 @@ resource "ibm_pi_instance" "instance" { pi_sys_type = var.sys_type pi_image_id = data.ibm_pi_image.data_source_image.id pi_key_pair_name = data.ibm_pi_key.data_source_key.id - pi_network { network_id = data.ibm_pi_public_network.data_source_network.id } + pi_network { + network_id = data.ibm_pi_network.data_source_private_network.id + } pi_volume_ids = [data.ibm_pi_volume.data_source_volume.id] } - data "ibm_pi_instance" "data_source_instance" { depends_on = [ibm_pi_instance.instance] - pi_cloud_instance_id = var.cloud_instance_id + pi_cloud_instance_id = ibm_pi_workspace.powervs_service_instance.id pi_instance_name = var.instance_name -} \ No newline at end of file +} + +# Create an ssh key +resource "ibm_pi_key" "key" { + pi_cloud_instance_id = ibm_pi_workspace.powervs_service_instance.id + pi_key_name = var.ssh_key_name + pi_ssh_key = var.ssh_key_rsa +} +data "ibm_pi_key" "data_source_key" { + depends_on = [ibm_pi_key.key] + + pi_cloud_instance_id = ibm_pi_workspace.powervs_service_instance.id + pi_key_name = var.ssh_key_name +} diff --git a/examples/ibm-power/variables.tf b/examples/ibm-power/variables.tf index b3d9adc292..3cff9896be 100644 --- a/examples/ibm-power/variables.tf +++ b/examples/ibm-power/variables.tf @@ -1,33 +1,94 @@ -// Service / Account +# Service // Account variable "ibm_cloud_api_key" { description = "API Key" type = string default = "" } variable "region" { - description = "Reigon of Service" + description = "Region of Service" type = string default = "" } variable "zone" { description = "Zone of Service" type = string - default = "" + default = "" } -variable "cloud_instance_id" { - description = "Cloud Instance ID of Service" - type = string - default = "" + +# Workspace +variable "workspace_name" { + description = "Workspace Name" + type = string + default = "" +} +variable "datacenter" { + description = "Datacenter Region" + type = string + default = "" +} +variable "resource_group_id" { + description = "Resource Group ID" + type = string + default = "" } -// Image +# Image variable "image_name" { - description = "Name of the image to be used" + description = "Name of the image in the image catalog" + type = string + default = "" +} +variable "image_id" { + description = "ID of the image in the image catalog" + type = string + default = "" +} + +# Private Network +variable "network_name" { + description = "Name of the network" type = string default = "" } +variable "network_type" { + description = "Type of a network" + type = string + default = "vlan" +} +variable "network_cidr" { + description = "Network in CIDR notation" + type = string + default = "" +} +variable "network_dns" { + description = "Comma seaparated list of DNS Servers to use for this network" + type = string + default = "" +} -// Instance +# Volume +variable "volume_name" { + description = "Name of the volume" + type = string + default = "" +} +variable "volume_size" { + description = "Size of a volume" + type = number + default = 1 +} +variable "volume_shareable" { + description = "Is a volume shareable" + type = bool + default = true +} +variable "volume_type" { + description = "Type of a volume" + type = string + default = "" +} + +# Instance variable "instance_name" { description = "Name of the instance" type = string @@ -51,7 +112,7 @@ variable "proc_type" { variable "storage_type" { description = "The storage type to be used" type = string - default = "" + default = "" } variable "sys_type" { description = "Instance System Type" @@ -59,7 +120,7 @@ variable "sys_type" { default = "" } -// SSH Key +# SSH Key variable "ssh_key_name" { description = "Name of the ssh key to be used" type = string @@ -70,42 +131,3 @@ variable "ssh_key_rsa" { type = string default = "" } - -// Network -variable "network_name" { - description = "Name of the network" - type = string - default = "" -} -variable "network_type" { - description = "Type of a network" - type = string - default = "" -} -variable "network_count" { - description = "Number of networks to provision" - type = number - default = 1 -} - -// Volume -variable "volume_name" { - description = "Name of the volume" - type = string - default = "" -} -variable "volume_size" { - description = "Size of a volume" - type = number - default = 0.25 -} -variable "volume_shareable" { - description = "Is a volume shareable" - type = bool - default = true -} -variable "volume_type" { - description = "Type of a volume" - type = string - default = "" -} \ No newline at end of file diff --git a/examples/ibm-power/versions.tf b/examples/ibm-power/versions.tf index 0b29488aaf..fa0e2e114c 100644 --- a/examples/ibm-power/versions.tf +++ b/examples/ibm-power/versions.tf @@ -1,7 +1,12 @@ +terraform { + required_version = ">= 0.13" +} + terraform { required_providers { ibm = { source = "IBM-Cloud/ibm" + version = "" } } -} \ No newline at end of file +} From cecd3f819ccce8cb7ce4bf1aac63b8d9b2225ade Mon Sep 17 00:00:00 2001 From: Axel Ismirlian Date: Fri, 15 Dec 2023 14:59:30 -0600 Subject: [PATCH 2/4] Update workspace creation construct --- examples/ibm-power/main.tf | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/examples/ibm-power/main.tf b/examples/ibm-power/main.tf index 4c2ba12bc4..fad18e6b67 100644 --- a/examples/ibm-power/main.tf +++ b/examples/ibm-power/main.tf @@ -1,27 +1,28 @@ # Create a workspace -resource "ibm_pi_workspace" "powervs_service_instance" { - pi_name = var.workspace_name - pi_datacenter = var.datacenter - pi_resource_group_id = var.resource_group_id - pi_plan = "public" +resource "ibm_resource_instance" "location" { + name = var.workspace_name + resource_group_id = var.resource_group_id + location = var.datacenter + service = "power-iaas" + plan = "power-virtual-server-group" } # Create an image resource "ibm_pi_image" "image" { - pi_cloud_instance_id = ibm_pi_workspace.powervs_service_instance.id + pi_cloud_instance_id = ibm_resource_instance.location.guid pi_image_name = var.image_name pi_image_id = var.image_id } data "ibm_pi_image" "data_source_image" { depends_on = [ibm_pi_image.image] - pi_cloud_instance_id = ibm_pi_workspace.powervs_service_instance.id + pi_cloud_instance_id = ibm_resource_instance.location.guid pi_image_name = var.image_name } # Create a network resource "ibm_pi_network" "private_network" { - pi_cloud_instance_id = ibm_pi_workspace.powervs_service_instance.id + pi_cloud_instance_id = ibm_resource_instance.location.guid pi_network_name = var.network_name pi_network_type = var.network_type pi_cidr = var.network_cidr @@ -30,13 +31,13 @@ resource "ibm_pi_network" "private_network" { data "ibm_pi_network" "data_source_private_network" { depends_on = [ibm_pi_network.private_network] - pi_cloud_instance_id = ibm_pi_workspace.powervs_service_instance.id + pi_cloud_instance_id = ibm_resource_instance.location.guid pi_network_name = var.network_name } # Create a volume resource "ibm_pi_volume" "volume" { - pi_cloud_instance_id = ibm_pi_workspace.powervs_service_instance.id + pi_cloud_instance_id = ibm_resource_instance.location.guid pi_volume_name = var.volume_name pi_volume_type = var.volume_type pi_volume_size = var.volume_size @@ -45,7 +46,7 @@ resource "ibm_pi_volume" "volume" { data "ibm_pi_volume" "data_source_volume" { depends_on = [ibm_pi_volume.volume] - pi_cloud_instance_id = ibm_pi_workspace.powervs_service_instance.id + pi_cloud_instance_id = ibm_resource_instance.location.guid pi_volume_name = var.volume_name } @@ -56,7 +57,7 @@ resource "ibm_pi_instance" "instance" { data.ibm_pi_volume.data_source_volume, data.ibm_pi_network.data_source_private_network] - pi_cloud_instance_id = ibm_pi_workspace.powervs_service_instance.id + pi_cloud_instance_id = ibm_resource_instance.location.guid pi_instance_name = var.instance_name pi_memory = var.memory pi_processors = var.processors @@ -73,19 +74,19 @@ resource "ibm_pi_instance" "instance" { data "ibm_pi_instance" "data_source_instance" { depends_on = [ibm_pi_instance.instance] - pi_cloud_instance_id = ibm_pi_workspace.powervs_service_instance.id + pi_cloud_instance_id = ibm_resource_instance.location.guid pi_instance_name = var.instance_name } # Create an ssh key resource "ibm_pi_key" "key" { - pi_cloud_instance_id = ibm_pi_workspace.powervs_service_instance.id + pi_cloud_instance_id = ibm_resource_instance.location.guid pi_key_name = var.ssh_key_name pi_ssh_key = var.ssh_key_rsa } data "ibm_pi_key" "data_source_key" { depends_on = [ibm_pi_key.key] - pi_cloud_instance_id = ibm_pi_workspace.powervs_service_instance.id + pi_cloud_instance_id = ibm_resource_instance.location.guid pi_key_name = var.ssh_key_name } From b4cb7c893652a3da1abe0215180386d285fe4091 Mon Sep 17 00:00:00 2001 From: Axel Ismirlian Date: Mon, 18 Dec 2023 13:51:57 -0600 Subject: [PATCH 3/4] Update datacenter location comment --- examples/ibm-power/variables.tf | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/examples/ibm-power/variables.tf b/examples/ibm-power/variables.tf index 3cff9896be..63c23eb52b 100644 --- a/examples/ibm-power/variables.tf +++ b/examples/ibm-power/variables.tf @@ -1,4 +1,4 @@ -# Service // Account +## Service // Account variable "ibm_cloud_api_key" { description = "API Key" type = string @@ -15,12 +15,13 @@ variable "zone" { default = "" } -# Workspace +## Workspace variable "workspace_name" { description = "Workspace Name" type = string default = "" } +# See available datacenter regions at: https://cloud.ibm.com/apidocs/power-cloud#endpoint variable "datacenter" { description = "Datacenter Region" type = string @@ -32,7 +33,7 @@ variable "resource_group_id" { default = "" } -# Image +## Image variable "image_name" { description = "Name of the image in the image catalog" type = string @@ -44,7 +45,7 @@ variable "image_id" { default = "" } -# Private Network +## Private Network variable "network_name" { description = "Name of the network" type = string @@ -66,7 +67,7 @@ variable "network_dns" { default = "" } -# Volume +## Volume variable "volume_name" { description = "Name of the volume" type = string @@ -88,7 +89,7 @@ variable "volume_type" { default = "" } -# Instance +## Instance variable "instance_name" { description = "Name of the instance" type = string @@ -120,7 +121,7 @@ variable "sys_type" { default = "" } -# SSH Key +## SSH Key variable "ssh_key_name" { description = "Name of the ssh key to be used" type = string From e45ab10c16a98595bf28e0a0ec8b512e6abd797a Mon Sep 17 00:00:00 2001 From: Axel Ismirlian Date: Fri, 5 Jan 2024 10:02:34 -0600 Subject: [PATCH 4/4] Remove explicit depends on text from example --- examples/ibm-power/main.tf | 44 +++++++++++---------------------- examples/ibm-power/variables.tf | 24 +++++++++--------- 2 files changed, 27 insertions(+), 41 deletions(-) diff --git a/examples/ibm-power/main.tf b/examples/ibm-power/main.tf index fad18e6b67..bc34f2c8f6 100644 --- a/examples/ibm-power/main.tf +++ b/examples/ibm-power/main.tf @@ -14,10 +14,8 @@ resource "ibm_pi_image" "image" { pi_image_id = var.image_id } data "ibm_pi_image" "data_source_image" { - depends_on = [ibm_pi_image.image] - pi_cloud_instance_id = ibm_resource_instance.location.guid - pi_image_name = var.image_name + pi_image_name = resource.ibm_pi_image.image.pi_image_name } # Create a network @@ -27,12 +25,11 @@ resource "ibm_pi_network" "private_network" { pi_network_type = var.network_type pi_cidr = var.network_cidr pi_dns = [var.network_dns] + pi_network_mtu = 2000 } data "ibm_pi_network" "data_source_private_network" { - depends_on = [ibm_pi_network.private_network] - pi_cloud_instance_id = ibm_resource_instance.location.guid - pi_network_name = var.network_name + pi_network_name = resource.ibm_pi_network.private_network.pi_network_name } # Create a volume @@ -44,19 +41,23 @@ resource "ibm_pi_volume" "volume" { pi_volume_shareable = var.volume_shareable } data "ibm_pi_volume" "data_source_volume" { - depends_on = [ibm_pi_volume.volume] + pi_cloud_instance_id = ibm_resource_instance.location.guid + pi_volume_name = resource.ibm_pi_volume.volume.pi_volume_name +} +# Create an ssh key +resource "ibm_pi_key" "key" { pi_cloud_instance_id = ibm_resource_instance.location.guid - pi_volume_name = var.volume_name + pi_key_name = var.ssh_key_name + pi_ssh_key = var.ssh_key_rsa +} +data "ibm_pi_key" "data_source_key" { + pi_cloud_instance_id = ibm_resource_instance.location.guid + pi_key_name = resource.ibm_pi_key.key.pi_key_name } # Create an instance resource "ibm_pi_instance" "instance" { - depends_on = [data.ibm_pi_image.data_source_image, - data.ibm_pi_key.data_source_key, - data.ibm_pi_volume.data_source_volume, - data.ibm_pi_network.data_source_private_network] - pi_cloud_instance_id = ibm_resource_instance.location.guid pi_instance_name = var.instance_name pi_memory = var.memory @@ -72,21 +73,6 @@ resource "ibm_pi_instance" "instance" { pi_volume_ids = [data.ibm_pi_volume.data_source_volume.id] } data "ibm_pi_instance" "data_source_instance" { - depends_on = [ibm_pi_instance.instance] - - pi_cloud_instance_id = ibm_resource_instance.location.guid - pi_instance_name = var.instance_name -} - -# Create an ssh key -resource "ibm_pi_key" "key" { pi_cloud_instance_id = ibm_resource_instance.location.guid - pi_key_name = var.ssh_key_name - pi_ssh_key = var.ssh_key_rsa -} -data "ibm_pi_key" "data_source_key" { - depends_on = [ibm_pi_key.key] - - pi_cloud_instance_id = ibm_resource_instance.location.guid - pi_key_name = var.ssh_key_name + pi_instance_name = resource.ibm_pi_instance.instance.pi_instance_name } diff --git a/examples/ibm-power/variables.tf b/examples/ibm-power/variables.tf index 63c23eb52b..a087dea11d 100644 --- a/examples/ibm-power/variables.tf +++ b/examples/ibm-power/variables.tf @@ -89,6 +89,18 @@ variable "volume_type" { default = "" } +## SSH Key +variable "ssh_key_name" { + description = "Name of the ssh key to be used" + type = string + default = "" +} +variable "ssh_key_rsa" { + description = "Public ssh key" + type = string + default = "" +} + ## Instance variable "instance_name" { description = "Name of the instance" @@ -120,15 +132,3 @@ variable "sys_type" { type = string default = "" } - -## SSH Key -variable "ssh_key_name" { - description = "Name of the ssh key to be used" - type = string - default = "" -} -variable "ssh_key_rsa" { - description = "Public ssh key" - type = string - default = "" -}