Skip to content

Commit beb3e71

Browse files
vishdivgcyturneysvennam92
authored
Resiliency changes (#1113)
Co-authored-by: cyturney <cyturney@amazon.com> Co-authored-by: Sai Vennam <svennam92@gmail.com>
1 parent 9dae1b4 commit beb3e71

30 files changed

+2076
-1
lines changed

hack/run-tests.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ RESOURCES_PRECREATED=${RESOURCES_PRECREATED:-""}
7676

7777
echo "Running test suite..."
7878

79+
# get current IDs
80+
USER_ID=$(id -u)
81+
GROUP_ID=$(id -g)
82+
7983
exit_code=0
8084

8185
$CONTAINER_CLI run $background_args $dns_args \

hack/validate-terraform.sh

100644100755
File mode changed.

lab/iam/iam-role-cfn.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,13 @@ Resources:
6262
ManagedPolicyName: ${Env}-ide-labs2
6363
PolicyDocument:
6464
file: ./iam/policies/labs2.yaml
65+
EksWorkshopLabsPolicy3:
66+
Type: AWS::IAM::ManagedPolicy
67+
DependsOn:
68+
- EksWorkshopIdeRole
69+
Properties:
70+
Roles:
71+
- !Ref EksWorkshopIdeRole
72+
ManagedPolicyName: ${Env}-ide-labs3
73+
PolicyDocument:
74+
file: ./iam/policies/labs3.yaml

lab/iam/policies/ec2.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Statement:
99
Resource: ["*"]
1010
- Effect: Allow
1111
Action:
12+
- ec2:StopInstances
1213
- ec2:TerminateInstances
1314
Resource: ["*"]
1415
Condition:

lab/iam/policies/iam.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@ Statement:
2323
- iam:CreatePolicy
2424
- iam:DeletePolicy
2525
- iam:GetPolicyVersion
26+
- iam:DeletePolicyVersion
2627
- iam:ListPolicyVersions
2728
- iam:TagPolicy
2829
- iam:GetPolicy
2930
Resource:
3031
- !Sub arn:aws:iam::${AWS::AccountId}:policy/${Env}*
3132
- !Sub arn:aws:iam::${AWS::AccountId}:policy/eksctl-${Env}*
33+
- Effect: Allow
34+
Action:
35+
- s3:ListAllMyBuckets
36+
- iam:ListPolicies
37+
- iam:ListRoles
38+
Resource: ["*"]
3239
- Effect: Allow
3340
Action:
3441
- iam:CreateInstanceProfile

lab/iam/policies/labs3.yaml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
Version: "2012-10-17"
2+
Statement:
3+
- Effect: Allow
4+
Action:
5+
- s3:CreateBucket
6+
- s3:DeleteBucket
7+
- s3:PutObject
8+
- s3:List*
9+
- s3:Get*
10+
- s3:GetObjectVersion
11+
- s3:PutBucketPublicAccessBlock
12+
- s3:PutBucketTagging
13+
- s3:DeleteObject
14+
- s3:DeleteObjectVersion
15+
Resource:
16+
- arn:aws:s3:::eks-workshop-canary-artifacts*
17+
- arn:aws:s3:::aws-synthetics-library*
18+
- Effect: Allow
19+
Action:
20+
- fis:CreateExperimentTemplate
21+
- fis:CreateExperimentTemplate
22+
- fis:GetExperimentTemplate
23+
- fis:ListExperimentTemplates
24+
- fis:DeleteExperimentTemplate
25+
- fis:UpdateExperimentTemplate
26+
- fis:TagResource
27+
- fis:UntagResource
28+
- fis:StartExperiment
29+
- fis:GetExperiment
30+
- fis:ListExperiments
31+
Resource:
32+
- !Sub arn:aws:fis:${AWS::Region}:${AWS::AccountId}:action/aws:eks:*
33+
- !Sub arn:aws:fis:${AWS::Region}:${AWS::AccountId}:action/aws:ssm:*
34+
- !Sub arn:aws:fis:${AWS::Region}:${AWS::AccountId}:experiment-template/*
35+
- !Sub arn:aws:fis:${AWS::Region}:${AWS::AccountId}:experiment/*
36+
37+
- Effect: Allow
38+
Action:
39+
- synthetics:CreateCanary
40+
- synthetics:DeleteCanary
41+
- synthetics:DescribeCanaries
42+
- synthetics:StartCanary
43+
- synthetics:StopCanary
44+
- synthetics:UpdateCanary
45+
Resource:
46+
- !Sub arn:aws:synthetics:${AWS::Region}:${AWS::AccountId}:canary:${Env}*
47+
- Effect: Allow
48+
Action:
49+
- cloudwatch:PutMetricAlarm
50+
- cloudwatch:PutMetricData
51+
- cloudwatch:GetMetricStatistics
52+
- cloudwatch:ListMetrics
53+
Resource:
54+
- !Sub arn:aws:cloudwatch:${AWS::Region}:${AWS::AccountId}:alarm:${Env}*
55+
- Effect: Allow
56+
Action:
57+
- lambda:CreateFunction
58+
- lambda:UpdateFunctionCode
59+
- lambda:GetFunctionConfiguration
60+
- lambda:UpdateFunctionConfiguration
61+
- lambda:GetFunction
62+
- lambda:DeleteFunction
63+
- lambda:InvokeFunction
64+
- lambda:AddPermission
65+
- lambda:RemovePermission
66+
- lambda:PublishLayerVersion
67+
- lambda:PublishVersion
68+
Resource:
69+
- !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:*${Env}*
70+
- !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:layer:*${Env}*

manifests/.workshop/terraform/base.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = "5.66.0"
7+
version = "5.72.0"
88
}
99
kubernetes = {
1010
source = "hashicorp/kubernetes"
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
echo "Starting cleanup process..."
6+
7+
# Function to safely delete a resource
8+
safe_delete() {
9+
local cmd=$1
10+
local resource=$2
11+
echo "Attempting to delete $resource..."
12+
if $cmd 2>/dev/null; then
13+
echo "$resource deleted successfully."
14+
else
15+
echo "Failed to delete $resource or it doesn't exist. Continuing..."
16+
fi
17+
}
18+
19+
# Delete Kubernetes resources
20+
echo "Cleaning up Kubernetes resources..."
21+
kubectl delete ingress,deployment,service -n ui --all --ignore-not-found
22+
kubectl delete role,rolebinding -n ui --all --ignore-not-found
23+
kubectl delete namespace chaos-mesh --ignore-not-found
24+
25+
# Uninstall Helm charts
26+
echo "Uninstalling Helm charts..."
27+
helm uninstall aws-load-balancer-controller -n kube-system || true
28+
helm uninstall chaos-mesh -n chaos-mesh || true
29+
30+
# Delete ALBs
31+
echo "Cleaning up ALBs..."
32+
for alb_arn in $(aws elbv2 describe-load-balancers --query "LoadBalancers[?starts_with(LoadBalancerName, 'k8s-ui-ui-') || starts_with(LoadBalancerName, 'k8s-default-ui-')].LoadBalancerArn" --output text); do
33+
safe_delete "aws elbv2 delete-load-balancer --load-balancer-arn $alb_arn" "ALB $alb_arn"
34+
done
35+
36+
# Delete IAM Roles and Policies
37+
echo "Cleaning up IAM roles and policies..."
38+
for role_prefix in "fis-execution-role-eks-workshop" "canary-execution-role-eks-workshop"; do
39+
for role in $(aws iam list-roles --query "Roles[?starts_with(RoleName, '${role_prefix}')].RoleName" --output text); do
40+
echo "Processing role: $role"
41+
for policy in $(aws iam list-attached-role-policies --role-name $role --query "AttachedPolicies[*].PolicyArn" --output text); do
42+
safe_delete "aws iam detach-role-policy --role-name $role --policy-arn $policy" "attached policy $policy from role $role"
43+
done
44+
for policy in $(aws iam list-role-policies --role-name $role --query "PolicyNames" --output text); do
45+
safe_delete "aws iam delete-role-policy --role-name $role --policy-name $policy" "inline policy $policy from role $role"
46+
done
47+
safe_delete "aws iam delete-role --role-name $role" "IAM role $role"
48+
done
49+
done
50+
51+
for policy_prefix in "eks-resiliency-fis-policy" "eks-resiliency-canary-policy"; do
52+
for policy_arn in $(aws iam list-policies --scope Local --query "Policies[?starts_with(PolicyName, '${policy_prefix}')].Arn" --output text); do
53+
safe_delete "aws iam delete-policy --policy-arn $policy_arn" "IAM policy $policy_arn"
54+
done
55+
done
56+
57+
# Delete S3 buckets
58+
echo "Cleaning up S3 buckets..."
59+
for bucket in $(aws s3api list-buckets --query "Buckets[?starts_with(Name, 'eks-workshop-canary-artifacts-')].Name" --output text); do
60+
aws s3 rm s3://$bucket --recursive
61+
safe_delete "aws s3api delete-bucket --bucket $bucket" "S3 bucket $bucket"
62+
done
63+
64+
# Delete CloudWatch Synthetics canary and alarm
65+
CANARY_NAME="eks-workshop-canary"
66+
ALARM_NAME="eks-workshop-canary-alarm"
67+
68+
echo "Cleaning up CloudWatch Synthetics canary and alarm..."
69+
if aws synthetics get-canary --name $CANARY_NAME &>/dev/null; then
70+
aws synthetics stop-canary --name $CANARY_NAME || true
71+
sleep 30
72+
safe_delete "aws synthetics delete-canary --name $CANARY_NAME" "CloudWatch Synthetics canary $CANARY_NAME"
73+
fi
74+
75+
safe_delete "aws cloudwatch delete-alarms --alarm-names $ALARM_NAME" "CloudWatch alarm $ALARM_NAME"
76+
77+
echo "Cleanup process completed. Please check for any remaining resources manually."

0 commit comments

Comments
 (0)