Skip to content

Commit

Permalink
fix: setup tf code
Browse files Browse the repository at this point in the history
  • Loading branch information
lpsm-dev committed Apr 5, 2024
1 parent f050af6 commit 2f87715
Show file tree
Hide file tree
Showing 28 changed files with 514 additions and 31 deletions.
42 changes: 42 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,45 @@

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# ================================================
# TERRAFORM
# ================================================

# Local .terraform directories
**/.terraform/*

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

# Crash log files
crash.log

# Exclude all .tfvars files, which are likely to contain sentitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
#
*.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 CLI configuration files
.terraformrc
terraform.rc

tfsec.test.xml
.terraform.lock.hcl
10 changes: 10 additions & 0 deletions infra/terraform/setup-ec2/_backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Generated by Terragrunt. Sig: nIlQXj57tbuaRZEa
terraform {
backend "s3" {
bucket = ""
dynamodb_table = ""
encrypt = true
key = "projects/docker-crypto-miner/setup-ec2/terraform.tfstate"
region = "us-east-1"
}
}
6 changes: 6 additions & 0 deletions infra/terraform/setup-ec2/_datas.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# ==================================================================
# DATAS - AWS
# ==================================================================

data "aws_caller_identity" "current" {}
data "aws_region" "current" {}
22 changes: 22 additions & 0 deletions infra/terraform/setup-ec2/_locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
locals {
# ==================================================================
# GENERAL
# ==================================================================
client_name = "lpsm-dev"
# ==================================================================
# AWS GENERAL
# ==================================================================
aws_account_id = data.aws_caller_identity.current.account_id
aws_default_tags = {
cost_allocation_business_unit = "lpsm-dev"
cost_allocation_product = "lpsm-dev"
operation_support_account_name = "${local.client_name}-${local.aws_environment}-services"
operation_support_criticality = "low"
operation_support_environment = local.aws_environment
operation_support_team = "cloud"
source_code = "https://github.com/lpsm-dev/docker-crypto-miner"
source_project = "setup-ec2"
}
aws_environment = "develop"
aws_region = "us-east-1"
}
13 changes: 13 additions & 0 deletions infra/terraform/setup-ec2/_outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# ==================================================================
# OUTPUTS - AWS
# ==================================================================

output "aws_account_id" {
description = "Selected AWS Account ID"
value = local.aws_account_id
}

output "aws_region" {
description = "Details about selected AWS region"
value = data.aws_region.current.name
}
66 changes: 59 additions & 7 deletions infra/terraform/setup-ec2/_providers.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,64 @@
/**
* Configure AWS provider
*/
# ==================================================================
# PROVIDER - AWS DEFAULT
# ==================================================================

provider "aws" {
region = local.aws_region
default_tags {
tags = {
"automation:managedby" = "terraform",
"cost-allocation:business-unit" = local.aws_default_tags.cost_allocation_business_unit,
"cost-allocation:product" = local.aws_default_tags.cost_allocation_product,
"operation-support:account" = local.aws_default_tags.operation_support_account_name,
"operation-support:criticality" = local.aws_default_tags.operation_support_criticality
"operation-support:environment" = local.aws_default_tags.operation_support_environment,
"operation-support:team" = local.aws_default_tags.operation_support_team,
"source-code" = local.aws_default_tags.source_code
"source-project" = local.aws_default_tags.source_project
}
}
}

# ==================================================================
# PROVIDER - AWS SA-EAST-1
# ==================================================================

provider "aws" {
region = var.aws_region
profile = var.aws_profile
region = "sa-east-1"
alias = "sa-east-1"
default_tags {
tags = {
"automation:managedby" = "terraform",
"cost-allocation:business-unit" = local.aws_default_tags.cost_allocation_business_unit,
"cost-allocation:product" = local.aws_default_tags.cost_allocation_product,
"operation-support:account" = local.aws_default_tags.operation_support_account_name,
"operation-support:criticality" = local.aws_default_tags.operation_support_criticality
"operation-support:environment" = local.aws_default_tags.operation_support_environment,
"operation-support:team" = local.aws_default_tags.operation_support_team,
"source-code" = local.aws_default_tags.source_code
"source-project" = local.aws_default_tags.source_project
}
}
}

# ==================================================================
# PROVIDER - AWS US-EAST-1
# ==================================================================

# Common tags for all resources that accept tags
provider "aws" {
region = "us-east-1"
alias = "us-east-1"
default_tags {
tags = var.tags
tags = {
"automation:managedby" = "terraform",
"cost-allocation:business-unit" = local.aws_default_tags.cost_allocation_business_unit,
"cost-allocation:product" = local.aws_default_tags.cost_allocation_product,
"operation-support:account" = local.aws_default_tags.operation_support_account_name,
"operation-support:criticality" = local.aws_default_tags.operation_support_criticality
"operation-support:environment" = local.aws_default_tags.operation_support_environment,
"operation-support:team" = local.aws_default_tags.operation_support_team,
"source-code" = local.aws_default_tags.source_code
"source-project" = local.aws_default_tags.source_project
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/**
* Configure required Terraform providers
*/
terraform {
required_version = "1.6.2"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.11"
version = "~> 5.38"
}
}
}
6 changes: 0 additions & 6 deletions infra/terraform/setup-ec2/_required_version.tf

This file was deleted.

3 changes: 0 additions & 3 deletions infra/terraform/setup-ec2/_variables.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
* Configure your Terraform variables
*/
variable "aws_region" {
type = string
description = "AWS Region name"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/**
* Setup AWS instances
*/
# ==================================================================
# RESOURCE AWS EC2 - INSTANCE
# ==================================================================

resource "aws_instance" "instance" {
count = var.aws_instance_count

ami = lookup(var.aws_instance_ami, var.aws_region)
instance_type = var.aws_instance_type
user_data = file("${path.root}/files/scripts/run.sh")

tags = {
Name = "instance-${count.index}"
}

user_data = file("./scripts/run.sh")
}
File renamed without changes.
10 changes: 10 additions & 0 deletions infra/terraform/setup-eks/_backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Generated by Terragrunt. Sig: nIlQXj57tbuaRZEa
terraform {
backend "s3" {
bucket = ""
dynamodb_table = ""
encrypt = true
key = "projects/docker-crypto-miner/setup-eks/terraform.tfstate"
region = "us-east-1"
}
}
2 changes: 1 addition & 1 deletion infra/terraform/setup-eks/_datas.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ==================================================================
# AWS
# DATAS - AWS
# ==================================================================

data "aws_caller_identity" "current" {}
Expand Down
22 changes: 22 additions & 0 deletions infra/terraform/setup-eks/_locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
locals {
# ==================================================================
# GENERAL
# ==================================================================
client_name = "lpsm-dev"
# ==================================================================
# AWS GENERAL
# ==================================================================
aws_account_id = data.aws_caller_identity.current.account_id
aws_default_tags = {
cost_allocation_business_unit = "lpsm-dev"
cost_allocation_product = "lpsm-dev"
operation_support_account_name = "${local.client_name}-${local.aws_environment}-services"
operation_support_criticality = "low"
operation_support_environment = local.aws_environment
operation_support_team = "cloud"
source_code = "https://github.com/lpsm-dev/docker-crypto-miner"
source_project = "setup-eks"
}
aws_environment = "develop"
aws_region = "us-east-1"
}
13 changes: 13 additions & 0 deletions infra/terraform/setup-eks/_outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# ==================================================================
# OUTPUTS - AWS
# ==================================================================

output "aws_account_id" {
description = "Selected AWS Account ID"
value = local.aws_account_id
}

output "aws_region" {
description = "Details about selected AWS region"
value = data.aws_region.current.name
}
64 changes: 64 additions & 0 deletions infra/terraform/setup-eks/_providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# ==================================================================
# PROVIDER - AWS DEFAULT
# ==================================================================

provider "aws" {
region = local.aws_region
default_tags {
tags = {
"automation:managedby" = "terraform",
"cost-allocation:business-unit" = local.aws_default_tags.cost_allocation_business_unit,
"cost-allocation:product" = local.aws_default_tags.cost_allocation_product,
"operation-support:account" = local.aws_default_tags.operation_support_account_name,
"operation-support:criticality" = local.aws_default_tags.operation_support_criticality
"operation-support:environment" = local.aws_default_tags.operation_support_environment,
"operation-support:team" = local.aws_default_tags.operation_support_team,
"source-code" = local.aws_default_tags.source_code
"source-project" = local.aws_default_tags.source_project
}
}
}

# ==================================================================
# PROVIDER - AWS SA-EAST-1
# ==================================================================

provider "aws" {
region = "sa-east-1"
alias = "sa-east-1"
default_tags {
tags = {
"automation:managedby" = "terraform",
"cost-allocation:business-unit" = local.aws_default_tags.cost_allocation_business_unit,
"cost-allocation:product" = local.aws_default_tags.cost_allocation_product,
"operation-support:account" = local.aws_default_tags.operation_support_account_name,
"operation-support:criticality" = local.aws_default_tags.operation_support_criticality
"operation-support:environment" = local.aws_default_tags.operation_support_environment,
"operation-support:team" = local.aws_default_tags.operation_support_team,
"source-code" = local.aws_default_tags.source_code
"source-project" = local.aws_default_tags.source_project
}
}
}

# ==================================================================
# PROVIDER - AWS US-EAST-1
# ==================================================================

provider "aws" {
region = "us-east-1"
alias = "us-east-1"
default_tags {
tags = {
"automation:managedby" = "terraform",
"cost-allocation:business-unit" = local.aws_default_tags.cost_allocation_business_unit,
"cost-allocation:product" = local.aws_default_tags.cost_allocation_product,
"operation-support:account" = local.aws_default_tags.operation_support_account_name,
"operation-support:criticality" = local.aws_default_tags.operation_support_criticality
"operation-support:environment" = local.aws_default_tags.operation_support_environment,
"operation-support:team" = local.aws_default_tags.operation_support_team,
"source-code" = local.aws_default_tags.source_code
"source-project" = local.aws_default_tags.source_project
}
}
}
4 changes: 2 additions & 2 deletions infra/terraform/setup-eks/_required.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
terraform {
required_version = "~> 1.7"
required_version = "1.6.2"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.31"
version = "~> 5.38"
}
}
}
Empty file.
Empty file.
Loading

0 comments on commit 2f87715

Please sign in to comment.