Skip to content
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

Setup gha 107 #7

Merged
merged 38 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
6296677
adding workflow directory
chelseybeck Feb 8, 2024
890454e
updating - to _
chelseybeck Feb 8, 2024
cdf8ce8
testing to see if plan works without dflook
chelseybeck Feb 8, 2024
9776bf6
writing plan to comment
chelseybeck Feb 13, 2024
f166ed0
adding missing v
chelseybeck Feb 13, 2024
45d14e8
testing path to key
chelseybeck Feb 13, 2024
5343460
testing permissions with updated path
chelseybeck Feb 13, 2024
cadfcee
reverting back to original directory structure
chelseybeck Feb 13, 2024
6dadd45
testing jonathans config
chelseybeck Feb 14, 2024
5dbd01f
reverting back to previous workflow
chelseybeck Feb 15, 2024
9166728
fixing format
chelseybeck Feb 15, 2024
77013e2
testing init
chelseybeck Feb 15, 2024
1121b9f
testing ci
chelseybeck Feb 15, 2024
10fb916
testing ci connection
chelseybeck Feb 15, 2024
85fff0f
fixing directory
chelseybeck Feb 15, 2024
a9dd217
adding auth step
chelseybeck Feb 15, 2024
b33e6a3
testing
chelseybeck Feb 15, 2024
d4f7d37
testing
chelseybeck Feb 15, 2024
72ba39f
testing
chelseybeck Feb 15, 2024
e74cfaa
removing redundancy and testing
chelseybeck Feb 19, 2024
28602cc
removing test and updating plan to use dflook as planned
chelseybeck Feb 19, 2024
e929b83
adding path to plan step
chelseybeck Feb 19, 2024
9c928ab
removing python script used for testing
chelseybeck Feb 19, 2024
79cd027
adding new users
chelseybeck Feb 19, 2024
d66224b
updating read only group to add ability to change pw
chelseybeck Feb 19, 2024
0e97319
removing duplicate steps
chelseybeck Feb 19, 2024
b2dc7b5
removing duplicate path
chelseybeck Feb 19, 2024
22ca6e6
removing path from plan
chelseybeck Feb 19, 2024
fb0c53c
fixing indent and granting contents read access for dflook
chelseybeck Feb 19, 2024
9db8a89
adding checkout step back in
chelseybeck Feb 19, 2024
22f3b36
adding iam services admin policy to update passwords and create acces…
chelseybeck Feb 20, 2024
343ddbd
updating policy arn to use a map and adding the admin group
chelseybeck Feb 20, 2024
66f4f24
updating formatting and adding access levels to users
chelseybeck Feb 20, 2024
8324623
changing for each to use a map
chelseybeck Feb 20, 2024
5ce810f
updating variable to use map instead of list
chelseybeck Feb 20, 2024
40e5058
updating file path
chelseybeck Feb 20, 2024
1d50e71
adding a custom policy to attach to iam services admin
chelseybeck Feb 20, 2024
b32fd04
adding apply stage
chelseybeck Feb 22, 2024
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
32 changes: 32 additions & 0 deletions .github/workflows/terraform-apply.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Apply Terraform changes on merge

on:
push:
branches:
- main # or any other branch you want to trigger the deployment

jobs:
terraform-apply:
name: Terraform Apply
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

permissions:
contents: read
pull-requests: write

steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-west-2

- name: Terraform Apply
uses: dflook/terraform-apply@v1
with:
path: terraform
Original file line number Diff line number Diff line change
@@ -1,39 +1,32 @@
name: Deploy IAM Resources to AWS with Terraform
name: Write Terraform Plan to Pull Request

on:
pull-request:
pull_request:
branches:
- main # or any other branch you want to trigger the deployment

jobs:
terraform:
name: Terraform
terraform-plan:
name: Terraform Plan
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

permissions:
contents: read
pull-requests: write

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: 1.0.0 # Specify the Terraform version

uses: actions/checkout@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-west-2 # Change to your AWS region

- name: Terraform Init
run: terraform init
aws-region: us-west-2

- name: Terraform Plan
uses: dflook/terraform-plan@v1
with:
path: terraform


9 changes: 9 additions & 0 deletions terraform/aws-custom-policies.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module "aws_custom_policies" {
source = "./modules/aws-policies"
policies = {
"IAMServicesAdmin" = {
description = "Policy granting IAM services admins permissions to make changes to user accounts"
filename = "level-4-iam-services-admin-policy.json"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,23 @@
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "",
"Effect": "Allow",
"Action": [
"",
"",
"",
""
"iam:CreateAccessKey"
],
"Resource": ""
"Resource": "arn:aws:iam::*:user/*"
},
{
"Sid": "",
"Effect": "",
"Effect": "Allow",
"Action": [
"",
"",
"",
""
"iam:UpdateLoginProfile"
],
"Resource": ""
"Resource": "arn:aws:iam::*:user/*",
"Condition": {
"StringEquals": {
"iam:ResourceTag/Access Level": ["1", "2"]
}
}
}
]
}
}
16 changes: 15 additions & 1 deletion terraform/aws-groups.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,19 @@ module "iam_read_only_group" {
source = "./modules/aws-groups"

group_name = "read-only-group"
policy_arn = ["arn:aws:iam::aws:policy/ReadOnlyAccess"]
policy_arn = {
"ReadOnlyAccess" = "arn:aws:iam::aws:policy/ReadOnlyAccess",
"IAMUserChangePassword" = "arn:aws:iam::aws:policy/IAMUserChangePassword"
}
}

// Create iam services admin group
module "iam_services_admin_group" {
source = "./modules/aws-groups"

group_name = "iam-services-admin-group"
policy_arn = {
"IAMServicesAdmin" = module.aws_custom_policies.policy_arns["IAMServicesAdmin"]
}
}

84 changes: 80 additions & 4 deletions terraform/aws-users.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,87 @@
// Create user and assign to group(s)
module "iam_user_gwenstacy" {
module "iam_user_JimmyJuarez10" {
source = "./modules/aws-users"

user_name = "gwenstacy"
user_name = "JimmyJuarez10"
user_tags = {
"Environment" = "Development"
"Project" = "spiderverse"
"Project" = "civic-tech-jobs"
}
user_groups = ["read-only-group"]
}

module "iam_user_brittanyms" {
source = "./modules/aws-users"

user_name = "brittanyms"
user_tags = {
"Project" = "devops-security"
"Access Level" = "1"
}
user_groups = ["read-only-group"]
}

module "iam_user_freaky4wrld" {
source = "./modules/aws-users"

user_name = "freaky4wrld"
user_tags = {
"Project" = "devops-security"
"Access Level" = "1"
}
user_groups = ["read-only-group"]
}

module "iam_user_shikha0428" {
source = "./modules/aws-users"

user_name = "shikha0428"
user_tags = {
"Project" = "devops-security"
"Access Level" = "1"
}
user_groups = ["read-only-group"]
}

module "iam_user_shinjonathan" {
source = "./modules/aws-users"

user_name = "shinjonathan"
user_tags = {
"Project" = "devops-security"
"Access Level" = "1"
}
user_groups = ["read-only-group"]
}

module "iam_user_samuelusc" {
source = "./modules/aws-users"

user_name = "samuelusc"
user_tags = {
"Project" = "devops-security"
"Access Level" = "1"
}
user_groups = ["read-only-group"]
}

module "iam_user_abbyz123" {
source = "./modules/aws-users"

user_name = "abbyz123"
user_tags = {
"Project" = "devops-security"
"Access Level" = "1"
}
user_groups = ["read-only-group"]
}

module "iam_user_awlFCCamp" {
source = "./modules/aws-users"

user_name = "awlFCCamp"
user_tags = {
"Project" = "devops-security"
"Access Level" = "1"
}
user_groups = ["read-only-group"]
}
2 changes: 1 addition & 1 deletion terraform/modules/aws-groups/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ resource "aws_iam_group" "group" {
}

resource "aws_iam_group_policy_attachment" "group_policy_attachment" {
for_each = toset(var.policy_arn)
for_each = var.policy_arn
group = aws_iam_group.group.name
policy_arn = each.value
}
4 changes: 2 additions & 2 deletions terraform/modules/aws-groups/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ variable "group_path" {
}

variable "policy_arn" {
description = "List of policy ARNs to attach to the group"
type = list(string)
description = "Map of policy names to ARNs to attach to the group"
type = map(string)
}
2 changes: 1 addition & 1 deletion terraform/modules/aws-policies/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ resource "aws_iam_policy" "custom_policy" {

name = each.key
description = each.value["description"]
policy = file("${path.module}/policies-json/${each.value["filename"]}")
policy = file("aws-custom-policies/${each.value["filename"]}")
}