Skip to content
Closed
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
Empty file.
109 changes: 109 additions & 0 deletions examples/connectivity/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
##############################################################################
# Resource Group
##############################################################################

module "resource_group" {
source = "terraform-ibm-modules/resource-group/ibm"
version = "1.0.5"
# if an existing resource group is not set (null) create a new one using prefix
resource_group_name = var.resource_group == null ? "${var.prefix}-resource-group" : null
existing_resource_group_name = var.resource_group
}

##############################################################################
# ICD postgresql database
##############################################################################

module "postgresql_db" {
source = "../.."
resource_group_id = module.resource_group.resource_group_id
name = "${var.prefix}-postgres"
pg_version = var.pg_version
region = var.region
resource_tags = var.resource_tags
access_tags = var.access_tags
}

resource "ibm_is_vpc" "example_vpc" {
name = "${var.prefix}-vpc"
resource_group = module.resource_group.resource_group_id
tags = var.resource_tags
}

##############################################################################
# Create new SSH key
##############################################################################

resource "tls_private_key" "tls_key" {
algorithm = "RSA"
rsa_bits = 4096
}

resource "ibm_is_ssh_key" "ssh_key" {
name = "${var.prefix}-ssh-key"
public_key = tls_private_key.tls_key.public_key_openssh
}

##############################################################################
# VSI
##############################################################################

resource "ibm_is_instance" "vsi" {
name = "${var.prefix}-vsi"
image = "r006-1366d3e6-bf5b-49a0-b69a-8efd93cc225f"
profile = "cx2-2x4"
resource_group = module.resource_group.resource_group_id
vpc = ibm_is_vpc.example_vpc.id
zone = "us-south-1"
keys = [ibm_is_ssh_key.ssh_key.id]
lifecycle {
ignore_changes = [
image
]
}

primary_network_interface {
subnet = ibm_is_vpc.example_vpc.subnets[0].id
primary_ipv4_address = "10.240.0.6" # will be deprecated. Use primary_ip.[0].address
allow_ip_spoofing = true
}

boot_volume {
encryption = "crn:v1:bluemix:public:kms:us-south:a/dffc98a0f1f0f95f6613b3b752286b87:e4a29d1a-2ef0-42a6-8fd2-350deb1c647e:key:5437653b-c4b1-447f-9646-b2a2a4cd6179"
}

network_interfaces {
subnet = ibm_is_vpc.example_vpc.subnets[0].id
allow_ip_spoofing = false
}

# User can configure timeouts
timeouts {
create = "15m"
update = "15m"
delete = "15m"
}
}

resource "ibm_is_floating_ip" "vsi_fip" {
name = "${var.prefix}-fip"
target = ibm_is_instance.vsi.primary_network_interface[0].id
access_tags = var.access_tags
}

resource "null_resource" "db_connection" {
depends_on = [ibm_is_instance.vsi]

provisioner "remote-exec" {
inline = [
"sudo apt-get install -y postgresql-client",
"psql -h ${module.postgresql_db.hostname} -p ${module.postgresql_db.port}"
]
connection {
type = "ssh"
host = ibm_is_floating_ip.vsi_fip.address
user = "admin"
private_key = tls_private_key.tls_key.private_key_pem
}
}
}
Empty file.
4 changes: 4 additions & 0 deletions examples/connectivity/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
provider "ibm" {
ibmcloud_api_key = var.ibmcloud_api_key
region = var.region
}
41 changes: 41 additions & 0 deletions examples/connectivity/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
variable "ibmcloud_api_key" {
type = string
description = "The IBM Cloud API Key"
sensitive = true
}

variable "region" {
type = string
description = "Region to provision all resources created by this example."
default = "us-south"
}

variable "prefix" {
type = string
description = "Prefix to append to all resources created by this example"
default = "pg-con"
}

variable "pg_version" {
description = "Version of the postgresql instance. If no value passed, the current ICD preferred version is used."
type = string
default = null
}

variable "resource_group" {
type = string
description = "An existing resource group name to use for this example, if unset a new resource group will be created"
default = null
}

variable "resource_tags" {
type = list(string)
description = "Optional list of tags to be added to created resources"
default = []
}

variable "access_tags" {
type = list(string)
description = "A list of access tags to apply to the PostgreSQL instance created by the module, see https://cloud.ibm.com/docs/account?topic=account-access-tags-tutorial for more details"
default = []
}
17 changes: 17 additions & 0 deletions examples/connectivity/version.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
terraform {
required_version = ">= 1.3.0"
required_providers {
# Pin to the lowest provider version of the range defined in the main module's version.tf to ensure lowest version still works
ibm = {
source = "IBM-Cloud/ibm"
version = "1.54.0"
}
tls = {
source = "hashicorp/tls"
version = ">= 4.0.4"
}
null = {
version = ">= 3.2.1"
}
}
}