From a560e1cbf627d9343c4b4c61fdae55ea2722800c Mon Sep 17 00:00:00 2001 From: Vamshi_Kesari <118153587+kesarivamshi@users.noreply.github.com> Date: Thu, 24 Nov 2022 19:33:49 +0530 Subject: [PATCH 01/21] Update vars.yml --- Ansible/vars.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Ansible/vars.yml b/Ansible/vars.yml index 1fad5cc..8f73067 100644 --- a/Ansible/vars.yml +++ b/Ansible/vars.yml @@ -4,7 +4,7 @@ server_name: dev2.snipeit.com #REPO -repo: https://github.com/PearlThoughts-Platform/Snipe-IT-GitHub-Actions +repo: https://github.com/kesarivamshi/Snipe-IT-GitHub-Actions.git repo_branch: devcontainer api_project_dir: /srv/Snipe-IT-GitHub-Actions api1_secret_name: smw ## store the .env values in AWS secret manager as a json key pair values and mention the secret name. @@ -52,4 +52,4 @@ php_extensions: host_user: ubuntu -group_name: deploy \ No newline at end of file +group_name: deploy From d23d16b48e1b512ca5f1c267684110f3e01093b0 Mon Sep 17 00:00:00 2001 From: Vamshi_Kesari <118153587+kesarivamshi@users.noreply.github.com> Date: Thu, 24 Nov 2022 19:37:50 +0530 Subject: [PATCH 02/21] Update ami.pkr.hcl --- ami.pkr.hcl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ami.pkr.hcl b/ami.pkr.hcl index 50e1a02..f4dee39 100644 --- a/ami.pkr.hcl +++ b/ami.pkr.hcl @@ -14,9 +14,9 @@ packer { source "amazon-ebs" "linux" { # AMI Settings - ami_name = "snipeitdev_goldenAMI_${var.build_number}" - instance_type = "c5.large" - source_ami = "ami-00978328f54e31526" + ami_name = "snipeit_goldenAMI_${var.build_number}" + instance_type = "t2.micro" + source_ami = "ami-08c40ec9ead489470" ssh_username = "ubuntu" associate_public_ip_address = false ami_virtualization_type = "hvm" @@ -60,4 +60,4 @@ packer { playbook_file = "Ansible/main.yml" user = "ubuntu" } - } \ No newline at end of file + } From b9f429605ad85221278a3aed77abbd55e0b90cfa Mon Sep 17 00:00:00 2001 From: Vamshi_Kesari <118153587+kesarivamshi@users.noreply.github.com> Date: Thu, 24 Nov 2022 19:46:30 +0530 Subject: [PATCH 03/21] Update provider.tf --- terraform/provider.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/terraform/provider.tf b/terraform/provider.tf index 156ad15..6239ab2 100644 --- a/terraform/provider.tf +++ b/terraform/provider.tf @@ -1,7 +1,7 @@ provider "aws" { region = "us-east-1" - access_key = "AKIAQWYSZRJYQM5d4" - secret_key = "adeZNE1Id82orq/yt9VI36R7/iBS5JPwmabddd" + access_key = "AKIAR6HMURYL22YOQJ4L" + secret_key = "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" } From 0aecba308901e0a95ab066f5d27736622a73fa2c Mon Sep 17 00:00:00 2001 From: Vamshi_Kesari <118153587+kesarivamshi@users.noreply.github.com> Date: Thu, 24 Nov 2022 19:47:18 +0530 Subject: [PATCH 04/21] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 197d76b..6f4bcc8 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Every commit will automatically creates AMI ``` ### Terraform for Infra provisioning terraform folder - +.... ### Demo Video For Reference From 39f6bc269b924417e5a1775c474cde52947b6125 Mon Sep 17 00:00:00 2001 From: Vamshi_Kesari <118153587+kesarivamshi@users.noreply.github.com> Date: Thu, 24 Nov 2022 20:09:23 +0530 Subject: [PATCH 05/21] Update ami.pkr.hcl --- ami.pkr.hcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ami.pkr.hcl b/ami.pkr.hcl index f4dee39..85e8ec0 100644 --- a/ami.pkr.hcl +++ b/ami.pkr.hcl @@ -16,7 +16,7 @@ packer { # AMI Settings ami_name = "snipeit_goldenAMI_${var.build_number}" instance_type = "t2.micro" - source_ami = "ami-08c40ec9ead489470" + source_ami = "ami-0f69dd1d0d03ad669" ssh_username = "ubuntu" associate_public_ip_address = false ami_virtualization_type = "hvm" From 63616bed258f9fb4471c05ade8ddabb49da6257e Mon Sep 17 00:00:00 2001 From: Vamshi_Kesari <118153587+kesarivamshi@users.noreply.github.com> Date: Thu, 24 Nov 2022 20:14:47 +0530 Subject: [PATCH 06/21] Update ami.pkr.hcl --- ami.pkr.hcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ami.pkr.hcl b/ami.pkr.hcl index 85e8ec0..f6c362c 100644 --- a/ami.pkr.hcl +++ b/ami.pkr.hcl @@ -48,7 +48,7 @@ packer { } # Profile Settings - region = "us-east-2" + region = "us-east-1" ami_regions = ["us-east-1"] } From 10c316c6573fbbf702b39b9bdfc3489c8b71931a Mon Sep 17 00:00:00 2001 From: Vamshi_Kesari <118153587+kesarivamshi@users.noreply.github.com> Date: Thu, 24 Nov 2022 20:19:47 +0530 Subject: [PATCH 07/21] Update ami.pkr.hcl --- ami.pkr.hcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ami.pkr.hcl b/ami.pkr.hcl index f6c362c..b2544b9 100644 --- a/ami.pkr.hcl +++ b/ami.pkr.hcl @@ -16,7 +16,7 @@ packer { # AMI Settings ami_name = "snipeit_goldenAMI_${var.build_number}" instance_type = "t2.micro" - source_ami = "ami-0f69dd1d0d03ad669" + source_ami = "ami-08c40ec9ead489470" ssh_username = "ubuntu" associate_public_ip_address = false ami_virtualization_type = "hvm" From 61daf9ed5586f9b1bf7e69125d2f4476b83ac81e Mon Sep 17 00:00:00 2001 From: Sai Date: Fri, 25 Nov 2022 12:16:33 +0530 Subject: [PATCH 08/21] add ec2-terraform --- ec2-terraform/aws-cerd.tf | 6 ++++++ ec2-terraform/main.tf | 10 ++++++++++ ec2-terraform/resaws.tf | 4 ++++ ec2-terraform/rest.tf | 17 +++++++++++++++++ ec2-terraform/sec.tf | 28 ++++++++++++++++++++++++++++ ec2-terraform/var.tf | 7 +++++++ 6 files changed, 72 insertions(+) create mode 100644 ec2-terraform/aws-cerd.tf create mode 100644 ec2-terraform/main.tf create mode 100644 ec2-terraform/resaws.tf create mode 100644 ec2-terraform/rest.tf create mode 100644 ec2-terraform/sec.tf create mode 100644 ec2-terraform/var.tf diff --git a/ec2-terraform/aws-cerd.tf b/ec2-terraform/aws-cerd.tf new file mode 100644 index 0000000..9f4d7c7 --- /dev/null +++ b/ec2-terraform/aws-cerd.tf @@ -0,0 +1,6 @@ +provider "aws" { + profile = "default" + region = "eu-central-1" + access_key = var.AWS_ACCESS_KEY_ID + secret_key = var.AWS_SECRET_ACCESS_KEY +} \ No newline at end of file diff --git a/ec2-terraform/main.tf b/ec2-terraform/main.tf new file mode 100644 index 0000000..534d413 --- /dev/null +++ b/ec2-terraform/main.tf @@ -0,0 +1,10 @@ +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 3.27" + } + } + + required_version = ">= 1.0.4" +} \ No newline at end of file diff --git a/ec2-terraform/resaws.tf b/ec2-terraform/resaws.tf new file mode 100644 index 0000000..5860de9 --- /dev/null +++ b/ec2-terraform/resaws.tf @@ -0,0 +1,4 @@ +resource "aws_key_pair" "deployer" { + key_name = "ec2-deployer-key-pair" + public_key = "your public_key look like that ssh-rsa AAAAB3Nā€¦ā€ +} \ No newline at end of file diff --git a/ec2-terraform/rest.tf b/ec2-terraform/rest.tf new file mode 100644 index 0000000..dc9222c --- /dev/null +++ b/ec2-terraform/rest.tf @@ -0,0 +1,17 @@ +resource "aws_instance" "app_server" { + count = 2 + ami = "ami-047e03b8591f2d48a" + instance_type = "t2.micro" + key_name = "ec2-deployer-key-pair" + vpc_security_group_ids = [aws_security_group.main.id] + + tags = { + Name = "First-Ec2-With-Terraform" + } + connection { + type = "ssh" + host = self.public_ip + user = "ec2-user" + timeout = "4m" + } +} \ No newline at end of file diff --git a/ec2-terraform/sec.tf b/ec2-terraform/sec.tf new file mode 100644 index 0000000..7d80ae8 --- /dev/null +++ b/ec2-terraform/sec.tf @@ -0,0 +1,28 @@ +resource "aws_security_group" "main" { + egress = [ + { + cidr_blocks = ["0.0.0.0/0", ] + description = "" + from_port = 0 + ipv6_cidr_blocks = [] + prefix_list_ids = [] + protocol = "-1" + security_groups = [] + self = false + to_port = 0 + } + ] + ingress = [ + { + cidr_blocks = ["0.0.0.0/0", ] + description = "" + from_port = 22 + ipv6_cidr_blocks = [] + prefix_list_ids = [] + protocol = "tcp" + security_groups = [] + self = false + to_port = 22 + } + ] +} \ No newline at end of file diff --git a/ec2-terraform/var.tf b/ec2-terraform/var.tf new file mode 100644 index 0000000..8d37aff --- /dev/null +++ b/ec2-terraform/var.tf @@ -0,0 +1,7 @@ +variable "AWS_ACCESS_KEY_ID" { + type = string +} + +variable "AWS_SECRET_ACCESS_KEY" { + type = string +} \ No newline at end of file From bf887a8852b4d5a0ed031e154735ba40a77ff18d Mon Sep 17 00:00:00 2001 From: Vamshi_Kesari <118153587+kesarivamshi@users.noreply.github.com> Date: Fri, 25 Nov 2022 12:27:21 +0530 Subject: [PATCH 09/21] Update rest.tf --- ec2-terraform/rest.tf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ec2-terraform/rest.tf b/ec2-terraform/rest.tf index dc9222c..159402d 100644 --- a/ec2-terraform/rest.tf +++ b/ec2-terraform/rest.tf @@ -1,6 +1,6 @@ resource "aws_instance" "app_server" { - count = 2 - ami = "ami-047e03b8591f2d48a" + count = 1 + ami = "ami-08c40ec9ead489470" instance_type = "t2.micro" key_name = "ec2-deployer-key-pair" vpc_security_group_ids = [aws_security_group.main.id] @@ -11,7 +11,7 @@ resource "aws_instance" "app_server" { connection { type = "ssh" host = self.public_ip - user = "ec2-user" + user = "ubuntu" timeout = "4m" } -} \ No newline at end of file +} From e00e246a2ad4147a0e8454ccdfd22165da62da87 Mon Sep 17 00:00:00 2001 From: Sai Date: Fri, 25 Nov 2022 12:34:35 +0530 Subject: [PATCH 10/21] added terraform.yml --- ec2-terraform/.github/workflows/terraform.yml | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 ec2-terraform/.github/workflows/terraform.yml diff --git a/ec2-terraform/.github/workflows/terraform.yml b/ec2-terraform/.github/workflows/terraform.yml new file mode 100644 index 0000000..b95d158 --- /dev/null +++ b/ec2-terraform/.github/workflows/terraform.yml @@ -0,0 +1,70 @@ +name: "Terraform" + +on: + push: + branches: + - main + pull_request: + +jobs: + terraform: + name: "Terraform" + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup Terraform + uses: hashicorp/setup-terraform@v1 + with: + # terraform_version: 0.13.0: + cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} + + - name: Terraform Format + id: fmt + run: terraform fmt -check + + - name: Terraform Init + id: init + run: terraform init + + - name: Terraform Validate + id: validate + run: terraform validate -no-color + + - name: Terraform Plan + id: plan + if: github.event_name == 'pull_request' + run: terraform plan -no-color + continue-on-error: true + + - uses: actions/github-script@0.9.0 + 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 }}\` + #### Terraform Plan šŸ“–\`${{ steps.plan.outcome }}\` +
Show Plan + \`\`\`\n + ${process.env.PLAN} + \`\`\` +
+ *Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; + github.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: output + }) + - name: Terraform Plan Status + if: steps.plan.outcome == 'failure' + run: exit 1 + + - name: Terraform Apply + if: github.ref == 'refs/heads/main' && github.event_name == 'push' + run: terraform apply -auto-approve \ No newline at end of file From 0b27965b877aec9a167f45cceed02755f77261a7 Mon Sep 17 00:00:00 2001 From: Vamshi_Kesari <118153587+kesarivamshi@users.noreply.github.com> Date: Fri, 25 Nov 2022 12:43:05 +0530 Subject: [PATCH 11/21] Update main.yml --- terraform/.github/workflows/main.yml | 128 +++++++++++++-------------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/terraform/.github/workflows/main.yml b/terraform/.github/workflows/main.yml index 2c7cdfd..cac98dc 100644 --- a/terraform/.github/workflows/main.yml +++ b/terraform/.github/workflows/main.yml @@ -1,64 +1,64 @@ -# name: "Terraform Deployment" -# on: -# # Manual trigger -# workflow_dispatch: -# push: -# paths: -# - '*/**' -# pull_request: -# branches: [ main ] -# defaults: -# run: -# shell: bash -# jobs: -# terraform: -# name: ${{matrix.runner}} - ${{ matrix.environment }} -# runs-on: [ '${{ matrix.runner }}'] -# strategy: -# max-parallel: 1 -# matrix: -# include: -# - environment: test -# runner: ubuntu-latest -# - environment: prod -# runner: ubuntu-18.04 -# env: -# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} -# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} -# AWS_DEFAULT_REGION: us-east-2 -# steps: -# - uses: actions/checkout@v2 -# - uses: hashicorp/setup-terraform@v1 -# with: -# terraform_wrapper: false -# - name: Terraform Init -# id: init -# run: | -# rm -rf .terraform -# terraform init -upgrade=true -no-color -input=false -# - name: Terraform Plan -# id: plan -# run: | -# terraform plan -input=false -no-color -# - name: Terraform Apply -# if: github.ref == 'refs/heads/main' -# id: apply -# run: terraform apply -auto-approve -input=false -# - name: Terraform destroy -# if: github.ref == 'refs/heads/destroy' -# id: destroy -# run: terraform destroy -auto-approve -input=false -# comment: -# runs-on: ubuntu-latest -# needs: terraform -# if: github.event_name == 'pull_request' -# steps: -# - uses: actions/github-script@v5 -# with: -# script: | -# github.rest.issues.createComment({ -# issue_number: context.issue.number, -# owner: context.repo.owner, -# repo: context.repo.repo, -# body: 'šŸ‘‹ Thanks for reporting!' -# }) \ No newline at end of file +name: "Terraform Deployment" +on: + # Manual trigger + workflow_dispatch: + push: + paths: + - '*/**' + pull_request: + branches: [ main ] +defaults: + run: + shell: bash +jobs: + terraform: + name: ${{matrix.runner}} - ${{ matrix.environment }} + runs-on: [ '${{ matrix.runner }}'] + strategy: + max-parallel: 1 + matrix: + include: + - environment: test + runner: ubuntu-latest + - environment: prod + runner: ubuntu-18.04 + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: us-east-2 + steps: + - uses: actions/checkout@v2 + - uses: hashicorp/setup-terraform@v1 + with: + terraform_wrapper: false + - name: Terraform Init + id: init + run: | + rm -rf .terraform + terraform init -upgrade=true -no-color -input=false + - name: Terraform Plan + id: plan + run: | + terraform plan -input=false -no-color + - name: Terraform Apply + if: github.ref == 'refs/heads/main' + id: apply + run: terraform apply -auto-approve -input=false + - name: Terraform destroy + if: github.ref == 'refs/heads/destroy' + id: destroy + run: terraform destroy -auto-approve -input=false + comment: + runs-on: ubuntu-latest + needs: terraform + if: github.event_name == 'pull_request' + steps: + - uses: actions/github-script@v5 + with: + script: | + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: 'šŸ‘‹ Thanks for reporting!' + }) From f51ab9713a7c05e5e04e538e040deb53570af5e3 Mon Sep 17 00:00:00 2001 From: Vamshi_Kesari <118153587+kesarivamshi@users.noreply.github.com> Date: Fri, 25 Nov 2022 13:10:55 +0530 Subject: [PATCH 12/21] Update packer.yml --- .github/workflows/packer.yml | 68 ++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/.github/workflows/packer.yml b/.github/workflows/packer.yml index ffad9ed..df059e8 100644 --- a/.github/workflows/packer.yml +++ b/.github/workflows/packer.yml @@ -1,41 +1,41 @@ -name: containerr -on: push +# name: containerr +# on: push -jobs: - container: - #needs: [s3deploy] - runs-on: ubuntu-18.04 - container: pearlthoughts/p2p-packer:latest - steps: - # - uses: trstringer/manual-approval@v1 - # with: - # secret: ${{ github.TOKEN }} - # approvers: tejapearlthoughts - - uses: actions/checkout@v2 - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - #aws_session_token: ${{ secrets.AWS_SESSION_TOKEN}} - aws-region: us-east-1 - - run: | - repo_name=${{ github.event.repository.name }} - git config --global --add safe.directory /__w/$repo_name/$repo_name - git_hash=$(git rev-parse --short "$GITHUB_SHA") - echo "$SSH_KEY" > /__w/$repo_name/$repo_name/Ansible/id_rsa - packer init . - packer build \ - -var "build_number=$GITHUB_RUN_NUMBER" \ - -var "commit_sha=$git_hash" . +# jobs: +# container: +# #needs: [s3deploy] +# runs-on: ubuntu-18.04 +# container: pearlthoughts/p2p-packer:latest +# steps: +# # - uses: trstringer/manual-approval@v1 +# # with: +# # secret: ${{ github.TOKEN }} +# # approvers: tejapearlthoughts +# - uses: actions/checkout@v2 +# - name: Configure AWS Credentials +# uses: aws-actions/configure-aws-credentials@v1 +# with: +# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} +# aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} +# #aws_session_token: ${{ secrets.AWS_SESSION_TOKEN}} +# aws-region: us-east-1 +# - run: | +# repo_name=${{ github.event.repository.name }} +# git config --global --add safe.directory /__w/$repo_name/$repo_name +# git_hash=$(git rev-parse --short "$GITHUB_SHA") +# echo "$SSH_KEY" > /__w/$repo_name/$repo_name/Ansible/id_rsa +# packer init . +# packer build \ +# -var "build_number=$GITHUB_RUN_NUMBER" \ +# -var "commit_sha=$git_hash" . - name: Run in container - env: - SSH_KEY: ${{ secrets.SSH_KEY }} - # aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - # aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} +# name: Run in container +# env: +# SSH_KEY: ${{ secrets.SSH_KEY }} +# # aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} +# # aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} From 5068bb6fdd95c07a72a5a1d849ebf5579c4e2729 Mon Sep 17 00:00:00 2001 From: Vamshi_Kesari <118153587+kesarivamshi@users.noreply.github.com> Date: Fri, 25 Nov 2022 13:16:28 +0530 Subject: [PATCH 13/21] Update packer.yml --- .github/workflows/packer.yml | 68 ++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/.github/workflows/packer.yml b/.github/workflows/packer.yml index df059e8..ffad9ed 100644 --- a/.github/workflows/packer.yml +++ b/.github/workflows/packer.yml @@ -1,41 +1,41 @@ -# name: containerr -# on: push +name: containerr +on: push -# jobs: -# container: -# #needs: [s3deploy] -# runs-on: ubuntu-18.04 -# container: pearlthoughts/p2p-packer:latest -# steps: -# # - uses: trstringer/manual-approval@v1 -# # with: -# # secret: ${{ github.TOKEN }} -# # approvers: tejapearlthoughts -# - uses: actions/checkout@v2 -# - name: Configure AWS Credentials -# uses: aws-actions/configure-aws-credentials@v1 -# with: -# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} -# aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} -# #aws_session_token: ${{ secrets.AWS_SESSION_TOKEN}} -# aws-region: us-east-1 -# - run: | -# repo_name=${{ github.event.repository.name }} -# git config --global --add safe.directory /__w/$repo_name/$repo_name -# git_hash=$(git rev-parse --short "$GITHUB_SHA") -# echo "$SSH_KEY" > /__w/$repo_name/$repo_name/Ansible/id_rsa -# packer init . -# packer build \ -# -var "build_number=$GITHUB_RUN_NUMBER" \ -# -var "commit_sha=$git_hash" . +jobs: + container: + #needs: [s3deploy] + runs-on: ubuntu-18.04 + container: pearlthoughts/p2p-packer:latest + steps: + # - uses: trstringer/manual-approval@v1 + # with: + # secret: ${{ github.TOKEN }} + # approvers: tejapearlthoughts + - uses: actions/checkout@v2 + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + #aws_session_token: ${{ secrets.AWS_SESSION_TOKEN}} + aws-region: us-east-1 + - run: | + repo_name=${{ github.event.repository.name }} + git config --global --add safe.directory /__w/$repo_name/$repo_name + git_hash=$(git rev-parse --short "$GITHUB_SHA") + echo "$SSH_KEY" > /__w/$repo_name/$repo_name/Ansible/id_rsa + packer init . + packer build \ + -var "build_number=$GITHUB_RUN_NUMBER" \ + -var "commit_sha=$git_hash" . -# name: Run in container -# env: -# SSH_KEY: ${{ secrets.SSH_KEY }} -# # aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} -# # aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + name: Run in container + env: + SSH_KEY: ${{ secrets.SSH_KEY }} + # aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + # aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} From a382c58670d1ffec099aed097466156ac971996d Mon Sep 17 00:00:00 2001 From: Vamshi_Kesari <118153587+kesarivamshi@users.noreply.github.com> Date: Mon, 28 Nov 2022 09:56:33 +0530 Subject: [PATCH 14/21] Update main.yml --- terraform/.github/workflows/main.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/terraform/.github/workflows/main.yml b/terraform/.github/workflows/main.yml index cac98dc..a86a4ae 100644 --- a/terraform/.github/workflows/main.yml +++ b/terraform/.github/workflows/main.yml @@ -1,6 +1,5 @@ name: "Terraform Deployment" -on: - # Manual trigger +on: push workflow_dispatch: push: paths: From 0af5322c6939e7077ab02d1cd2b8a525c52266de Mon Sep 17 00:00:00 2001 From: Vamshi_Kesari <118153587+kesarivamshi@users.noreply.github.com> Date: Mon, 28 Nov 2022 10:54:28 +0530 Subject: [PATCH 15/21] Update main.yml --- terraform/.github/workflows/main.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/terraform/.github/workflows/main.yml b/terraform/.github/workflows/main.yml index a86a4ae..8a09d9c 100644 --- a/terraform/.github/workflows/main.yml +++ b/terraform/.github/workflows/main.yml @@ -1,6 +1,5 @@ name: "Terraform Deployment" -on: push - workflow_dispatch: +on: push: paths: - '*/**' From 56e19cb1c7aef6f5cd01e3a97cd7a15ec5edcc7a Mon Sep 17 00:00:00 2001 From: Sai Date: Mon, 28 Nov 2022 15:11:05 +0530 Subject: [PATCH 16/21] deleted ec2 folder --- ec2-terraform/.github/workflows/terraform.yml | 70 ------------------- ec2-terraform/aws-cerd.tf | 6 -- ec2-terraform/main.tf | 10 --- ec2-terraform/resaws.tf | 4 -- ec2-terraform/rest.tf | 17 ----- ec2-terraform/sec.tf | 28 -------- ec2-terraform/var.tf | 7 -- 7 files changed, 142 deletions(-) delete mode 100644 ec2-terraform/.github/workflows/terraform.yml delete mode 100644 ec2-terraform/aws-cerd.tf delete mode 100644 ec2-terraform/main.tf delete mode 100644 ec2-terraform/resaws.tf delete mode 100644 ec2-terraform/rest.tf delete mode 100644 ec2-terraform/sec.tf delete mode 100644 ec2-terraform/var.tf diff --git a/ec2-terraform/.github/workflows/terraform.yml b/ec2-terraform/.github/workflows/terraform.yml deleted file mode 100644 index b95d158..0000000 --- a/ec2-terraform/.github/workflows/terraform.yml +++ /dev/null @@ -1,70 +0,0 @@ -name: "Terraform" - -on: - push: - branches: - - main - pull_request: - -jobs: - terraform: - name: "Terraform" - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Setup Terraform - uses: hashicorp/setup-terraform@v1 - with: - # terraform_version: 0.13.0: - cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} - - - name: Terraform Format - id: fmt - run: terraform fmt -check - - - name: Terraform Init - id: init - run: terraform init - - - name: Terraform Validate - id: validate - run: terraform validate -no-color - - - name: Terraform Plan - id: plan - if: github.event_name == 'pull_request' - run: terraform plan -no-color - continue-on-error: true - - - uses: actions/github-script@0.9.0 - 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 }}\` - #### Terraform Plan šŸ“–\`${{ steps.plan.outcome }}\` -
Show Plan - \`\`\`\n - ${process.env.PLAN} - \`\`\` -
- *Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; - github.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: output - }) - - name: Terraform Plan Status - if: steps.plan.outcome == 'failure' - run: exit 1 - - - name: Terraform Apply - if: github.ref == 'refs/heads/main' && github.event_name == 'push' - run: terraform apply -auto-approve \ No newline at end of file diff --git a/ec2-terraform/aws-cerd.tf b/ec2-terraform/aws-cerd.tf deleted file mode 100644 index 9f4d7c7..0000000 --- a/ec2-terraform/aws-cerd.tf +++ /dev/null @@ -1,6 +0,0 @@ -provider "aws" { - profile = "default" - region = "eu-central-1" - access_key = var.AWS_ACCESS_KEY_ID - secret_key = var.AWS_SECRET_ACCESS_KEY -} \ No newline at end of file diff --git a/ec2-terraform/main.tf b/ec2-terraform/main.tf deleted file mode 100644 index 534d413..0000000 --- a/ec2-terraform/main.tf +++ /dev/null @@ -1,10 +0,0 @@ -terraform { - required_providers { - aws = { - source = "hashicorp/aws" - version = "~> 3.27" - } - } - - required_version = ">= 1.0.4" -} \ No newline at end of file diff --git a/ec2-terraform/resaws.tf b/ec2-terraform/resaws.tf deleted file mode 100644 index 5860de9..0000000 --- a/ec2-terraform/resaws.tf +++ /dev/null @@ -1,4 +0,0 @@ -resource "aws_key_pair" "deployer" { - key_name = "ec2-deployer-key-pair" - public_key = "your public_key look like that ssh-rsa AAAAB3Nā€¦ā€ -} \ No newline at end of file diff --git a/ec2-terraform/rest.tf b/ec2-terraform/rest.tf deleted file mode 100644 index 159402d..0000000 --- a/ec2-terraform/rest.tf +++ /dev/null @@ -1,17 +0,0 @@ -resource "aws_instance" "app_server" { - count = 1 - ami = "ami-08c40ec9ead489470" - instance_type = "t2.micro" - key_name = "ec2-deployer-key-pair" - vpc_security_group_ids = [aws_security_group.main.id] - - tags = { - Name = "First-Ec2-With-Terraform" - } - connection { - type = "ssh" - host = self.public_ip - user = "ubuntu" - timeout = "4m" - } -} diff --git a/ec2-terraform/sec.tf b/ec2-terraform/sec.tf deleted file mode 100644 index 7d80ae8..0000000 --- a/ec2-terraform/sec.tf +++ /dev/null @@ -1,28 +0,0 @@ -resource "aws_security_group" "main" { - egress = [ - { - cidr_blocks = ["0.0.0.0/0", ] - description = "" - from_port = 0 - ipv6_cidr_blocks = [] - prefix_list_ids = [] - protocol = "-1" - security_groups = [] - self = false - to_port = 0 - } - ] - ingress = [ - { - cidr_blocks = ["0.0.0.0/0", ] - description = "" - from_port = 22 - ipv6_cidr_blocks = [] - prefix_list_ids = [] - protocol = "tcp" - security_groups = [] - self = false - to_port = 22 - } - ] -} \ No newline at end of file diff --git a/ec2-terraform/var.tf b/ec2-terraform/var.tf deleted file mode 100644 index 8d37aff..0000000 --- a/ec2-terraform/var.tf +++ /dev/null @@ -1,7 +0,0 @@ -variable "AWS_ACCESS_KEY_ID" { - type = string -} - -variable "AWS_SECRET_ACCESS_KEY" { - type = string -} \ No newline at end of file From ead9e582468a335d3a0dfd251d0ac183a649b5dc Mon Sep 17 00:00:00 2001 From: Vamshi_Kesari <118153587+kesarivamshi@users.noreply.github.com> Date: Thu, 1 Dec 2022 08:08:58 +0530 Subject: [PATCH 17/21] Update main.yml --- terraform/.github/workflows/main.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/terraform/.github/workflows/main.yml b/terraform/.github/workflows/main.yml index 8a09d9c..3566cfd 100644 --- a/terraform/.github/workflows/main.yml +++ b/terraform/.github/workflows/main.yml @@ -1,5 +1,7 @@ name: "Terraform Deployment" on: + # Manual trigger + workflow_dispatch: push: paths: - '*/**' @@ -23,7 +25,7 @@ jobs: env: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - AWS_DEFAULT_REGION: us-east-2 + AWS_DEFAULT_REGION: us-east-1 steps: - uses: actions/checkout@v2 - uses: hashicorp/setup-terraform@v1 From 02a193ee6e80c85853457f1e632a752c7f3c7a25 Mon Sep 17 00:00:00 2001 From: Vamshi_Kesari <118153587+kesarivamshi@users.noreply.github.com> Date: Thu, 1 Dec 2022 08:18:37 +0530 Subject: [PATCH 18/21] Update main.yml --- terraform/.github/workflows/main.yml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/terraform/.github/workflows/main.yml b/terraform/.github/workflows/main.yml index 3566cfd..d5b1239 100644 --- a/terraform/.github/workflows/main.yml +++ b/terraform/.github/workflows/main.yml @@ -1,12 +1,6 @@ name: "Terraform Deployment" -on: - # Manual trigger - workflow_dispatch: - push: - paths: - - '*/**' - pull_request: - branches: [ main ] +on: + workflow_dispatch defaults: run: shell: bash From a9f45566a9b2b9e3db37dfce9c9cf61dfb49173a Mon Sep 17 00:00:00 2001 From: Vamshi_Kesari <118153587+kesarivamshi@users.noreply.github.com> Date: Thu, 1 Dec 2022 08:22:20 +0530 Subject: [PATCH 19/21] Update main.yml --- terraform/.github/workflows/main.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/terraform/.github/workflows/main.yml b/terraform/.github/workflows/main.yml index d5b1239..a2fe461 100644 --- a/terraform/.github/workflows/main.yml +++ b/terraform/.github/workflows/main.yml @@ -1,9 +1,6 @@ name: "Terraform Deployment" on: - workflow_dispatch -defaults: - run: - shell: bash + workflow_dispatch jobs: terraform: name: ${{matrix.runner}} - ${{ matrix.environment }} From cb4ba9614bac9dee60f652bb761550e59122f1e9 Mon Sep 17 00:00:00 2001 From: Vamshi_Kesari <118153587+kesarivamshi@users.noreply.github.com> Date: Thu, 1 Dec 2022 08:24:04 +0530 Subject: [PATCH 20/21] Update main.yml --- terraform/.github/workflows/main.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/terraform/.github/workflows/main.yml b/terraform/.github/workflows/main.yml index a2fe461..10350c4 100644 --- a/terraform/.github/workflows/main.yml +++ b/terraform/.github/workflows/main.yml @@ -1,6 +1,5 @@ name: "Terraform Deployment" -on: - workflow_dispatch +on: push jobs: terraform: name: ${{matrix.runner}} - ${{ matrix.environment }} From af57c11524a08ea5533f3fb8fdbccceeca84bee7 Mon Sep 17 00:00:00 2001 From: Vamshi_Kesari <118153587+kesarivamshi@users.noreply.github.com> Date: Thu, 1 Dec 2022 09:24:00 +0530 Subject: [PATCH 21/21] Update main.yml --- terraform/.github/workflows/main.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/terraform/.github/workflows/main.yml b/terraform/.github/workflows/main.yml index 10350c4..781fdb6 100644 --- a/terraform/.github/workflows/main.yml +++ b/terraform/.github/workflows/main.yml @@ -1,5 +1,9 @@ name: "Terraform Deployment" -on: push +on: + push: + branches: + - main + pull_request: jobs: terraform: name: ${{matrix.runner}} - ${{ matrix.environment }}