|
| 1 | +data "ibm_pi_network" "network" { |
| 2 | + pi_network_name = var.network |
| 3 | + pi_cloud_instance_id = var.power_instance_id |
| 4 | +} |
| 5 | + |
| 6 | +data "ibm_pi_image" "power_images" { |
| 7 | + pi_image_name = var.image_name |
| 8 | + pi_cloud_instance_id = var.power_instance_id |
| 9 | +} |
| 10 | + |
| 11 | +provider "ct" {} |
| 12 | + |
| 13 | +variable "project" { |
| 14 | + type = string |
| 15 | + default = "coreos-ppc64le-builder" |
| 16 | +} |
| 17 | + |
| 18 | +# Which distro are we deploying a builder for? Override the |
| 19 | +# default by setting the env var: TF_VAR_distro=rhcos |
| 20 | +variable "distro" { |
| 21 | + type = string |
| 22 | + default = "fcos" |
| 23 | +} |
| 24 | + |
| 25 | +check "health_check_distro" { |
| 26 | + assert { |
| 27 | + condition = anytrue([ |
| 28 | + var.distro == "fcos", |
| 29 | + var.distro == "rhcos" |
| 30 | + ]) |
| 31 | + error_message = "Distro must be 'fcos' or 'rhcos'" |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +# Variables used for splunk deployment, which is only |
| 36 | +# for RHCOS builders. Define them in the environment with: |
| 37 | +# export TF_VAR_splunk_hostname=... |
| 38 | +# export TF_VAR_splunk_sidecar_repo=... |
| 39 | +# export TF_VAR_itpaas_splunk_repo=... |
| 40 | +variable "splunk_hostname" { |
| 41 | + type = string |
| 42 | + default = "" |
| 43 | +} |
| 44 | +variable "splunk_sidecar_repo" { |
| 45 | + type = string |
| 46 | + default = "" |
| 47 | +} |
| 48 | +variable "itpaas_splunk_repo" { |
| 49 | + type = string |
| 50 | + default = "" |
| 51 | +} |
| 52 | + |
| 53 | +# Check that if we are deploying a RHCOS builder the splunk |
| 54 | +# variables have been defined. |
| 55 | +check "health_check_rhcos_splunk_vars" { |
| 56 | + assert { |
| 57 | + condition = !(var.distro == "rhcos" && anytrue([ |
| 58 | + var.splunk_hostname == "", |
| 59 | + var.splunk_sidecar_repo == "", |
| 60 | + var.itpaas_splunk_repo == "" |
| 61 | + ])) |
| 62 | + error_message = "Must define splunk env vars for RCHOS builders" |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +locals { |
| 67 | + fcos_snippets = [ |
| 68 | + file("../../coreos-ppc64le-builder.bu"), |
| 69 | + ] |
| 70 | + rhcos_snippets = [ |
| 71 | + file("../../coreos-ppc64le-builder.bu"), |
| 72 | + templatefile("../../builder-splunk.bu", { |
| 73 | + SPLUNK_HOSTNAME = var.splunk_hostname |
| 74 | + SPLUNK_SIDECAR_REPO = var.splunk_sidecar_repo |
| 75 | + ITPAAS_SPLUNK_REPO = var.itpaas_splunk_repo |
| 76 | + }) |
| 77 | + ] |
| 78 | +} |
| 79 | +data "ct_config" "butane" { |
| 80 | + strict = true |
| 81 | + content = file("../../builder-common.bu") |
| 82 | + snippets = var.distro == "rhcos" ? local.rhcos_snippets : local.fcos_snippets |
| 83 | +} |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | +resource "ibm_pi_instance" "pvminstance" { |
| 88 | + pi_memory = var.memory |
| 89 | + pi_processors = var.processors |
| 90 | + pi_instance_name = "${var.project}-${formatdate("YYYYMMDD", timestamp())}" |
| 91 | + pi_proc_type = var.proc_type |
| 92 | + pi_image_id = data.ibm_pi_image.power_images.id |
| 93 | + pi_network { |
| 94 | + network_id = data.ibm_pi_network.network.id |
| 95 | + } |
| 96 | + pi_key_pair_name = var.ssh_key_name |
| 97 | + pi_sys_type = var.system_type |
| 98 | + pi_cloud_instance_id = var.power_instance_id |
| 99 | + pi_user_data = base64encode(data.ct_config.butane.rendered) |
| 100 | + |
| 101 | +} |
0 commit comments