diff --git a/examples/ibm-power/main.tf b/examples/ibm-power/main.tf index bf6c35f70e..bc34f2c8f6 100644 --- a/examples/ibm-power/main.tf +++ b/examples/ibm-power/main.tf @@ -1,49 +1,64 @@ -data "ibm_pi_image" "data_source_image" { - pi_cloud_instance_id = var.cloud_instance_id +# Create a workspace +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_resource_instance.location.guid pi_image_name = var.image_name + pi_image_id = var.image_id } -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 +data "ibm_pi_image" "data_source_image" { + pi_cloud_instance_id = ibm_resource_instance.location.guid + pi_image_name = resource.ibm_pi_image.image.pi_image_name } -data "ibm_pi_key" "data_source_key" { - depends_on = [ibm_pi_key.key] - pi_cloud_instance_id = var.cloud_instance_id - pi_key_name = var.ssh_key_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_resource_instance.location.guid 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] + pi_network_mtu = 2000 } -data "ibm_pi_public_network" "data_source_network" { - depends_on = [ibm_pi_network.network] - - pi_cloud_instance_id = var.cloud_instance_id +data "ibm_pi_network" "data_source_private_network" { + pi_cloud_instance_id = ibm_resource_instance.location.guid + pi_network_name = resource.ibm_pi_network.private_network.pi_network_name } + +# Create a volume resource "ibm_pi_volume" "volume" { - pi_cloud_instance_id = var.cloud_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 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 +} - pi_cloud_instance_id = var.cloud_instance_id - pi_volume_name = var.volume_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" { + pi_cloud_instance_id = ibm_resource_instance.location.guid + pi_key_name = resource.ibm_pi_key.key.pi_key_name } -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] - pi_cloud_instance_id = var.cloud_instance_id +# Create an instance +resource "ibm_pi_instance" "instance" { + pi_cloud_instance_id = ibm_resource_instance.location.guid pi_instance_name = var.instance_name pi_memory = var.memory pi_processors = var.processors @@ -52,13 +67,12 @@ 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_instance_name = var.instance_name -} \ No newline at end of file + pi_cloud_instance_id = ibm_resource_instance.location.guid + 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 b3d9adc292..a087dea11d 100644 --- a/examples/ibm-power/variables.tf +++ b/examples/ibm-power/variables.tf @@ -1,65 +1,95 @@ -// 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 = "" +} +# See available datacenter regions at: https://cloud.ibm.com/apidocs/power-cloud#endpoint +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 = "" +} -// Instance -variable "instance_name" { - description = "Name of the instance" +## Private Network +variable "network_name" { + description = "Name of the network" type = string default = "" } -variable "memory" { - description = "Instance memory" - type = number - default = 1 +variable "network_type" { + description = "Type of a network" + type = string + default = "vlan" } -variable "processors" { - description = "Instance processors" - type = number - default = 1 +variable "network_cidr" { + description = "Network in CIDR notation" + type = string + default = "" } -variable "proc_type" { - description = "Instance ProcType" +variable "network_dns" { + description = "Comma seaparated list of DNS Servers to use for this network" type = string - default = "" + default = "" } -variable "storage_type" { - description = "The storage type to be used" + +## Volume +variable "volume_name" { + description = "Name of the volume" type = string - default = "" + default = "" } -variable "sys_type" { - description = "Instance System Type" +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 = "" + default = "" } -// SSH Key +## SSH Key variable "ssh_key_name" { description = "Name of the ssh key to be used" type = string @@ -71,41 +101,34 @@ variable "ssh_key_rsa" { default = "" } -// Network -variable "network_name" { - description = "Name of the network" +## Instance +variable "instance_name" { + description = "Name of the instance" type = string default = "" } -variable "network_type" { - description = "Type of a network" - type = string - default = "" +variable "memory" { + description = "Instance memory" + type = number + default = 1 } -variable "network_count" { - description = "Number of networks to provision" +variable "processors" { + description = "Instance processors" type = number default = 1 } - -// Volume -variable "volume_name" { - description = "Name of the volume" +variable "proc_type" { + description = "Instance ProcType" type = string - default = "" -} -variable "volume_size" { - description = "Size of a volume" - type = number - default = 0.25 + default = "" } -variable "volume_shareable" { - description = "Is a volume shareable" - type = bool - default = true +variable "storage_type" { + description = "The storage type to be used" + type = string + default = "" } -variable "volume_type" { - description = "Type of a volume" +variable "sys_type" { + description = "Instance System Type" type = string - default = "" -} \ No newline at end of file + default = "" +} 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 +}