From 4bf31058de17b824eea189232eb60f6822eccc29 Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Fri, 16 Feb 2024 20:24:30 -0500 Subject: [PATCH] Issue #45: Update pipeline with aks credentials to apply kubernetes manifest from terraform --- apply-terraform.yml | 54 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/apply-terraform.yml b/apply-terraform.yml index 954f5cdf..ce38a567 100644 --- a/apply-terraform.yml +++ b/apply-terraform.yml @@ -19,11 +19,31 @@ stages: - job: TerraformInitPlan displayName: "Terraform Init and Plan" steps: + - task: AzureCLI@2 + displayName: "Azure CLI Login" + inputs: + azureSubscription: $(serviceConnectionName) + scriptType: "bash" + scriptLocation: "inlineScript" + inlineScript: | + echo "Successfully logged in with Azure CLI" + + - task: AzureCLI@2 + displayName: "Get AKS Credentials" + inputs: + azureSubscription: $(serviceConnectionName) + scriptType: "bash" + scriptLocation: "inlineScript" + inlineScript: | + az aks get-credentials --name --resource-group --admin --file ~/.kube/config + echo "AKS credentials configured for kubectl" + - task: DownloadSecureFile@1 name: DownloadSecureVars - displayName: 'Download staging.tfvars' + displayName: "Download staging.tfvars" inputs: - secureFile: 'staging.tfvars' + secureFile: "staging.tfvars" + - task: TerraformTaskV2@2 displayName: Terra Init inputs: @@ -35,12 +55,13 @@ stages: backendAzureRmStorageAccountName: "$(storageAccountName)" backendAzureRmContainerName: "$(containerName)" backendAzureRmKey: "$(stateKey)" + - task: TerraformTaskV2@2 displayName: Terra Plan inputs: provider: "azurerm" command: "plan" - commandOptions: '-var-file=$(DownloadSecureVars.SecureFilePath)' + commandOptions: "-var-file=$(DownloadSecureVars.SecureFilePath)" workingDirectory: "$(System.DefaultWorkingDirectory)/terraform/staging" environmentServiceNameAzureRM: "$(serviceConnectionName)" @@ -59,11 +80,32 @@ stages: deploy: steps: - checkout: self + + - task: AzureCLI@2 + displayName: "Azure CLI Login" + inputs: + azureSubscription: $(serviceConnectionName) + scriptType: "bash" + scriptLocation: "inlineScript" + inlineScript: | + echo "Successfully logged in with Azure CLI" + + - task: AzureCLI@2 + displayName: "Get AKS Credentials" + inputs: + azureSubscription: $(serviceConnectionName) + scriptType: "bash" + scriptLocation: "inlineScript" + inlineScript: | + az aks get-credentials --name $(aks-name) --resource-group $(resource-group) --admin --file ~/.kube/config + echo "AKS credentials configured for kubectl" + - task: DownloadSecureFile@1 name: DownloadSecureVars - displayName: 'Download staging.tfvars' + displayName: "Download staging.tfvars" inputs: - secureFile: 'staging.tfvars' + secureFile: "staging.tfvars" + - task: TerraformTaskV2@2 displayName: Terra Init inputs: @@ -80,6 +122,6 @@ stages: inputs: provider: "azurerm" command: "apply" - commandOptions: '-var-file=$(DownloadSecureVars.SecureFilePath)' + commandOptions: "-var-file=$(DownloadSecureVars.SecureFilePath)" workingDirectory: "$(System.DefaultWorkingDirectory)/terraform/staging" environmentServiceNameAzureRM: "$(serviceConnectionName)"