Terraform module for creation of resources on public cloud platforms.
The following public cloud platforms and resources are currently covered:
AWS
- EC2 and Lightsails instances (VMs) with Node.js and MongoDB installations.
Note 1: Node.js is installed on the the web server instance(s).
Note 2: Node.js and MongoDB are installed on the db server instance(s).
Note 3: Node.js installation can be disabled on the db server instance(s):
a) By setting the variableenable_web_server
, in theinit_mongodb_server.sh
file tofalse
.
b) See line 30 ofinit_mongodb_server.sh
file.Linode
- Linode instances (VMs) with Node.js and MongoDB installations.
Note 1: Node.js and MongoDB are installed on the web server instance(s).
Note 2: MongoDB installation can be disabled on the web server instance(s):
a) By setting the variable,enable_mongodb_server
, tofalse
in thestartup script
b) See line 122 of themain.tf
file, wherelinode_stackscript_init
is defined.
This repo is based on Terraform Version 0.14.4
.
-
Save or download the start-up bash file(s) in the link(s) below to the current working directory (CWD):
a) https://raw.githubusercontent.com/MongoExpUser/Terraform-Created-Resources/master/init_web_server.sh
b) https://raw.githubusercontent.com/MongoExpUser/Terraform-Created-Resources/master/init_mongodb_server.sh -
Also, copy the following script into a file (base.tf) in the current working directory:
# define credential variable(s) of provider(s)
variable "aws_access_key" {}
variable "aws_secret_key" {}
variable "aws_region" {}
variable "create_aws_resources" {default = 1}
# define provider(s)
provider "aws" {
access_key = var.aws_access_key
secret_key = var.aws_secret_key
region = var.aws_region
}
# create resource(s)
module "public_cloud_resources" {
source = "git::https://github.com/MongoExpUser/Terraform-Created-Resources.git"
}
# create output(s)
output "ec2_web_server_instances" {
description = "A list of all created EC2 web server instances"
# the list contains key-value pairs of each instance's attributes
value = module.public_cloud_resources.aws_ec2_web_servers
}
output "ec2_db_server_instances" {
description = "A list of all created EC2 db server instances"
# the list contains key-value pairs of each instance's attributes
value = module.public_cloud_resources.aws_ec2_db_servers
}
output "lightsail_web_server_instances" {
description = "A list of all created AWS lightsail web server instances"
# the list contains key-value pairs of each instance's attributes
value = module.public_cloud_resources.aws_lightsail_web_servers
}
output "lightsail_db_server_instances" {
description = "A list of all created AWS lightsail db server instances"
# the list contains key-value pairs of each instance's attributes
value = module.public_cloud_resources.aws_lightsail_db_servers
}
output "lightsail_web_server_static_ips" {
description = "A list of all created AWS lightsail static ips"
# the list contains key-value pairs of each instance's attributes
value = module.public_cloud_resources.aws_lightsail_web_server_static_ips
}
output "lightsail_db_server_static_ips" {
description = "A list of all created AWS lightsail static ips"
# the list contains key-value pairs of each instance's attributes
value = module.public_cloud_resources.aws_lightsail_db_server_static_ips
}
- Finally, execute the module from the base file (base.tf) in the current working directory (CWD) by typing the following commands at the prompt (assuming running via
bash
withsudo
access):
#1) run init
sudo terraform init
#2) run terraform plan
sudo TF_VAR_aws_access_key="access-key-value" \
TF_VAR_aws_secret_key="secret-key-value" \
TF_VAR_aws_region="aws-region-value" \
terraform plan
#3) run terraform apply
sudo TF_VAR_aws_access_key="access-key-value" \
TF_VAR_aws_secret_key="secret-key-value" \
TF_VAR_aws_region="aws-region-value" \
terraform apply
- Copy the following script into a file (base.tf) in the current working directory:
# define credential variable(s) of provider(s)
variable "linode_token_value" {}
variable "create_linode_resources" {default = 1}
# define provider(s)
provider "linode" {
token = var.linode_token_value
}
# create resource(s)
module "public_cloud_resources" {
source = "git::https://github.com/MongoExpUser/Terraform-Created-Resources.git"
}
# create outputs
output "linode_sshkeys" {
description = "A list of all created linode_sshkeys"
# the list contains key-value pairs of each linode_sshkey's attributes
value = module.public_cloud_resources.linode_sshkeys
}
output "linode_stackscripts" {
description = "A list of all created linode_stackscripts"
# the list contains key-value pairs of each linode_stackscript's attributes
value = module.public_cloud_resources.linode_stackscripts
}
output "linode_instance_web_servers" {
description = "A list of all created linode_instances"
# the list contains key-value pairs of each linode_instance's attributes
value = module.public_cloud_resources.linode_instance_web_servers
}
- Then, execute the module from the base file (base.tf) in the current working directory (CWD) by typing the following commands at the prompt (assuming running via
bash
withsudo
access):
#1) run init
sudo terraform init
#2) run terraform plan
sudo TF_VAR_linode_token_value="linode-token-value" terraform plan
#3) run terraform apply
sudo TF_VAR_linode_token_value="linode-token-value" terraform apply
Copyright © 2015 - present. MongoExpUser
Licensed under the MIT license.