-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
name: Helm release Nginx | ||
on: | ||
push: | ||
branches: | ||
- 'main' | ||
- 'feature/**' | ||
- 'hotfix/**' | ||
- 'bug/**' | ||
- 'test/**' | ||
paths: | ||
- 'releases/**' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
Test: | ||
if: always() && github.ref != 'refs/heads/main' | ||
environment: Test | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: releases/ | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: hashicorp/setup-terraform@v2 | ||
- name: Terraform fmt | ||
id: fmt | ||
run: terraform fmt -check | ||
continue-on-error: true | ||
|
||
- name: Terraform Init | ||
id: init | ||
run: terraform init -backend-config="access_key=${{ secrets.AWS_ACCESS_KEY_ID }}" -backend-config="secret_key=${{ secrets.AWS_SECRET_ACCESS_KEY }}" -backend-config="key=${{ vars.ENVIRONMENT }}/${{ vars.APP_NAME }}/infrastructure/${{ vars.AWS_REGION }}.tfstate" | ||
|
||
- name: Terraform Validate | ||
id: validate | ||
run: terraform validate -no-color | ||
|
||
- name: Terraform Plan | ||
id: plan | ||
run: terraform plan -var "AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }}" -var "AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}" -var "AWS_REGION=${{ vars.AWS_REGION }}" -var "app_name=${{ vars.APP_NAME }}" -var "environment=${{ vars.ENVIRONMENT }}" | ||
continue-on-error: true | ||
|
||
- uses: actions/github-script@v6 | ||
if: github.event_name == 'pull_request' | ||
env: | ||
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}" | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\` | ||
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` | ||
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\` | ||
<details><summary>Validation Output</summary> | ||
\`\`\`\n | ||
${{ steps.validate.outputs.stdout }} | ||
\`\`\` | ||
</details> | ||
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\` | ||
<details><summary>Show Plan</summary> | ||
\`\`\`\n | ||
${process.env.PLAN} | ||
\`\`\` | ||
</details> | ||
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ env.tf_actions_working_dir }}\`, Workflow: \`${{ github.workflow }}\`*`; | ||
github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: output | ||
}) | ||
Deploy-test: | ||
if: success() && github.ref != 'refs/heads/main' | ||
needs: Test | ||
environment: Test | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: releases/ | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: hashicorp/setup-terraform@v2 | ||
|
||
- name: Terraform Init | ||
id: init | ||
run: terraform init -backend-config="access_key=${{ secrets.AWS_ACCESS_KEY_ID }}" -backend-config="secret_key=${{ secrets.AWS_SECRET_ACCESS_KEY }}" -backend-config="key=${{ vars.ENVIRONMENT }}/${{ vars.APP_NAME }}/infrastructure/${{ vars.AWS_REGION }}.tfstate" | ||
|
||
- name: Terraform Apply | ||
id: apply | ||
run: terraform apply -var "AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }}" -var "AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}" -var "AWS_REGION=${{ vars.AWS_REGION }}" -var "app_name=${{ vars.APP_NAME }}" -var "environment=${{ vars.ENVIRONMENT }}" -auto-approve |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Configure terraform backend | ||
terraform { | ||
backend "s3" { | ||
bucket = "kmartinez-projects" | ||
region = "us-east-1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Cluster Auth for kubernetes provider | ||
data "aws_eks_cluster" "eks_cluster" { | ||
name = "${var.environment}-${var.app_name}-cluster-${var.AWS_REGION}" | ||
|
||
} | ||
data "aws_eks_cluster_auth" "cluster_auth" { | ||
name = "${var.environment}-${var.app_name}-cluster-${var.AWS_REGION}" | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
resource "helm_release" "prometheus" { | ||
chart = "nginx" | ||
name = "nginx" | ||
namespace = "${var.environment}-${var.app_name}-ns-${var.AWS_REGION}" | ||
repository = "https://https://ken501.github.io/gitchartrepo/" | ||
version = "0.1.0" | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
terraform { | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 4.0" | ||
} | ||
} | ||
} | ||
|
||
// Configure the AWS Provider | ||
provider "aws" { | ||
region = var.AWS_REGION | ||
access_key = var.AWS_ACCESS_KEY_ID | ||
secret_key = var.AWS_SECRET_ACCESS_KEY | ||
} | ||
// Configure the Helm Provider | ||
provider "helm" { | ||
kubernetes { | ||
host = data.aws_eks_cluster.eks_cluster.endpoint | ||
cluster_ca_certificate = base64decode(data.aws_eks_cluster.eks_cluster.certificate_authority[0].data) | ||
token = data.aws_eks_cluster_auth.cluster_auth.token | ||
exec { | ||
api_version = "client.authentication.k8s.io/v1beta1" | ||
args = ["eks", "get-token", "--cluster-name", data.aws_eks_cluster.eks_cluster.id] | ||
command = "aws" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Common Variables | ||
|
||
variable "AWS_ACCESS_KEY_ID" { | ||
description = "AWS Access key" | ||
type = string | ||
} | ||
|
||
variable "AWS_SECRET_ACCESS_KEY" { | ||
description = "AWS Secret key" | ||
type = string | ||
} | ||
|
||
variable "AWS_REGION" { | ||
description = "AWS preferred region" | ||
type = string | ||
} | ||
|
||
variable "app_name" { | ||
description = "Application name" | ||
type = string | ||
} | ||
|
||
variable "environment" { | ||
description = "Application lifecycle stage" | ||
type = string | ||
} | ||
|
||
variable "additional_tags" { | ||
description = "Tags used to identify the project and other details" | ||
default = {} | ||
type = map(string) | ||
} |