Skip to content

Commit

Permalink
Modified code for user mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusB-DevOps committed Dec 9, 2024
1 parent 419b8a4 commit f726345
Showing 1 changed file with 15 additions and 26 deletions.
41 changes: 15 additions & 26 deletions .github/workflows/terraform-apply.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,36 @@ jobs:
steps:
#Step 0: Read user mapping
- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@v
with:
fetch-depth: 0
- name: Checkout secrets
uses: actions/checkout@v3
with:
secrets: USER_MAPPING_JSON

- name: List root directory
run: ls -la

- name: List .github/workflows directory
run: ls -la .github/workflows

- name: Read User Mapping (Improved)
- name: Read User Mapping
id: user-mapping
run: |
USER_MAPPING=$(secrets.USER_MAPPING_JSON) # Assuming stored as a GitHub Secret
USER_CREDENTIALS=$(jq -r --arg USERNAME "$GITHUB_ACTOR" '.[$USERNAME]' <<< "$USER_MAPPING")
echo "::set-output name=user-mapping::${USER_CREDENTIALS}"
USER_MAPPING=$(cat .github/workflows/user-mapping.json)
echo "::set-output name=user-mapping::$USER_MAPPING"
- name: Print user mapping
- name: Print User Mapping
run: echo "${{ steps.user-mapping.outputs.user-mapping }}"

# Step 0.1: Set AWS credentials
- name: Set AWS Credentials (Simplified)
- name: Set AWS Credentials
id: set-aws-credentials
run: |
USER_CREDENTIALS=$(echo "${{ steps.user-mapping.outputs.user-mapping }}" | jq -r '.AWS_SECRET_ACCESS_KEY')
echo "AWS_SECRET_ACCESS_KEY=$USER_CREDENTIALS" >> $GITHUB_ENV
USER_CREDENTIALS=$(echo "${{ steps.user-mapping.outputs.user-mapping }}" | jq -r '.AWS_SECRET_KEY_ID')
echo "AWS_SECRET_KEY_ID=$USER_CREDENTIALS" >> $GITHUB_ENV
USERNAME="${{ github.actor }}"
USER_MAPPING="${{ steps.user-mapping.outputs.user-mapping }}"
AWS_SECRET_ACCESS_KEY=$(echo $USER_MAPPING | jq -r --arg USERNAME "$USERNAME" '.[$USERNAME].AWS_SECRET_ACCESS_KEY')
AWS_SECRET_KEY_ID=$(echo $USER_MAPPING | jq -r --arg USERNAME "$USERNAME" '.[$USERNAME].AWS_SECRET_KEY_ID')
echo "AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}" >> $GITHUB_ENV
echo "AWS_SECRET_KEY_ID=${AWS_SECRET_KEY_ID}" >> $GITHUB_ENV
# Step 1: Configure AWS credentials
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ env.AWS_SECRET_KEY_ID }}
aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }}
aws-region: eu-central-1
aws-region: us-east-1

# Step 2: Checkout the repository code
#- name: Checkout Repository
# uses: actions/checkout@v4

Expand Down

0 comments on commit f726345

Please sign in to comment.