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(terraform)!: access backend behind firewall #261

Closed
wants to merge 20 commits into from
Closed
Changes from 2 commits
Commits
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/workflows/terraform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ on:
required: false
default: "."

subscription:
description: The subscription to deploy in
type: string
required: true

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this not just a duplicate of the secret AZURE_SUBSCRIPTION_ID?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use the subscription id on --resource-group tag inline command, if so, yes I think we can scrap that then.

Copy link
Contributor Author

@sebastianlolv sebastianlolv Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can rather rename it to project_name or something similar? Since we need to reference it in the key vault name?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't even notice that we're talking about a Key Vault here, and not a Storage account 😅

How would this work if you're running a Terraform config with multiple or no Key Vaults? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea 😅 I think I might have read this wrong, looks like they whitelist it in the tfstate storage accounts when I look at Radix's version of it. 😅 I can turn it into something like what they have done.

terraform_version:
description: The version of Terraform to install.
type: string
Expand Down Expand Up @@ -67,6 +72,9 @@ env:

ENCRYPTION_PASSWORD: ${{ secrets.ENCRYPTION_PASSWORD }}

resource_group_name: ${{ inputs.subscription }}-tfstate
key_vault_name: kv-${{ inputs.subscription }}-${{ inputs.environment }}

jobs:
terraform-plan:
name: Terraform Plan
Expand Down Expand Up @@ -173,6 +181,24 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: 'Az login'
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

- name: Get GitHub Public IP
id: github_public_ip
uses: haythem/[email protected]

- name: Add GitHub IP to Key Vault
run: |
az keyvault account network-rule add \
--resource-group "${{ env.resource_group_name }}" \
--name "${{ env.key_vault_name }}" \
--ip-address ${{ steps.github_public_ip.outputs.ipv4 }} >/dev/null

- name: Download artifact
uses: actions/download-artifact@v3
with:
Expand All @@ -198,3 +224,10 @@ jobs:
uses: GeekyEggo/delete-artifact@54ab544f12cdb7b71613a16a2b5a37a9ade990af
with:
name: ${{ inputs.artifact_name }}

- name: Revoke GitHub IP on Key Vault
run: |
az keyvault account network-rule remove \
--resource-group "${{ env.resource_group_name }}" \
--name "${{ env.key_vault_name }}" \
--ip-address ${{ steps.github_public_ip.outputs.ipv4 }} >/dev/null