Skip to content

Commit

Permalink
add infra folder and inital workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
jburns24 committed Sep 8, 2023
1 parent 1a97c61 commit a1dc4ad
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/build-infra.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Build Infra

on:
push:
branches:
- main
paths:
- './infra/**'
workflow_dispatch: {}

jobs:
run:
name: run
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

# Install the terraform and terragrunt
# - uses: alexellis/setup-arkade@v1
# - uses: alexellis/arkade-get@master
# with:
# terraform: latest
# terragrunt: latest

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.PERSONAL_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.PERSONAL_SECRET_ACCESS_KEY }}
role-to-assume: ${{ vars.ROLE_TO_ASSUME }}
aws-region: ${{ vars.AWS_REGION }}

# Display IAM Identity
- name: Display IAM Identity
run: |
aws sts get-caller-identity
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,19 @@ notes
.env

*.tsbuildinfo

# Terragrunt/Terraform files https://raw.githubusercontent.com/gruntwork-io/terragrunt/f6ab8991f4f318343db3321691ac37fa366c8762/.gitignore
.*.sw?
.idea
terragrunt.iml
vendor
.terraform
.vscode
*.tfstate
*.tfstate.backup
*.out
.terragrunt-cache
.bundle
.ruby-version
.terraform.lock.hcl
terragrunt
24 changes: 24 additions & 0 deletions infra/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
remote_state {
backend = "s3"
generate = {
path = "backend.tf"
if_exists = "overwrite_terragrunt"
}
config = {
bucket = "keyless-workflow-demo"
key = "keyless-workflow-demo/terraform.tfstate"

region = "us-west-2"
dynamodb_table = "tflocks"
disable_bucket_update = true

# Permissions thing
skip_bucket_versioning = true

encrypt = true
}
}

terraform {
source = ".//tf"
}
3 changes: 3 additions & 0 deletions infra/tf/_outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "knowledgeshare_ecr_url" {
value = aws_ecr_repository.knowledgeshare_ui_ecr.repository_url
}
12 changes: 12 additions & 0 deletions infra/tf/_terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
}
}
}

provider "aws" {
region = "us-west-2"
}
5 changes: 5 additions & 0 deletions infra/tf/_varibales.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
variable "name" {
type = string
description = "The Repository Name"
default = "keyless-workflow-demo"
}
8 changes: 8 additions & 0 deletions infra/tf/ecr.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
resource "aws_ecr_repository" "knowledgeshare_ui_ecr" {
name = var.name
image_tag_mutability = "MUTABLE"

image_scanning_configuration {
scan_on_push = true
}
}
34 changes: 34 additions & 0 deletions infra/tf/ecs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
resource "aws_ecs_cluster" "knowledgeshare_ui_ecs_cluster" {
name = "knowledgeshare-demo"
setting {
name = "containerInsights"
value = "enabled"
}
}

resource "aws_ecs_task_definition" "knowledgeshare_ui_task" {
family = "knowledgeshare-service"
container_definitions = jsonencode([{
name = "knowledgeshare-ui"
image = "${aws_ecr_repository.knowledgeshare_ui_ecr.repository_url}:latest"
memory = 512
essential = true
portMappings = [
{
containerPort = 8080
hostPort = 80
}
]
}])
}

resource "aws_ecs_service" "knowledgeshare_ui_service" {
name = "knowledgeshare_ui"
cluster = aws_ecs_cluster.knowledgeshare_ui_ecs_cluster.id
task_definition = aws_ecs_task_definition.knowledgeshare_ui_task.arn
desired_count = 2
force_new_deployment = true
# iam_role = aws_iam_role.foo.arn
# depends_on = [aws_iam_role_policy.foo]

}

0 comments on commit a1dc4ad

Please sign in to comment.