Skip to content

Commit

Permalink
Adding applicationName to aws resource definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
willdavsmith committed Sep 11, 2023
1 parent c2d8d2e commit 7e0d0ae
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 30 deletions.
53 changes: 42 additions & 11 deletions .github/scripts/delete-aws-resources.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,42 @@
for RESOURCE_TYPE in ${{ env.RESOURCE_TYPES }}; do
aws cloudcontrol list-resources --region ${{ env.AWS_REGION }} --type-name $RESOURCE_TYPE --query 'ResourceDescriptions[].Identifier' --output text > resources.txt
while read -r line; do
aws cloudcontrol delete-resource --region ${{ env.AWS_REGION }} --type $RESOURCE_TYPE --identifier $line
done < resources.txt
done
aws cloudcontrol list-resources --region ${{ env.AWS_REGION }} --type-name ${{ env.RESOURCE_TYPES }} --query 'ResourceDescriptions[].Identifier' --output text > resources.txt
# delete resource
while read -r line; do
aws cloudcontrol delete-resource --region ${{ env.AWS_REGION }} --type ${{ env.RESOURCE_TYPES }} --identifier $line
done < resources.txt
#!/bin/bash

# ------------------------------------------------------------
# Copyright 2023 The Radius Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------

APP_NAME=$1
APP_LABEL='RadiusApplication'
RESOURCE_TYPES='AWS::RDS::DBInstance,AWS::RDS::DBSubnetGroup,AWS::MemoryDB::Cluster,AWS::MemoryDB::SubnetGroup'

for resource_type in ${RESOURCE_TYPES//,/ }
do
aws cloudcontrol list-resources --type-name "$resource_type" --query "ResourceDescriptions[].Identifier" --output text | tr '\t' '\n' | while read identifier
do
aws cloudcontrol get-resource --type-name "$resource_type" --identifier "$identifier" --query "ResourceDescription.Properties" --output text | while read resource
do
resource_tags=$(jq -c -r .Tags <<< "$resource")
for tag in $(jq -c -r '.[]' <<< "$resource_tags")
do
key=$(jq -r '.Key' <<< "$tag")
value=$(jq -r '.Value' <<< "$tag")
if [[ "$key" == "$APP_LABEL" && "$value" == "$APP_NAME" ]]
then
echo "Deleting resource of type: $resource_type with identifier: $identifier"
aws cloudcontrol delete-resource --type-name "$resource_type" --identifier "$identifier"
fi
done
done
done
done
14 changes: 4 additions & 10 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -306,25 +306,19 @@ jobs:
--subscription $SUBSCRIPTION_ID \
--name $RESOURCE_GROUP \
--yes
- name: Delete AWS Resources
- name: Delete EKS Cluster
if: always() && matrix.credential == 'aws'
env:
EKS_CLUSTER_NAME: ${{ steps.gen-id.outputs.TEST_EKS_CLUSTER_NAME }}
UNIQUE_APP_NAME: ${{ steps.gen-id.outputs.TEST_UNIQUE_APP_NAME }}
run: |
# Uninstall Radius from EKS cluster
rad uninstall kubernetes
# Delete EKS cluster
echo "Deleting EKS cluster: $EKS_CLUSTER_NAME"
eksctl delete cluster --name $EKS_CLUSTER_NAME --region ${{ env.AWS_REGION }} --wait
# Delete AWS resources
# get the arn list of all resources tagged by the appname: $UNIQUE_APP_NAME
arn_list=$(aws resourcegroupstaggingapi get-resources --tag-filters Key=application,Values=$UNIQUE_APP_NAME --query 'ResourceTagMappingList[*].ResourceARN' --output text)
# delete all resources tagged by appname: $UNIQUE_APP_NAME
# tag the resource
# get the list of all resources in account
# list all memorydb clusters
- name: Delete AWS Resources
run: |
./.github/scripts/delete-aws-resources.sh ${{ steps.gen-id.outputs.TEST_UNIQUE_APP_NAME }}
- name: Create GitHub issue on failure
if: failure() && github.event_name != 'pull_request'
run: gh issue create --title "Samples deployment failed for ${{ matrix.app }}" --body "Test failed on ${{ github.repository }}. See [workflow logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for more details." --repo ${{ github.repository }}
1 change: 1 addition & 0 deletions reference-apps/eshop/iac/eshop.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ module aws 'infra/aws.bicep' = if (platform == 'aws') {
environment: environment
adminLogin: adminLogin
adminPassword: adminPassword
applicationName: appName
}
}

Expand Down
18 changes: 9 additions & 9 deletions reference-apps/eshop/iac/infra/aws.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ param environment string
param application string

@description('Radius application name')
param appname string
param applicationName string

@description('SQL administrator username')
param adminLogin string
Expand Down Expand Up @@ -39,7 +39,7 @@ resource sqlSubnetGroup 'AWS.RDS/DBSubnetGroup@default' = {
Tags: [
{
Key: 'RadiusApplication'
Value: application
Value: applicationName
}
]
}
Expand Down Expand Up @@ -68,7 +68,7 @@ resource identityDb 'AWS.RDS/DBInstance@default' = {
Tags: [
{
Key: 'RadiusApplication'
Value: application
Value: applicationName
}
]
}
Expand Down Expand Up @@ -97,7 +97,7 @@ resource catalogDb 'AWS.RDS/DBInstance@default' = {
Tags: [
{
Key: 'RadiusApplication'
Value: application
Value: applicationName
}
]
}
Expand Down Expand Up @@ -126,7 +126,7 @@ resource orderingDb 'AWS.RDS/DBInstance@default' = {
Tags: [
{
Key: 'RadiusApplication'
Value: application
Value: applicationName
}
]
}
Expand Down Expand Up @@ -155,7 +155,7 @@ resource webhooksDb 'AWS.RDS/DBInstance@default' = {
Tags: [
{
Key: 'RadiusApplication'
Value: application
Value: applicationName
}
]
}
Expand All @@ -170,7 +170,7 @@ resource redisSubnetGroup 'AWS.MemoryDB/SubnetGroup@default' = {
Tags: [
{
Key: 'RadiusApplication'
Value: application
Value: applicationName
}
]
}
Expand All @@ -189,7 +189,7 @@ resource keystoreCache 'AWS.MemoryDB/Cluster@default' = {
Tags: [
{
Key: 'RadiusApplication'
Value: application
Value: applicationName
}
]
}
Expand All @@ -208,7 +208,7 @@ resource basketCache 'AWS.MemoryDB/Cluster@default' = {
Tags: [
{
Key: 'RadiusApplication'
Value: application
Value: applicationName
}
]
}
Expand Down

0 comments on commit 7e0d0ae

Please sign in to comment.