Skip to content

Commit

Permalink
Merge pull request #1 from pbfinley1911/main
Browse files Browse the repository at this point in the history
Add copy routine for private image
  • Loading branch information
pbfinley1911 authored Jun 1, 2022
2 parents 149580d + fa76889 commit 395a85b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
This directory contains the sample Terraform code to create a Power virtual server instance image.

To create your own Power virtual server instance image, you should fork this repository and then modify the local variable `public_image_name` in the file `main.tf` to reference your own publicly availble image.
To create your own Power virtual server instance image, you should fork this repository and then modify the local variable `stock_image_name` in the file `main.tf` to reference your own publicly availble image.

## Before you begin

Expand All @@ -22,7 +22,7 @@ To install the software, configure the following required variables:
* Enter an SSH Key Name for the selected server instance
* Enter a Network Name or ID for the selected server instance.

If necessary, modify the optional configuration items related to [memory](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/pi_instance#pi_memory), [processors](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/pi_instance#pi_processors), [processor type](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/pi_instance#pi_proc_type), and [system type](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/pi_instance#pi_sys_type).
If necessary, modify the optional configuration items related to [memory](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/pi_instance#pi_memory), [processors](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/pi_instance#pi_processors), [processor type](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/pi_instance#pi_proc_type), [storage type](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/pi_instance#pi_storage_type) and [system type](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/pi_instance#pi_sys_type).

## Upgrading to a new version

Expand Down
21 changes: 18 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ data "ibm_pi_catalog_images" "catalog_images" {
pi_cloud_instance_id = local.pid
}

data "ibm_pi_images" "cloud_instance_images" {
pi_cloud_instance_id = local.pid
}

locals {
public_image_name = "7200-05-01"
catalog_image = [for x in data.ibm_pi_catalog_images.catalog_images.images : x if x.name == local.public_image_name]
stock_image_name = "7300-00-01"
catalog_image = [for x in data.ibm_pi_catalog_images.catalog_images.images : x if x.name == local.stock_image_name]
private_image = [for x in data.ibm_pi_images.cloud_instance_images.image_info : x if x.name == local.stock_image_name]
private_image_id = length(local.private_image) > 0 ? local.private_image[0].id : ""
}

data "ibm_pi_key" "key" {
Expand All @@ -19,15 +25,24 @@ data "ibm_pi_network" "power_network" {
pi_network_name = var.network_name
}

resource "ibm_pi_image" "stock_image_copy" {
count = length(local.private_image_id) == 0 ? 1 : 0

pi_image_name = local.stock_image_name
pi_image_id = local.catalog_image[0].image_id
pi_cloud_instance_id = local.pid
}

resource "ibm_pi_instance" "instance" {
pi_cloud_instance_id = local.pid
pi_memory = var.memory
pi_processors = var.processors
pi_instance_name = var.instance_name
pi_proc_type = var.processor_type
pi_image_id = local.catalog_image[0].image_id
pi_image_id = length(local.private_image_id) == 0 ? ibm_pi_image.stock_image_copy[0].image_id : local.private_image_id
pi_key_pair_name = data.ibm_pi_key.key.id
pi_sys_type = var.sys_type
pi_storage_type = var.storage_type
pi_network {
network_id = data.ibm_pi_network.power_network.id
}
Expand Down
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ variable "sys_type" {
default = "s922"
description = "The type of system on which to create the VM: 's922', 'e880', 'e980', 'e1080', or 's1022'"
}
variable "storage_type" {
type = string
default = "tier1"
description = "The type of storage tier to assign for storage volume performance: 'tier1' or 'tier3'"
}
variable "ssh_key_name" {
type = string
description = "The name of the public SSH RSA key to use when creating the instance, as defined for the selected Power Systems Virtual Server CRN"
Expand Down

0 comments on commit 395a85b

Please sign in to comment.