I need to deploy a storage account to azure with terraform. I am using Github Actions as CICD platform. For this need i need to create a service principal and provide contribiutor role to it. But i am unable to do it. I have attached a image. How can i solve this ?
Please don’t ask the same question multiple time. I have answered you here:
I am using Azure+terrafrom playground. Not azure playground.
You cannot add an application registration, or add a new secret to an existing application registration. The lab is designed so you use the Azure playground from within the terminal session that has already been set up.
I need to do it via CICD ( Github Actions ). So how can i do this ? Without CICD i can deploy resources even from my Laptop. There should be a Way. Before Kodekloud , I used cloudguru ( another sandbox platform) . there they provided the Client-ID and Secret in the Lab session.
How do you deploy from your laptop?
I write the main.tf in visualcode .
- Then i login to the azure portal via visual code terminal ( I have intsall az cli, terraform in my terminal )
- then i simply execute terffaform plan & terraform execute.Below i have mentioned my mainf.tf. I am simply creating a storage account in azure.
terraform {
required_version = “>= 1.3.0”
required_providers {
azurerm = {
source = “hashicorp/azurerm”
version = “>= 3.43.0”
}
}
}
provider “azurerm” {
features {}
skip_provider_registration = true
}
resource “azurerm_resource_group” “rg” {
name = “kml_rg_main-9cf253d78b7c42e3”
location = “West US”
}
resource “azurerm_storage_account” “storage” {
name = “faslanstra45”
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
account_tier = “Standard”
account_replication_type = “LRS”
}
resource “azurerm_storage_account” “storage1” {
name = “faslanstra46”
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
account_tier = “Standard”
account_replication_type = “LRS”
}
I’ve not tried it but you may be able to use az login
on GitHub:
az login --tenant $YOUR_TENANT_ID -u $YOUR_USERNAME -p $YOUR_PASSWORD
I tried it - you can login with Azure CLI with the Credentials and Tenant ID.
but Github is on the website right. you are telling that i need to download the Github app login to azure. Also will this work when deploy a resource via CICD
I mean in your GitHub action use Azure CLI.
Hi , Azure+Terraform playground is not starting. Any update is being done to it ?
Hi ,
I tried as you mention. below i have mentioned my CICP pipeline and error message i am getting.
CICD Pipeline
name: ‘Terraform’
on:
push:
branches: [ “main” ]
paths: ‘**.tf’
permissions:
contents: read
jobs:
terraform:
name: ‘Terraform’
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v3
# Install Azure CLI
- name: Install Azure CLI
run: |
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
# Log in to Azure CLI
- name: Azure Login
run: |
az login --tenant 30fe8ff1-adc6-444d-ba94-1238894df42c -u kk_lab_user_main-b911665b0069409b@azurekmlprodkodekloud.onmicrosoft.com -p pJm4^qSdAcUw4Rog
# 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
# Install Azure CLI
- name: terraform import
run: |
terraform import azurerm_resource_group.rg /subscriptions/a2b28c85-1948-4263-90ca-bade2bac4df4/resourceGroups/kml_rg_main-b911665b0069409b
# Generates an execution plan for Terraform
- name: Terraform Plan
run: terraform plan -input=false
# Build or change infrastructure according to Terraform configuration files
- name: Terraform Apply
run: terraform apply -auto-approve -input=false
Hi Team,
Can i get a Solution for this ? I hardly need to simulate this with CICD ?