Skip to content

dashdevs/terraform-aws-single-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

terraform-aws-single-service

Usage

IMPORTANT: We do not pin modules to versions in our examples because of the difficulty of keeping the versions in the documentation in sync with the latest released versions. We highly recommend that in your code you pin the version to the exact version you are using so that your infrastructure remains stable, and update versions in a systematic way so that they do not catch you by surprise.

example for one EC instance:

module "admin_panel_computing" {
  source                    = "dashdevs/single-service/aws"
  name                      = var.name_prefix
  vpc_id                    = var.vpc_id
  ec2_subnets               = var.subnets
  ec2_instance_name_postfix = var.instance_name
  applications_config       = [{
    application_name  = var.application_name
    application_ports = "80:8080"
  }]
}

example for EC2 instance with autoscaling group:

module "computing" {
  source                    = "dashdevs/single-service/aws"
  name                      = var.name_prefix
  vpc_id                    = var.vpc_id
  ec2_subnets               = var.private_subnets
  ec2_instance_type         = var.ec2_instance_type
  target_group_arns         = module.load-balancer.target_group_arns
  ec2_instance_name_postfix = var.instance_name
  create_autoscaling        = true
  ec2_instance_count_max    = 2
  applications_config = [{
    application_name  = var.application_name
    application_ports = "80:8080"
    application_start_command = null
    application_env_vars = [
      {
        name = "example_var_name"
        value = "example_var_value"
      }
    ]
  }]
}

Requirements

Name Version
terraform >= 1.5.2
aws >= 3.34

Providers

Name Version
aws >= 3.34

Inputs

Name Description Type Default Required
name Is used to create names for all internal resources of a module. It represents a prefix that will be added to the names of all internal resources to ensure their uniqueness within the module. string n/a yes
vpc_id Identifier of the VPC to which the internal resources will be connected string n/a yes
ec2_subnets List of subnet identifiers to which the internal resources will be connected list(string) n/a yes
ec2_create_eip Used to create Elastic IP and assign to the EC2 instance bool false no
ec2_instance_type Type of an EC2 instances string t2.micro no
ec2_instance_count_min Minimum number of EC2 instances that should be provisioned if create_autoscaling is true number 1 no
ec2_instance_count_max Maximum number of EC2 instances that should be provisioned if create_autoscaling is true number 1 no
attach_ecr_based_deployment_policy If true, will attach ecr based deployment policy to EC2 instances bool true no
iam_role_additional_policies List of additional policy for attach to EC2 instances list(string) [] no
create_autoscaling Used to create autoscaling group. If true, will create autoscaling group bool false no
target_group_arns Loadbalancer target group ARN list. Used for attach EC2 instance to loadbalancer, if create_autoscaling is false list(string) [] no
ec2_instance_name_postfix A primary keyword of the instance name. The resulting instance name will consist of name prefix and instance name postfix. string server no
ec2_ingress_ports The list of ports that are allowed for incoming traffic to an EC2 instance list(string) ["80", "22"] no
applications_config Applications connfig map for map application name, ports, start_coommand, and list of environment variables list(object({application_name, application_ports})) See defaults in application_name, application_ports, application_start_command and application_env_vars no
application_name Application name. Internal field in applications_config string core no
application_ports Application ports. Internal field in applications_config string "80:8080" no
application_start_command Application Docker endpoint in the ssm document. Internal field in applications_config string null no
application_env_vars List of map of the application environment variables in the ssm document. Wher name it is the variable name and value it is the variable value. Internal field in applications_config list(object{name = string, value = string}) [] no

Outputs

Name Description
ec2_instance_role The IAM role identifier assigned to the EC2 instance
ec2_ssh_keypair_value The value of the SSH key pair that will be used for EC2 instances
ec2_security_group_id The security group identifier assigned to the EC2 instance
ec2_instance_id EC2 Instance identifier
ec2_elastic_ip_address Elastic ip address assigned to the EC2 instance