Skip to content

Terraform module for creation of resources on public clouds platforms.

License

Notifications You must be signed in to change notification settings

MongoExpUser/Terraform-Created-Resources

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terraform-Created-Resources

Terraform module for creation of resources on public cloud platforms.

The following public cloud platforms and resources are currently covered:

  1. 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 variable enable_web_server, in the init_mongodb_server.sh file to false.
    b) See line 30 of init_mongodb_server.sh file.
  2. 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, to false in the startup script
    b) See line 122 of the main.tf file, where linode_stackscript_init is defined.

This repo is based on Terraform Version 0.14.4.

RUNNING MODULE

To run the module to create resources on AWS:

  1. 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

  2. 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
}
  1. 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 with sudo 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

To run the module to create resources on Linode:

  1. 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
}
  1. 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 with sudo 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

License

Copyright © 2015 - present. MongoExpUser

Licensed under the MIT license.

About

Terraform module for creation of resources on public clouds platforms.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published