Skip to content

Commit

Permalink
WIP - First draft
Browse files Browse the repository at this point in the history
  • Loading branch information
ashishmohite committed Jun 16, 2020
1 parent 2c014cb commit d0d5e55
Show file tree
Hide file tree
Showing 15 changed files with 842 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log

# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
# .tfvars files are managed as part of configuration and so should be included in
# version control.
#
*.tfvars

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Include override files you do wish to add to version control using negated pattern
#
# !example_override.tf

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*

# Ignore ide configs
.idea
.vscode
71 changes: 71 additions & 0 deletions examples/load_balanced/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
provider "aws" {
region = var.region
profile = var.aws_profile
}

module "vpc" {
source = "scalereal/vpc/aws"
version = "0.0.1"
availability_zones = var.vpc_availability_zones
cidr_block = var.vpc_cidr_block
database_subnets = var.vpc_database_subnets
env = var.env
private_subnets = var.vpc_private_subnets
public_subnets = var.vpc_public_subnets
service_name = var.service_name
}

data "aws_iam_policy_document" "this" {
statement {
actions = ["sts:AssumeRole"]
principals {
identifiers = ["elasticbeanstalk.amazonaws.com"]
type = "Service"
}
effect = "Allow"
}
}

resource "aws_iam_role" "this" {
name = "eb_appversion_deletion_role"
assume_role_policy = data.aws_iam_policy_document.this.json
}

module "elastic_beanstalk_application" {
source = "scalereal/elastic-beanstalk-application/aws"
version = "0.0.1"
name = "Ruby App"
appversion_service_role_arn = aws_iam_role.this.arn
appversion_max_age_in_days = 90
}

//Error 1
#Error: InvalidParameterValue: Health transition option settings require enhanced SystemType.
//status code: 400, request id: 1f25b699-a4f8-4269-b0b1-3654c25de702yes
//
//on ../../main.tf line 138, in resource "aws_elastic_beanstalk_environment" "env":
//138: resource "aws_elastic_beanstalk_environment" "env" {


//Error 2
//Error: ConfigurationValidationException: Configuration validation exception: Invalid option value: 'null' (Namespace: 'aws:ec2:vpc', OptionName: 'Subnets'): Specify the subnets for the VPC.
//status code: 400, request id: c06491c6-35e0-4119-b702-c95edd1ea632
//
//on ../../main.tf line 138, in resource "aws_elastic_beanstalk_environment" "env":
//138: resource "aws_elastic_beanstalk_environment" "env" {


module "elastic_beanstalk_environment" {
source = "../../"
eb_app_name = module.elastic_beanstalk_application.name
env = var.env
service_name = var.service_name
description = "My Ruby test Env"
solution_stack_name = var.eb_solution_stack_name
vpc_id = module.vpc.id
enable_enhanced_healthreporting = true
private_subnets = module.vpc.private_subnets_ids
public_subnets = module.vpc.public_subnet_ids
asg_max_count = "2"
asg_min_count = "1"
}
Empty file added examples/load_balanced/out.tf
Empty file.
22 changes: 22 additions & 0 deletions examples/load_balanced/vars.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
variable "aws_profile" {
type = string
description = "AWS profile for running the TF scripts"
}

variable "region" {
type = string
default = "ap-south-1"
description = "AWS region for running the TF scripts"
}

variable "service_name" {}
variable "env" {}
variable "vpc_cidr_block" {}
variable "vpc_public_subnets" {}
variable "vpc_private_subnets" {}
variable "vpc_database_subnets" {}
variable "vpc_availability_zones" {}
variable eb_solution_stack_name {
type = string
default = "64bit Amazon Linux 2 v3.0.1 running Ruby 2.7"
}
Empty file.
Empty file added examples/single_instance/out.tf
Empty file.
Empty file.
Empty file added examples/worker_tier/main.tf
Empty file.
Empty file added examples/worker_tier/out.tf
Empty file.
Empty file added examples/worker_tier/vars.tf
Empty file.
61 changes: 61 additions & 0 deletions iam.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
data "aws_iam_policy_document" "ec2_role" {
statement {
actions = ["sts:AssumeRole"]
principals {
identifiers = ["ec2.amazonaws.com"]
type = "Service"
}
effect = "Allow"
}
}

resource "aws_iam_role" "ec2_role" {
name = "${var.service_name}-${var.env}-ec2-role"
assume_role_policy = data.aws_iam_policy_document.ec2_role.json
}

resource "aws_iam_instance_profile" "ec2_iam_instance_profile" {
name = "${var.service_name}-${var.env}-iam-instance-profile"
role = aws_iam_role.ec2_role.name
}

resource "aws_iam_role_policy_attachment" "policy_attachment_1" {
role = aws_iam_role.ec2_role.name
policy_arn = "arn:aws:iam::aws:policy/AWSElasticBeanstalkWebTier"
}

resource "aws_iam_role_policy_attachment" "policy_attachment_2" {
role = aws_iam_role.ec2_role.name
policy_arn = "arn:aws:iam::aws:policy/AWSElasticBeanstalkWorkerTier"
}

resource "aws_iam_role_policy_attachment" "policy_attachment_3" {
role = aws_iam_role.ec2_role.name
policy_arn = "arn:aws:iam::aws:policy/AWSElasticBeanstalkMulticontainerDocker"
}

data "aws_iam_policy_document" "service_role" {
statement {
actions = ["sts:AssumeRole"]
principals {
identifiers = ["elasticbeanstalk.amazonaws.com"]
type = "Service"
}
effect = "Allow"
}
}

resource "aws_iam_role" "service_role" {
name = "${var.service_name}-${var.env}-service-role"
assume_role_policy = data.aws_iam_policy_document.service_role.json
}

resource "aws_iam_role_policy_attachment" "policy_attachment_4" {
role = aws_iam_role.service_role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSElasticBeanstalkEnhancedHealth"
}

resource "aws_iam_role_policy_attachment" "service" {
role = aws_iam_role.service_role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSElasticBeanstalkService"
}
Loading

0 comments on commit d0d5e55

Please sign in to comment.