Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instance refactor #22

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions examples/instance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@ This example illustrates how to use the `instance` module.

## Inputs

| Name | Description | Type | Default | Required |
|-----------------------------------|-------------------------------------------------------|--------|---------|----------|
| resource\_group | Name of the resource group | string | default | no |
| no\_of\_instances | Number of VSI's | number | 1 | no |
| name | Name of the Subnet | string | n/a | yes |
| vpc | Name of the VPC | string | n/a | yes |
| location | Zone of the subnet | string | n/a | yes |
| image | Image ID for the instance | string | n/a | yes |
| profile | Profile type for the Instance | string | n/a | yes |
| ssh\_keys | List of ssh key IDs to the instance | list(string) | n/a | yes |
| primary\_network\_interface | List of primary_network_interface that are to be attached to the instance | list(object) | n/a | yes |
| user\_data | User Data for the instance | string | n/a | no |
| boot\_volume | List of boot volume that are to be attached to the instance| list(object) | n/a | no |
| network\_interfaces | List of network_interfaces that are to be attached to the instance | list(object) | n/a | no |
| data\_volumes | List of volume ids that are to be attached to the instance | list(string) | n/a | no |
| tags | List of tags to attach | list(string) | n/a | no |
Name | Description | Type | Default | Required
------------------------- | ------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- | ------- |------
instance_name | Name of the Instance | string | | true
vpc_name | VPC name | string | | true
subnet_name | Subnet in VPC where instances will be created | string | | true
image_name | Name of the image for the VSI | string | | true
profile | Profile type for the Instance | string | | true
ssh_key_name | Name of SSH key to use when provisioning VSI | string | | true
security_group_ids | Optional. A list of security group ids to attach the primary network interface. | list(string) | [] |
primary_network_interface | List of primary_network_interface that are to be attached to the instance | list(object({ interface_name = string primary_ipv4_address = string })) | { interface_name = "" primary_ipv4_address = "" } |
resource_group | Resource group name | string | null |
instances | number of Instances | number | 1 |
user_data | User Data for the instance | string | null |
data_volumes | List of volume ids that are to be attached to the instance | list(string) | null |
tags | List of Tags for the vpc | list(string) | null |
network_interfaces | List of network_interfaces that are to be attached to the instance | list(object({ subnet = string interface_name = string security_groups = list(string) primary_ipv4_address = string })) | null |
boot_volume | List of boot volume that are to be attached to the instance | list(object({ name = string encryption = string })) | null |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

Expand Down
37 changes: 18 additions & 19 deletions examples/instance/input.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@ Example Usage

//mandatory variables

primary_network_interface = [{
subnet = "0737-7a911fcf-737d-4a85-b3b1-0184c6939eb6"
interface_name = ""
primary_ipv4_address = ""
security_groups = ["r006-3c175148-9e94-4300-aa2d-f0a8aca1a9a4"]
},
]

ssh_keys = ["r006-61f07322-ec1d-4e8d-97d8-3002d46e9d0d"]
name = "tf-module-vsi"
subnet_id = "0737-7a911fcf-737d-4a85-b3b1-0184c6939eb6"
security_group_ids = ["r006-3c175148-9e94-4300-aa2d-f0a8aca1a9a4"]
ssh_key_ids = ["r006-61f07322-ec1d-4e8d-97d8-3002d46e9d0d"]
image_id = "r018-60d279a0-b328-40eb-a379-595ca53bee18"
profile = "bx2-2x8"


// optional variables

primary_network_interface = {
interface_name = ""
primary_ipv4_address = ""
}

network_interfaces = [{
subnet = "0727-6d96ba0c-e0da-434d-84ef-b57f0dc1ebff"
subnet_id = "0727-6d96ba0c-e0da-434d-84ef-b57f0dc1ebff"
interface_name = ""
primary_ipv4_address = ""
security_groups = []
Expand All @@ -42,12 +44,9 @@ data_volumes = ["r006-4e86a92a-bc1b-409b-9438-e13e7550730e"]
******************************************************/


primary_network_interface = [{
subnet = "<subnet_id>"
interface_name = "<primary_network_interface name>"
security_groups = ["<security_group_id>"]
primary_ipv4_address = "<primary_ipv4_address>"
},
]

ssh_keys = ["<sshKeyID>"]
name = "tf-module-vsi"
subnet_id = "<subnet_id>"
security_groups = ["<security_group_id>"]
ssh_key_ids = ["<sshKeyID>"]
profile = "<instance_profile>"
image_id = "<image_id>"
55 changes: 42 additions & 13 deletions examples/instance/main.tf
Original file line number Diff line number Diff line change
@@ -1,35 +1,64 @@
#####################################################
##############################################################################
# Instance Configuration Example
# Copyright 2020 IBM
#####################################################
##############################################################################

provider "ibm" {
provider ibm {
}

data "ibm_is_vpc" "vpc" {
data ibm_resource_group resource_group {
name = (var.resource_group != null ? var.resource_group : "default")
}

##############################################################################


##############################################################################
# VPC Data
##############################################################################

data ibm_is_vpc vpc {
name = var.vpc
}

data "ibm_resource_group" "resource_group" {
name = (var.resource_group != null ? var.resource_group : "default")
data ibm_is_subnet subnet {
name = var.subnet_name
}

data ibm_is_image image {
name = var.image_name
}

data ibm_is_ssh_key ssh_key {
name = var.ssh_key_name
}

module "instance" {
##############################################################################


##############################################################################
# Create Instance
##############################################################################

module instance {
// source = "terraform-ibm-modules/vpc/ibm//modules/instance"
source = "../../modules/instance"

no_of_instances = var.no_of_instances
instances = var.instances
name = var.name
vpc_id = data.ibm_is_vpc.vpc.id
resource_group_id = data.ibm_resource_group.resource_group.id
location = var.location
image = var.image
subnet_id = data.ibm_is_subnet.subnet.id
zone = data.ibm_is_subnet.subnet.zone
image_id = data.ibm_is_image.image.id
security_group_ids = var.security_group_ids
profile = var.profile
ssh_keys = var.ssh_keys
primary_network_interface = var.primary_network_interface
ssh_key_ids = [ data.ibm_is_ssh_key.ssh_key.id ]
user_data = var.user_data
boot_volume = var.boot_volume
network_interfaces = var.network_interfaces
data_volumes = var.data_volumes
tags = var.tags
}
}

##############################################################################
57 changes: 32 additions & 25 deletions examples/instance/variables.tf
Original file line number Diff line number Diff line change
@@ -1,83 +1,90 @@
#####################################################
##############################################################################
# Instance Module Example Parameters
# Copyright 2020 IBM
#####################################################
##############################################################################

variable "name" {
variable instance_name {
description = "Name of the Instance"
type = string
}

variable "vpc" {
variable vpc_name {
description = "VPC name"
type = string
}

variable "location" {
description = "Instance zone"
variable subnet_name {
description = "Subnet in VPC where instances will be created"
type = string
}

variable "image" {
description = "Image ID for the instance"
variable image_name {
description = "Name of the image for the VSI"
type = string
}

variable "profile" {
variable profile {
description = "Profile type for the Instance"
type = string
}

variable "ssh_keys" {
description = "List of ssh key IDs to the instance"
variable ssh_key_name {
description = "Name of SSH key to use when provisioning VSI"
type = string
}

##############################################################################


##############################################################################
# Optional Parameters
##############################################################################

variable security_group_ids {
description = "Optional. A list of security group ids to attach the primary network interface."
type = list(string)
default = []
}

variable "primary_network_interface" {
variable primary_network_interface {
description = "List of primary_network_interface that are to be attached to the instance"
type = list(object({
subnet = string
interface_name = string
security_groups = list(string)
primary_ipv4_address = string
}))
}

#####################################################
# Optional Parameters
#####################################################

variable "resource_group" {
variable resource_group {
description = "Resource group name"
type = string
default = null
}

variable "no_of_instances" {
variable instances {
description = "number of Instances"
type = number
default = 1
}

variable "user_data" {
variable user_data {
description = "User Data for the instance"
type = string
default = null
}

variable "data_volumes" {
variable data_volumes {
description = "List of volume ids that are to be attached to the instance"
type = list(string)
default = null
}

variable "tags" {
variable tags {
description = "List of Tags for the vpc"
type = list(string)
default = null
}

variable "network_interfaces" {
variable network_interfaces {
description = "List of network_interfaces that are to be attached to the instance"
type = list(object({
subnet = string
Expand All @@ -88,7 +95,7 @@ variable "network_interfaces" {
default = null
}

variable "boot_volume" {
variable boot_volume {
description = "List of boot volume that are to be attached to the instance"
type = list(object({
name = string
Expand Down
4 changes: 2 additions & 2 deletions examples/instance/versions.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#####################################################
##############################################################################
# VPC Instance
# Copyright 2020 IBM
#####################################################
##############################################################################

/***************************************************
NOTE: To source a particular version of IBM terraform provider, configure the parameter `version` as follows
Expand Down
Loading