Skip to content

Commit

Permalink
Switch to using OIDC (tjcorr#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjcorr authored Jun 8, 2022
1 parent 1596be8 commit bfbdc78
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 39 deletions.
27 changes: 0 additions & 27 deletions .github/workflows/oidc-test.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,26 @@ on:
branches:
- main

#Special permissions required for OIDC authentication
permissions:
id-token: write
contents: read
pull-requests: write

#These environment variables are used by the terraform azure provider to authenticate.
#To eliminate the use of stored secrets consider switching to OIDD.
#These environment variables are used by the terraform azure provider to setup OIDD authenticate.
env:
ARM_CLIENT_ID: "${{ secrets.ARM_CLIENT_ID }}"
ARM_CLIENT_SECRET: "${{ secrets.ARM_CLIENT_SECRET }}"
ARM_SUBSCRIPTION_ID: "${{ secrets.ARM_SUBSCRIPTION_ID }}"
ARM_TENANT_ID: "${{ secrets.ARM_TENANT_ID }}"
ARM_CLIENT_ID: "${{ secrets.AZURE_CLIENT_ID }}"
ARM_SUBSCRIPTION_ID: "${{ secrets.AZURE_SUBSCRIPTION_ID }}"
ARM_TENANT_ID: "${{ secrets.AZURE_TENANT_ID }}"

jobs:
terraform-plan:
name: 'Terraform Plan'
runs-on: ubuntu-latest
environment: production
environment: production-readonly
env:
#this is needed since we are running terraform with read-only permissions
ARM_SKIP_PROVIDER_REGISTRATION: true
outputs:
tfplanExitCode: ${{ steps.tf-plan.outputs.exitcode }}

Expand All @@ -35,6 +41,7 @@ jobs:
uses: hashicorp/setup-terraform@v1
with:
terraform_wrapper: false


# Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
- name: Terraform Init
Expand Down Expand Up @@ -115,7 +122,7 @@ jobs:
name: 'Terraform Apply'
if: github.ref == 'refs/heads/main' && needs.terraform-plan.outputs.tfplanExitCode == 2
runs-on: ubuntu-latest
environment: production-approval
environment: production-readwrite
needs: [terraform-plan]

steps:
Expand All @@ -126,7 +133,7 @@ jobs:
# Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1

# Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
- name: Terraform Init
run: terraform init
Expand Down
6 changes: 4 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@ terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">= 2.62"
version = ">= 3.7.0"
}
}

backend "azurerm" {
resource_group_name = "rg-tf-pipeline-demo-state"
storage_account_name = "tfpipelinedemostate"
storage_account_name = "tfpipelinedemo"
container_name = "tfstate"
key = "terraform.tfstate"
use_oidc = true
}
}

provider "azurerm" {
features {}
use_oidc = true
}

resource "azurerm_resource_group" "rg-aks" {
Expand Down
2 changes: 1 addition & 1 deletion terraform.tfvars
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
resource_group_name = "rg-tf-pipeline-demo3"
resource_group_name = "rg-tf-pipeline-demo"
location = "eastus"

0 comments on commit bfbdc78

Please sign in to comment.