Skip to content

Commit d03d3a9

Browse files
authored
Update terraform example (#5050)
* Update powervs terraform example with workspace creation * Update workspace creation construct * Update datacenter location comment * Remove explicit depends on text from example
1 parent 37a64aa commit d03d3a9

File tree

3 files changed

+135
-93
lines changed

3 files changed

+135
-93
lines changed

examples/ibm-power/main.tf

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,64 @@
1-
data "ibm_pi_image" "data_source_image" {
2-
pi_cloud_instance_id = var.cloud_instance_id
1+
# Create a workspace
2+
resource "ibm_resource_instance" "location" {
3+
name = var.workspace_name
4+
resource_group_id = var.resource_group_id
5+
location = var.datacenter
6+
service = "power-iaas"
7+
plan = "power-virtual-server-group"
8+
}
9+
10+
# Create an image
11+
resource "ibm_pi_image" "image" {
12+
pi_cloud_instance_id = ibm_resource_instance.location.guid
313
pi_image_name = var.image_name
14+
pi_image_id = var.image_id
415
}
5-
resource "ibm_pi_key" "key" {
6-
pi_cloud_instance_id = var.cloud_instance_id
7-
pi_key_name = var.ssh_key_name
8-
pi_ssh_key = var.ssh_key_rsa
16+
data "ibm_pi_image" "data_source_image" {
17+
pi_cloud_instance_id = ibm_resource_instance.location.guid
18+
pi_image_name = resource.ibm_pi_image.image.pi_image_name
919
}
10-
data "ibm_pi_key" "data_source_key" {
11-
depends_on = [ibm_pi_key.key]
1220

13-
pi_cloud_instance_id = var.cloud_instance_id
14-
pi_key_name = var.ssh_key_name
15-
}
16-
resource "ibm_pi_network" "network" {
17-
pi_cloud_instance_id = var.cloud_instance_id
21+
# Create a network
22+
resource "ibm_pi_network" "private_network" {
23+
pi_cloud_instance_id = ibm_resource_instance.location.guid
1824
pi_network_name = var.network_name
1925
pi_network_type = var.network_type
20-
count = var.network_count
26+
pi_cidr = var.network_cidr
27+
pi_dns = [var.network_dns]
28+
pi_network_mtu = 2000
2129
}
22-
data "ibm_pi_public_network" "data_source_network" {
23-
depends_on = [ibm_pi_network.network]
24-
25-
pi_cloud_instance_id = var.cloud_instance_id
30+
data "ibm_pi_network" "data_source_private_network" {
31+
pi_cloud_instance_id = ibm_resource_instance.location.guid
32+
pi_network_name = resource.ibm_pi_network.private_network.pi_network_name
2633
}
34+
35+
# Create a volume
2736
resource "ibm_pi_volume" "volume" {
28-
pi_cloud_instance_id = var.cloud_instance_id
37+
pi_cloud_instance_id = ibm_resource_instance.location.guid
2938
pi_volume_name = var.volume_name
3039
pi_volume_type = var.volume_type
3140
pi_volume_size = var.volume_size
3241
pi_volume_shareable = var.volume_shareable
3342
}
3443
data "ibm_pi_volume" "data_source_volume" {
35-
depends_on = [ibm_pi_volume.volume]
44+
pi_cloud_instance_id = ibm_resource_instance.location.guid
45+
pi_volume_name = resource.ibm_pi_volume.volume.pi_volume_name
46+
}
3647

37-
pi_cloud_instance_id = var.cloud_instance_id
38-
pi_volume_name = var.volume_name
48+
# Create an ssh key
49+
resource "ibm_pi_key" "key" {
50+
pi_cloud_instance_id = ibm_resource_instance.location.guid
51+
pi_key_name = var.ssh_key_name
52+
pi_ssh_key = var.ssh_key_rsa
53+
}
54+
data "ibm_pi_key" "data_source_key" {
55+
pi_cloud_instance_id = ibm_resource_instance.location.guid
56+
pi_key_name = resource.ibm_pi_key.key.pi_key_name
3957
}
40-
resource "ibm_pi_instance" "instance" {
41-
depends_on = [data.ibm_pi_image.data_source_image,
42-
data.ibm_pi_key.data_source_key,
43-
data.ibm_pi_volume.data_source_volume,
44-
data.ibm_pi_public_network.data_source_network]
4558

46-
pi_cloud_instance_id = var.cloud_instance_id
59+
# Create an instance
60+
resource "ibm_pi_instance" "instance" {
61+
pi_cloud_instance_id = ibm_resource_instance.location.guid
4762
pi_instance_name = var.instance_name
4863
pi_memory = var.memory
4964
pi_processors = var.processors
@@ -52,13 +67,12 @@ resource "ibm_pi_instance" "instance" {
5267
pi_sys_type = var.sys_type
5368
pi_image_id = data.ibm_pi_image.data_source_image.id
5469
pi_key_pair_name = data.ibm_pi_key.data_source_key.id
55-
pi_network { network_id = data.ibm_pi_public_network.data_source_network.id }
70+
pi_network {
71+
network_id = data.ibm_pi_network.data_source_private_network.id
72+
}
5673
pi_volume_ids = [data.ibm_pi_volume.data_source_volume.id]
5774
}
58-
5975
data "ibm_pi_instance" "data_source_instance" {
60-
depends_on = [ibm_pi_instance.instance]
61-
62-
pi_cloud_instance_id = var.cloud_instance_id
63-
pi_instance_name = var.instance_name
64-
}
76+
pi_cloud_instance_id = ibm_resource_instance.location.guid
77+
pi_instance_name = resource.ibm_pi_instance.instance.pi_instance_name
78+
}

examples/ibm-power/variables.tf

Lines changed: 80 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,95 @@
1-
// Service / Account
1+
## Service // Account
22
variable "ibm_cloud_api_key" {
33
description = "API Key"
44
type = string
55
default = "<key>"
66
}
77
variable "region" {
8-
description = "Reigon of Service"
8+
description = "Region of Service"
99
type = string
1010
default = "<e.g dal>"
1111
}
1212
variable "zone" {
1313
description = "Zone of Service"
1414
type = string
15-
default = "<e.g 12>"
15+
default = "<e.g dal12>"
1616
}
17-
variable "cloud_instance_id" {
18-
description = "Cloud Instance ID of Service"
19-
type = string
20-
default = "<cid>"
17+
18+
## Workspace
19+
variable "workspace_name" {
20+
description = "Workspace Name"
21+
type = string
22+
default = "<name>"
23+
}
24+
# See available datacenter regions at: https://cloud.ibm.com/apidocs/power-cloud#endpoint
25+
variable "datacenter" {
26+
description = "Datacenter Region"
27+
type = string
28+
default = "<region>"
29+
}
30+
variable "resource_group_id" {
31+
description = "Resource Group ID"
32+
type = string
33+
default = "<name>"
2134
}
2235

23-
// Image
36+
## Image
2437
variable "image_name" {
25-
description = "Name of the image to be used"
38+
description = "Name of the image in the image catalog"
2639
type = string
2740
default = "<name>"
2841
}
42+
variable "image_id" {
43+
description = "ID of the image in the image catalog"
44+
type = string
45+
default = "<id>"
46+
}
2947

30-
// Instance
31-
variable "instance_name" {
32-
description = "Name of the instance"
48+
## Private Network
49+
variable "network_name" {
50+
description = "Name of the network"
3351
type = string
3452
default = "<name>"
3553
}
36-
variable "memory" {
37-
description = "Instance memory"
38-
type = number
39-
default = 1
54+
variable "network_type" {
55+
description = "Type of a network"
56+
type = string
57+
default = "vlan"
4058
}
41-
variable "processors" {
42-
description = "Instance processors"
43-
type = number
44-
default = 1
59+
variable "network_cidr" {
60+
description = "Network in CIDR notation"
61+
type = string
62+
default = "<e.g 192.168.0.0/24>"
4563
}
46-
variable "proc_type" {
47-
description = "Instance ProcType"
64+
variable "network_dns" {
65+
description = "Comma seaparated list of DNS Servers to use for this network"
4866
type = string
49-
default = "<e.g shared>"
67+
default = "<e.g 10.1.0.68>"
5068
}
51-
variable "storage_type" {
52-
description = "The storage type to be used"
69+
70+
## Volume
71+
variable "volume_name" {
72+
description = "Name of the volume"
5373
type = string
54-
default = "<e.g tier1>"
74+
default = "<name>"
5575
}
56-
variable "sys_type" {
57-
description = "Instance System Type"
76+
variable "volume_size" {
77+
description = "Size of a volume"
78+
type = number
79+
default = 1
80+
}
81+
variable "volume_shareable" {
82+
description = "Is a volume shareable"
83+
type = bool
84+
default = true
85+
}
86+
variable "volume_type" {
87+
description = "Type of a volume"
5888
type = string
59-
default = "<e.g s922>"
89+
default = "<e.g tier3>"
6090
}
6191

62-
// SSH Key
92+
## SSH Key
6393
variable "ssh_key_name" {
6494
description = "Name of the ssh key to be used"
6595
type = string
@@ -71,41 +101,34 @@ variable "ssh_key_rsa" {
71101
default = "<rsa value>"
72102
}
73103

74-
// Network
75-
variable "network_name" {
76-
description = "Name of the network"
104+
## Instance
105+
variable "instance_name" {
106+
description = "Name of the instance"
77107
type = string
78108
default = "<name>"
79109
}
80-
variable "network_type" {
81-
description = "Type of a network"
82-
type = string
83-
default = "<e.g pub-vlan>"
110+
variable "memory" {
111+
description = "Instance memory"
112+
type = number
113+
default = 1
84114
}
85-
variable "network_count" {
86-
description = "Number of networks to provision"
115+
variable "processors" {
116+
description = "Instance processors"
87117
type = number
88118
default = 1
89119
}
90-
91-
// Volume
92-
variable "volume_name" {
93-
description = "Name of the volume"
120+
variable "proc_type" {
121+
description = "Instance ProcType"
94122
type = string
95-
default = "<name>"
96-
}
97-
variable "volume_size" {
98-
description = "Size of a volume"
99-
type = number
100-
default = 0.25
123+
default = "<e.g shared>"
101124
}
102-
variable "volume_shareable" {
103-
description = "Is a volume shareable"
104-
type = bool
105-
default = true
125+
variable "storage_type" {
126+
description = "The storage type to be used"
127+
type = string
128+
default = "<e.g tier3>"
106129
}
107-
variable "volume_type" {
108-
description = "Type of a volume"
130+
variable "sys_type" {
131+
description = "Instance System Type"
109132
type = string
110-
default = "<e.g ssd>"
111-
}
133+
default = "<e.g s922>"
134+
}

examples/ibm-power/versions.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
terraform {
2+
required_version = ">= 0.13"
3+
}
4+
15
terraform {
26
required_providers {
37
ibm = {
48
source = "IBM-Cloud/ibm"
9+
version = "<desired_provider_version>"
510
}
611
}
7-
}
12+
}

0 commit comments

Comments
 (0)