|
| 1 | +// packer { |
| 2 | +// required_plugins { |
| 3 | +// ibmcloud = { |
| 4 | +// version = ">=v3.0.0" |
| 5 | +// source = "github.com/IBM/ibmcloud" |
| 6 | +// } |
| 7 | +// } |
| 8 | +// } |
| 9 | + |
| 10 | +variable "IBM_API_KEY" { |
| 11 | + type = string |
| 12 | +} |
| 13 | + |
| 14 | +variable "SUBNET_ID" { |
| 15 | + type = string |
| 16 | +} |
| 17 | + |
| 18 | +variable "REGION" { |
| 19 | + type = string |
| 20 | +} |
| 21 | + |
| 22 | +variable "RESOURCE_GROUP_ID" { |
| 23 | + type = string |
| 24 | +} |
| 25 | + |
| 26 | +variable "SECURITY_GROUP_ID" { |
| 27 | + type = string |
| 28 | +} |
| 29 | +// variable "VPC_URL" { |
| 30 | +// type = string |
| 31 | +// } |
| 32 | +// variable "IAM_URL" { |
| 33 | +// type = string |
| 34 | +// } |
| 35 | + |
| 36 | + |
| 37 | +locals { |
| 38 | + timestamp = regex_replace(timestamp(), "[- TZ:]", "") |
| 39 | +} |
| 40 | + |
| 41 | +source "ibmcloud-vpc" "centos" { |
| 42 | + api_key = var.IBM_API_KEY |
| 43 | + region = var.REGION |
| 44 | + subnet_id = var.SUBNET_ID |
| 45 | + resource_group_id = var.RESOURCE_GROUP_ID |
| 46 | + security_group_id = var.SECURITY_GROUP_ID |
| 47 | + |
| 48 | + vsi_base_image_name = "ibm-centos-7-9-minimal-amd64-5" |
| 49 | + |
| 50 | + vsi_profile = "bx2-2x8" |
| 51 | + vsi_interface = "public" |
| 52 | + vsi_user_data_file = "" |
| 53 | + |
| 54 | + image_name = "packer-${local.timestamp}-1" |
| 55 | + |
| 56 | + communicator = "ssh" |
| 57 | + ssh_username = "root" |
| 58 | + ssh_port = 22 |
| 59 | + ssh_timeout = "15m" |
| 60 | + |
| 61 | + timeout = "30m" |
| 62 | +} |
| 63 | + |
| 64 | +source "ibmcloud-vpc" "centos-other" { |
| 65 | + api_key = var.IBM_API_KEY |
| 66 | + region = var.REGION |
| 67 | + subnet_id = var.SUBNET_ID |
| 68 | + resource_group_id = var.RESOURCE_GROUP_ID |
| 69 | + security_group_id = var.SECURITY_GROUP_ID |
| 70 | + |
| 71 | + vsi_base_image_name = "ibm-centos-7-9-minimal-amd64-5" |
| 72 | + |
| 73 | + vsi_profile = "bx2-2x8" |
| 74 | + vsi_interface = "public" |
| 75 | + vsi_user_data_file = "" |
| 76 | + |
| 77 | + image_name = "packer-${local.timestamp}-2" |
| 78 | + |
| 79 | + communicator = "ssh" |
| 80 | + ssh_username = "root" |
| 81 | + ssh_port = 22 |
| 82 | + ssh_timeout = "15m" |
| 83 | + |
| 84 | + timeout = "30m" |
| 85 | +} |
| 86 | + |
| 87 | +build { |
| 88 | + sources = [ |
| 89 | + "source.ibmcloud-vpc.centos", |
| 90 | + "source.ibmcloud-vpc.centos-other" |
| 91 | + ] |
| 92 | + |
| 93 | + provisioner "shell" { |
| 94 | + execute_command = "{{.Vars}} bash '{{.Path}}'" |
| 95 | + inline = [ |
| 96 | + "echo 'Hello from IBM Cloud Packer Plugin - VPC Infrastructure'", |
| 97 | + "echo 'Hello from IBM Cloud Packer Plugin - VPC Infrastructure' >> /hello.txt" |
| 98 | + ] |
| 99 | + } |
| 100 | +} |
0 commit comments