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

Feat: Adding terraform bootstrap for fully private deployment #200

Merged
merged 45 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
fe41c87
adding the e2e test for bootstrap with terraform
edgarsilva948 Jun 4, 2024
4e3654e
fixing versions comment
edgarsilva948 Jun 4, 2024
9f0484c
adding the fully private bootstrap
edgarsilva948 Jun 5, 2024
9e3cdbd
adding image push script
edgarsilva948 Jun 7, 2024
cb7adc3
fixing private images
edgarsilva948 Jun 8, 2024
cb68236
adding eks fully private sg rules
edgarsilva948 Jun 8, 2024
f695de2
fixing sg locals loop
edgarsilva948 Jun 9, 2024
7c7f796
adjusting security group rules
edgarsilva948 Jun 9, 2024
c9763ab
adjusting security group rules
edgarsilva948 Jun 9, 2024
067fe7c
adding package pull policy
edgarsilva948 Jun 9, 2024
b3a67a5
adding sleep after the family provider
edgarsilva948 Jun 9, 2024
6ea8619
upgrading upjet version
edgarsilva948 Jun 9, 2024
48ac2e6
adding the skip dependency comment
edgarsilva948 Jun 10, 2024
bc1a81e
downgrading crossplane to work fully private
edgarsilva948 Jun 10, 2024
8368352
fixing timeouts and sleep
edgarsilva948 Jun 10, 2024
2a46d4c
fixing the sg rules
edgarsilva948 Jun 10, 2024
fa9eeaf
adjusting script lua from eksctl
edgarsilva948 Jun 10, 2024
f9f442c
adding sg rules comment
edgarsilva948 Jun 10, 2024
371258d
fixing terraform bootstrap
edgarsilva948 Jun 18, 2024
0bef156
breaking the small changes into new branches
edgarsilva948 Jun 18, 2024
e26ae3a
reverting runtime config fix
edgarsilva948 Jun 18, 2024
84ce195
reverting the e2e files
edgarsilva948 Jun 18, 2024
933442b
reverting docs fix
edgarsilva948 Jun 18, 2024
9b739b0
reverting terraform main.tf fix
edgarsilva948 Jun 18, 2024
f88bf32
adding default for ecr_region and ecr_account_id, shortening the name…
candonov Jun 25, 2024
6a7aa10
ecr repos
candonov Jun 27, 2024
84ac0e7
ecr pull through cache updates
candonov Jul 3, 2024
05a18e6
removing unnessesary script
candonov Jul 3, 2024
fcde89e
typo
candonov Jul 3, 2024
3ce4351
typo
candonov Jul 3, 2024
4af7bf2
updating gif
candonov Jul 3, 2024
9686189
fixing readme and adding cidr comments
edgarsilva948 Jul 5, 2024
8d9fea1
fixing readme to include the ecr secret
edgarsilva948 Jul 5, 2024
d94f0af
adjusting scripts and readme
edgarsilva948 Jul 5, 2024
578dfe6
adding the cleanup script and adjusting readme
edgarsilva948 Jul 5, 2024
d16482f
adding the faq.md in the clean up section
edgarsilva948 Jul 5, 2024
0f3da0d
adding crane auth login
edgarsilva948 Jul 5, 2024
647e272
adding upbound/provider-aws-cloudfront repo creation
edgarsilva948 Jul 5, 2024
5807632
adding proxy comments
edgarsilva948 Jul 9, 2024
e847b21
fixing conflicts
edgarsilva948 Jul 9, 2024
1518fc1
ecr updates
candonov Jul 23, 2024
ea892fd
Update bootstrap/terraform-fully-private/README.md
candonov Jul 23, 2024
d7756df
Update bootstrap/terraform-fully-private/providers/upjet-aws/provider…
candonov Jul 23, 2024
645f7a7
Update bootstrap/terraform-fully-private/README.md
candonov Jul 23, 2024
94a59e3
adding docs to explain the org/repo requirement
edgarsilva948 Jul 23, 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
33 changes: 33 additions & 0 deletions .github/scripts/e2e-delete-lbs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os
import boto3

REGION = os.environ.get('AWS_DEFAULT_REGION', 'us-east-1')
ELB_CLIENT = boto3.client('elbv2', region_name=REGION)

def delete_target_groups(target_group_arns):
for tg_arn in target_group_arns:
ELB_CLIENT.delete_target_group(TargetGroupArn=tg_arn)

def delete_listeners(listener_arns):
for listener_arn in listener_arns:
ELB_CLIENT.delete_listener(ListenerArn=listener_arn)

def delete_load_balancers():
response = ELB_CLIENT.describe_load_balancers()

for lb in response['LoadBalancers']:
lb_arn = lb['LoadBalancerArn']
listeners = ELB_CLIENT.describe_listeners(LoadBalancerArn=lb_arn)
listener_arns = [listener['ListenerArn'] for listener in listeners['Listeners']]

delete_listeners(listener_arns)

target_groups = ELB_CLIENT.describe_target_groups(LoadBalancerArn=lb_arn)
target_group_arns = [tg['TargetGroupArn'] for tg in target_groups['TargetGroups']]

delete_target_groups(target_group_arns)

ELB_CLIENT.delete_load_balancer(LoadBalancerArn=lb_arn)

if __name__ == '__main__':
delete_load_balancers()
45 changes: 45 additions & 0 deletions .github/scripts/e2e-delete-sgs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import os
import boto3

REGION = os.environ.get('AWS_DEFAULT_REGION', 'us-east-1')
EC2_CLIENT = boto3.client('ec2', region_name=REGION)

def remove_security_group_rules(security_group_id):
try:
sg_details = EC2_CLIENT.describe_security_groups(GroupIds=[security_group_id])
sg = sg_details['SecurityGroups'][0]

if sg['IpPermissions']:
EC2_CLIENT.revoke_security_group_ingress(
GroupId=security_group_id,
IpPermissions=sg['IpPermissions']
)

if sg['IpPermissionsEgress']:
EC2_CLIENT.revoke_security_group_egress(
GroupId=security_group_id,
IpPermissions=sg['IpPermissionsEgress']
)
except Exception as e:
print(f"Error removing rules from {security_group_id}: {str(e)}")

def delete_all_security_groups():
try:
response = EC2_CLIENT.describe_security_groups()
for sg in response['SecurityGroups']:
# Skip deleting default security groups or any critical system security group
if sg['GroupName'] == 'default' or 'default' in sg['GroupName']:
print(f"Skipping default security group: {sg['GroupId']} ({sg['GroupName']})")
continue

try:
remove_security_group_rules(sg['GroupId'])
EC2_CLIENT.delete_security_group(GroupId=sg['GroupId'])
print(f"Deleted security group: {sg['GroupId']}")
except Exception as e:
print(f"Failed to delete {sg['GroupId']}: {str(e)}")
except Exception as e:
print(f"Failed to process security groups: {str(e)}")

if __name__ == '__main__':
delete_all_security_groups()
120 changes: 120 additions & 0 deletions .github/workflows/e2e-parallel-full.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: e2e-parallel-full

on:
workflow_dispatch:
inputs:
TFDestroy:
description: 'Destroy TF Automatically (false/true) - Default: true'
required: true
default: 'true'

concurrency: e2e-parallel-full

env:
BUCKET_NAME: terraform-crossplane-on-eks-github-actions-state

permissions:
contents: read

jobs:
prereq-cleanup:
name: Prerequisite Cleanup
runs-on: ubuntu-latest
# These permissions are needed to interact with GitHub's OIDC Token endpoint.
permissions:
id-token: write
contents: read
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
egress-policy: audit

- name: Checkout
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29

- name: Auth AWS
uses: aws-actions/configure-aws-credentials@v4.0.2
with:
role-to-assume: ${{ secrets.ROLE_TO_ASSUME }}
aws-region: us-east-1
role-duration-seconds: 3600
role-session-name: GithubActions-Session

- name: Ensure load balancers and sgs are removed
run: |
pip3 install boto3
python3 .github/scripts/e2e-delete-sgs.py
python3 .github/scripts/e2e-delete-lbs.py

deploy:
name: Run e2e test
runs-on: ubuntu-latest
needs: prereq-cleanup

# These permissions are needed to interact with GitHub's OIDC Token endpoint.
permissions:
id-token: write
contents: read
strategy:
fail-fast: false
matrix:
include:
- example_path: bootstrap/terraform
# - example_path: bootstrap/terraform-fully-private
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
egress-policy: audit

- name: Checkout
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29

- name: Setup backend
# Un-comment remote backend for use in workflow
run: sed -i "s/# //g" ${{ matrix.example_path }}/versions.tf

- name: Auth AWS
uses: aws-actions/configure-aws-credentials@v4.0.2
with:
role-to-assume: ${{ secrets.ROLE_TO_ASSUME }}
aws-region: us-east-1
role-duration-seconds: 3600
role-session-name: GithubActions-Session

- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.8.4

- name: Terraform Apply
id: apply
working-directory: ${{ matrix.example_path }}
run: |
terraform init -upgrade=true
terraform apply -target="module.vpc" -no-color -input=false -auto-approve
terraform apply -target="module.eks" -no-color -input=false -auto-approve
terraform apply -target="module.eks_blueprints_addons" -no-color -input=false -auto-approve
terraform apply -target="module.crossplane" -no-color -input=false -auto-approve
terraform apply -target="module.gatekeeper" -no-color -input=false -auto-approve
terraform apply -no-color -input=false -auto-approve

- name: Terraform Destroy
if: github.event.inputs.TFDestroy == 'true' && (steps.apply.outcome == 'success' || steps.apply.outcome == 'failure')
working-directory: ${{ matrix.example_path }}
run: |
terraform init -upgrade=true
terraform destroy -target="module.crossplane" -no-color -auto-approve
terraform destroy -target="module.gatekeeper" -no-color -auto-approve
terraform destroy -target="module.eks_blueprints_addons" -no-color -auto-approve
terraform destroy -target="module.eks" -no-color -auto-approve
terraform destroy -target="module.vpc" -no-color -auto-approve
terraform destroy -no-color -auto-approve

- name: Fail if TF apply failed
if: steps.apply.outcome == 'failure'
run: |
echo "Terraform Apply step failed...Please check the logs of the Terraform Apply step."
echo "Failing the job to avoid false positives."
exit 1
Loading