Skip to content

Stage #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 58 commits into
base: stage
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
45d654e
Merge pull request #1 from hkhcoder/stage
hkhcoder Nov 13, 2023
4f25818
initialize
geofLegrand Jan 5, 2025
3c4e8a3
add github action folder
geofLegrand Jan 5, 2025
4686681
add github action folder
geofLegrand Jan 5, 2025
f0c1882
Create main.yml
geofLegrand Jan 5, 2025
725b946
Delete .github/workflows directory
geofLegrand Jan 5, 2025
723e7cd
Update README.md
geofLegrand Jan 5, 2025
2c6263b
Create terraform.yml
geofLegrand Jan 5, 2025
4f99cff
Update terraform.yml
geofLegrand Jan 5, 2025
cc68421
Update README.md
geofLegrand Jan 5, 2025
83d1b34
Update terraform.yml
geofLegrand Jan 5, 2025
993b286
Delete .github/workflows directory
geofLegrand Jan 5, 2025
5d78cc0
Create terraform.yml
geofLegrand Jan 5, 2025
22c374f
Update README.md
geofLegrand Jan 5, 2025
b3d2a59
Update README.md
geofLegrand Jan 5, 2025
b9fe28a
Delete .github/workflows directory
geofLegrand Jan 5, 2025
729cd04
Create terraform.yml
geofLegrand Jan 5, 2025
2f97ff5
Update README.md
geofLegrand Jan 5, 2025
f5a3589
Update terraform.yml
geofLegrand Jan 5, 2025
762c024
Update terraform.yml
geofLegrand Jan 5, 2025
25fe8ee
Update README.md
geofLegrand Jan 5, 2025
27e9796
Update terraform.yml
geofLegrand Jan 5, 2025
d0ef3e0
update the terraform.yml file
geofLegrand Jan 5, 2025
dc902c5
Delete .github/workflows directory
geofLegrand Jan 5, 2025
6216536
update
geofLegrand Jan 5, 2025
fa3e80d
update
geofLegrand Jan 5, 2025
44da521
update
geofLegrand Jan 5, 2025
9ebc54b
update
geofLegrand Jan 5, 2025
e4a5bca
update
geofLegrand Jan 5, 2025
e686909
update
geofLegrand Jan 5, 2025
1e11732
update
geofLegrand Jan 5, 2025
0d7560c
update
geofLegrand Jan 5, 2025
1380b04
update
geofLegrand Jan 5, 2025
bb00517
Implement the github action
geofLegrand Jan 5, 2025
7453060
Implement the github action
geofLegrand Jan 5, 2025
a2cfb80
Implement the github action
geofLegrand Jan 5, 2025
15d0907
Add aws credentials
geofLegrand Jan 5, 2025
a969b09
Configure eks and add Ingress
geofLegrand Jan 6, 2025
f299d4b
add checkov to scan terraform code
geofLegrand Jan 6, 2025
433bb50
add checkov to scan terraform code
geofLegrand Jan 6, 2025
3d3166d
add checkov to scan terraform code
geofLegrand Jan 6, 2025
5e093a8
merging
geofLegrand Jan 6, 2025
decb74b
merging
geofLegrand Jan 6, 2025
477a983
merging
geofLegrand Jan 6, 2025
8f6bcab
merging
geofLegrand Jan 6, 2025
79e6ddc
merging
geofLegrand Jan 6, 2025
20efbda
merging
geofLegrand Jan 6, 2025
91c9050
merging
geofLegrand Jan 7, 2025
0e4f792
merging
geofLegrand Jan 7, 2025
f70dcc1
update date
geofLegrand Jan 7, 2025
6168e30
update date
geofLegrand Jan 7, 2025
629f3d6
data
geofLegrand Jan 7, 2025
c534b11
Update README.md
geofLegrand Jan 7, 2025
9865c69
Merge pull request #5 from geofLegrand/geofLegrand-patch-5
geofLegrand Jan 7, 2025
e942c86
Update terraform.yml
geofLegrand Jan 7, 2025
e52183e
Merge pull request #6 from geofLegrand/geofLegrand-terraform-destroy-6
geofLegrand Jan 7, 2025
a25097e
show checkov result on the windows
geofLegrand Jan 10, 2025
96d3285
Merge branch 'main' into stage
geofLegrand Jan 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 142 additions & 0 deletions .github/workflows/terraform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
name: "Vprofile IAC"

on:

push:
branches: ["main","stage"]
pull_request:
branches: ["main"]
env:
AWS_ACCESS_KEY_ID : ${{secrets.AWS_ACCESS_KEY_ID}}
AWS_SECRET_ACCESS_KEY: ${{secrets.AWS_SECRET_ACCESS_KEY}}
BUCKET_TF_STATE: ${{secrets.BUCKET_TF_STATE}}
AWS_REGION: us-east-1
EKS_CLUSTER: vprofile-eks
TF_VERSION: 1.6.3
WORKING_DIRECTORY: terraform
permissions:
issues: write
contents: read
pull-requests: write

jobs:
scan-terraform-config:
name: "Scan terraform with Checkov"
runs-on: ubuntu-latest

steps:
- name: Checkout source code
uses: actions/checkout@v4

- name: Run Checkov
id: checkov
uses: bridgecrewio/checkov-action@master
with:
directory: ${{env.WORKING_DIRECTORY}}
soft_fail: true

outputs:
checkov_report: ${{ steps.checkov.outputs.results }}


deploy-infra-terraform:
name: "Apply terraform code changes"
runs-on: ubuntu-latest
environment: production
needs: [scan-terraform-config] # create the dependance for the job 01
defaults:
run:
shell: bash
working-directory: ${{env.WORKING_DIRECTORY}}

steps:
- name: Checkout source code
uses: actions/checkout@v4

- name: Setup terraform with specified version on the runner
uses: hashicorp/setup-terraform@v1
with:
terraform_version: "${{env.TF_VERSION}}"
# Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
- name: Terraform Init
id: init
run: terraform init -backend-config="bucket=$BUCKET_TF_STATE"

# Checks that all Terraform configuration files adhere to a canonical format
- name: Terraform Format
id: fmt
run: terraform fmt -check

- name: Terraform validate
id: validate
run: terraform validate -no-color

# Generates an execution plan for Terraform
- name: Terraform Plan
id: plan
# -input=false -out plan.out
if: github.event_name == 'pull_request'
run: terraform plan -no-color
continue-on-error: true

- name: Terraform plan status
if: steps.plan.outcome == 'failure'
run: exit 1

- name: Add terraform plan comment
id: comment
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}}
# , Working Directory: \`${{ env.tf_actions_working_dir }}\`
script: |
const output = `#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### Terraform Validation 🤖${{ steps.validate.outputs.stdout }}
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`

<details><summary>Show Plan</summary>

\`\`\`${process.env.PLAN}\`\`\`

</details>

*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Workflow: \`${{ github.workflow }}\`*`;

github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})

- name: Terraform apply
id: appl
if: github.ref == 'refs/heads/main' && github.event_name == 'push'

run: terraform apply -auto-approve

# -input=false -parallelism=1 plan.out

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: ${{env.AWS_REGION}}
aws-access-key-id: ${{secrets.AWS_ACCESS_KEY_ID}}
aws-secret-access-key: ${{secrets.AWS_SECRET_ACCESS_KEY}}

- name: Get K8s config file
id: getconfig
if: steps.appl.outcome == 'success'
run: aws eks update-kubeconfig --region ${{env.AWS_REGION}} --name ${{env.EKS_CLUSTER}}

- name: Install ingress controller
if: steps.appl.outcome == 'success' && steps.getconfig.outcome == 'success'
run: kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.3/deploy/static/provider/aws/deploy.yaml




18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
# Terraform code
# Terraform code

## Maintain vpc & eks with terraform for vprofile project

## Tools required
Terraform version 1.6.3

### Steps
* terraform init
<<<<<<< HEAD
#### Steps
=======
### Steps from scratch
>>>>>>> stage
* terraform init
* terraform fmt -check
* terraform validate
* terraform plan -out planfile
* terraform plan -no-color -out planfile
* terraform apply -auto-approve -input=false -parallelism=1 planfile
####

######
######

#####
#####
2 changes: 1 addition & 1 deletion terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ locals {
cluster_name = var.clusterName
}

##
###
6 changes: 3 additions & 3 deletions terraform/terraform.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ terraform {
}

backend "s3" {
bucket = "gitopsterrastate"
key = "terraform.tfstate"
region = "us-east-2"
bucket = "vprofileaction3"
key = "dev/terraform.tfstate"
region = "us-east-1"
}

required_version = "~> 1.6.3"
Expand Down
4 changes: 2 additions & 2 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
variable "region" {
description = "AWS region"
type = string
default = "us-east-2"
default = "us-east-1"
}

variable "clusterName" {
description = "Name of the EKS cluster"
type = string
default = "kitops-eks"
default = "vprofile-eks"
}