Skip to content

Commit 93b4953

Browse files
authored
Tekton task to clean up the vpc resources (#350)
1 parent e95b99e commit 93b4953

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

tests/assets/amazon-eks-vpc.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,7 @@
664664
},
665665
"PublicSubnet01": {
666666
"Type": "AWS::EC2::Subnet",
667+
"DependsOn": "VPC",
667668
"Metadata": {
668669
"Comment": "Subnet 01"
669670
},
@@ -701,6 +702,7 @@
701702
},
702703
"PublicSubnet02": {
703704
"Type": "AWS::EC2::Subnet",
705+
"DependsOn": "VPCCIDRBlock2",
704706
"Metadata": {
705707
"Comment": "Subnet 02"
706708
},
@@ -738,6 +740,7 @@
738740
},
739741
"PublicSubnet03": {
740742
"Condition": "HasMoreThan2Azs",
743+
"DependsOn": "VPCCIDRBlock3",
741744
"Type": "AWS::EC2::Subnet",
742745
"Metadata": {
743746
"Comment": "Subnet 03"
@@ -776,6 +779,7 @@
776779
},
777780
"PublicSubnet04": {
778781
"Condition": "HasMoreThan2Azs",
782+
"DependsOn": "VPCCIDRBlock4",
779783
"Type": "AWS::EC2::Subnet",
780784
"Metadata": {
781785
"Comment": "Subnet 04"
@@ -814,6 +818,7 @@
814818
},
815819
"PrivateSubnet01": {
816820
"Type": "AWS::EC2::Subnet",
821+
"DependsOn": "VPCCIDRBlock5",
817822
"Metadata": {
818823
"Comment": "Private Subnet 01"
819824
},
@@ -850,6 +855,7 @@
850855
},
851856
"PrivateSubnet02": {
852857
"Type": "AWS::EC2::Subnet",
858+
"DependsOn": "VPCCIDRBlock6",
853859
"Metadata": {
854860
"Comment": "Private Subnet 02"
855861
},
@@ -886,6 +892,7 @@
886892
},
887893
"PrivateSubnet03": {
888894
"Condition": "HasMoreThan2Azs",
895+
"DependsOn": "VPCCIDRBlock7",
889896
"Type": "AWS::EC2::Subnet",
890897
"Metadata": {
891898
"Comment": "Private Subnet 03"
@@ -924,6 +931,7 @@
924931
"PrivateSubnet04": {
925932
"Condition": "HasMoreThan2Azs",
926933
"Type": "AWS::EC2::Subnet",
934+
"DependsOn": "VPCCIDRBlock8",
927935
"Metadata": {
928936
"Comment": "Private Subnet 04"
929937
},
@@ -961,6 +969,7 @@
961969
"PrivateSubnet05": {
962970
"Condition": "HasMoreThan2Azs",
963971
"Type": "AWS::EC2::Subnet",
972+
"DependsOn": "VPCCIDRBlock9",
964973
"Metadata": {
965974
"Comment": "Private Subnet 05"
966975
},
@@ -997,6 +1006,7 @@
9971006
},
9981007
"PrivateSubnet06": {
9991008
"Condition": "HasMoreThan2Azs",
1009+
"DependsOn": "VPCCIDRBlock10",
10001010
"Type": "AWS::EC2::Subnet",
10011011
"Metadata": {
10021012
"Comment": "Private Subnet 06"
@@ -1034,6 +1044,7 @@
10341044
},
10351045
"PrivateSubnet07": {
10361046
"Condition": "HasMoreThan2Azs",
1047+
"DependsOn": "VPCCIDRBlock11",
10371048
"Type": "AWS::EC2::Subnet",
10381049
"Metadata": {
10391050
"Comment": "Private Subnet 07"
@@ -1071,6 +1082,7 @@
10711082
},
10721083
"PrivateSubnet08": {
10731084
"Condition": "HasMoreThan2Azs",
1085+
"DependsOn": "VPCCIDRBlock12",
10741086
"Type": "AWS::EC2::Subnet",
10751087
"Metadata": {
10761088
"Comment": "Private Subnet 08"
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
apiVersion: tekton.dev/v1beta1
2+
kind: Task
3+
metadata:
4+
name: awscli-delete-vpc
5+
namespace: tekton-pipelines
6+
spec:
7+
description: |
8+
This Task can be used to delete CloudFormation stack containing VPC resources that was used for EKS clusters.
9+
params:
10+
- name: stack-name
11+
description: The name of the VPC name you want to delete.
12+
- name: region
13+
default: "us-west-2"
14+
steps:
15+
- name: awscli-delete-vpc
16+
image: alpine/k8s:1.22.6
17+
script: |
18+
#!/bin/bash
19+
echo "Approving KCM requests"
20+
kubectl certificate approve $(kubectl get csr | grep "Pending" | awk '{print $1}') 2>/dev/null || true
21+
aws sts get-caller-identity
22+
# Check if the stack exists
23+
aws cloudformation --region $(params.region) describe-stacks --stack-name $(params.stack-name)
24+
if [ $? -ne 0 ]; then
25+
echo "Stack $(params.stack-name) not found. Exiting..."
26+
exit 1
27+
else
28+
echo "Deleting stack $(params.stack-name)..."
29+
fi
30+
#Deletes the CFN stack
31+
aws cloudformation delete-stack --region $(params.region) --stack-name $(params.stack-name)
32+
# Wait for the stack to be deleted
33+
aws cloudformation wait stack-delete-complete --region $(params.region) --stack-name $(params.stack-name)
34+
echo "Stack deleted successfully!"

0 commit comments

Comments
 (0)