Posts

Showing posts from April, 2024

Azure - terraform Links

 https://github.com/JoeAtRest/terraform-azurerm-apim-api/blob/master/variables.tf APIM https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/api_management_user#argument-reference

Connectivity Step by Step

 Powershell to set environment variable  // The below script will set the environment variable on the OS level. # Set environment variables for DEV $env:TF_VAR_subscription_id_DEV = "DEV_SubscriptionId" $env:TF_VAR_tenant_id_DEV = "DEV_TenantId" $env:TF_VAR_key_vault_name_DEV = "DEV_KeyVaultName" $env:TF_VAR_key_vault_secret_name_DEV = "DEV_KeyVaultSecretName" # Set environment variables for QA $env:TF_VAR_subscription_id_QA = "QA_SubscriptionId" $env:TF_VAR_tenant_id_QA = "QA_TenantId" $env:TF_VAR_key_vault_name_QA = "QA_KeyVaultName" $env:TF_VAR_key_vault_secret_name_QA = "QA_KeyVaultSecretName" # Set environment variables for UAT $env:TF_VAR_subscription_id_UAT = "UAT_SubscriptionId" $env:TF_VAR_tenant_id_UAT = "UAT_TenantId" $env:TF_VAR_key_vault_name_UAT = "UAT_KeyVaultName" $env:TF_VAR_key_vault_secret_name_UAT = "UAT_KeyVaultSecretName" # Set environment variab...

access

 User subscription_id tenant_id client_id client_secret key_vault_name key_vault_secret_name     User: In this context, it refers to the service principal user account that Terraform will use to authenticate with Azure.     subscription_id: This is required for Terraform to identify the Azure subscription it will be managing resources within.     tenant_id: Also known as the directory ID, it identifies the Azure Active Directory (AAD) tenant associated with the subscription. Terraform uses this to authenticate with Azure AD.     client_id: This is the unique identifier for the service principal itself. Terraform uses this as part of the authentication process to prove the identity of the service principal.     client_secret: This is the password or secret key associated with the service principal. Terraform uses this secret key during the authentication process to authenticate the service principal.  ...

dev

provider.tf # Provider Configuration # provider "azurerm" { #   features {} # } # Module for Azure API Management module "apim" {   source = "../modules/apim"   # Pass any required variables to the APIM module   # apim_service_name   = var.apim_service_name   # resource_group_name = var.resource_group_name   # Add any other required variables here } # Define a data source for the existing resource group data "azurerm_resource_group" "dev_neogenomics_rg" {   name = "rg-esp-dev" } # Define a data source for the existing virtual network data "azurerm_virtual_network" "dev_neogenomics_rg_vnet" {   name                = "VNET-Dev-10.117.128.0-17"   resource_group_name = data.azurerm_resource_group.dev_neogenomics_rg.name } # Define a data source for the existing subnet within the virtual network data "azurerm_subnet" "dev_neogenomics_subnet" {   name...

APIM

main.tf      # Module for Azure API Management module "apim" {   source = "../modules/apim"   # Pass any required variables to the APIM module   apim_service_name   = var.apim_service_name   publisher_name      = var.publisher_name   publisher_email     = var.publisher_email   resource_group_name = var.resource_group_name   location = var.location   sku_name = var.sku_name   # Add any other required variables here } # Define a data source for the existing resource group data "azurerm_resource_group" "cg" {   name = var.resource_group_name } # Define a data source for the existing virtual network data "azurerm_virtual_network" "dev_neogenomics_rg_vnet" {   name                = var.vnet_name   resource_group_name = data.azurerm_resource_group.dev_neogenomics_rg.name } # Define a data so...

Terraform Pipeline - Linting and static code analysis

    Sure, let's break down the components of a CI/CD pipeline for Terraform infrastructure as code (IaC) using Azure Pipelines: Pull Request (PR) Workflow : Trigger : Automated when a pull request is opened or updated in the version control repository (e.g., GitHub, Azure Repos). Steps : Code Review : Automated or manual code review process where team members review the Terraform code changes. Automating the code review process for Terraform code changes involves setting up tools and workflows to analyze and evaluate the code automatically. Here are some steps to automate the code review process: Use Terraform Linters : Integrate Terraform linters such as tflint or terraform fmt into your CI/CD pipeline. These tools can automatically check Terraform code against best practices, style conventions, and potential errors. Configure them to run as part of your CI pipeline to catch issues early.   Both tflint and terraform fmt are free and open-source tools commonly used in...

File Structure

Image
terraform/ ├── modules/ │   ├── apim/ │   │   ├── main.tf │   │   ├── variables.tf │   │   └── outputs.tf │   ├── logic_app/ │   │   ├── main.tf │   │   ├── variables.tf │   │   └── outputs.tf │   ├── function_app/ │   │   ├── main.tf │   │   ├── variables.tf │   │   └── outputs.tf │   ├── app_service_plan/ │   │   ├── main.tf │   │   ├── variables.tf │   │   └── outputs.tf │   └── app_insights/ │       ├── main.tf │       ├── variables.tf │       └── outputs.tf ├── dev/ │   ├── main.tf │   ├── provider.tf              <-- Plac...

Service Principle Account - Connection -Terraform

  If you are using a service principal for Terraform connectivity to Azure, you typically don't need to configure az login or set the default subscription because Terraform interacts with Azure using the credentials of the service principal provided in the Terraform configuration. When using a service principal, Terraform retrieves the necessary authentication details (such as client ID, client secret, and tenant ID) from environment variables, configuration files, or other secure means. These credentials are used by Terraform to authenticate with Azure and perform operations on your behalf. However, if you are also using the Azure CLI ( az ) for other tasks outside of Terraform, you may still need to configure az login with the appropriate credentials, especially if you need to perform manual operations or interact with Azure resources directly from the command line. In such cases, you can log in with the service principal credentials using the following command:   az login...
 Details we need variable "subscription_id" {} variable "tenant_id" {} variable "client_id" {} variable "key_vault_name" {} variable "key_vault_secret_name" {}

Pre-requsites

To work with Terraform and connect it with Azure from your Virtual Desktop Infrastructure (VDI), you'll need several prerequisites. Here's a list of the necessary components: Virtual Desktop Infrastructure (VDI) : Make sure you have access to a VDI environment where you can install and run Terraform. Azure Subscription : You need an active Azure subscription. If you don't have one, you can sign up for a free account or obtain a subscription through your organization. Azure CLI : Install Azure Command-Line Interface (CLI) on your VDI. Azure CLI allows you to interact with Azure services from the command line. You can download and install it from the official Azure documentation. Installed -- did this Terraform : Install Terraform on your VDI. Terraform is an infrastructure as code tool used to build, change, and version infrastructure safely and efficiently. You can download Terraform from the official website and install it on your VDI. Azure Service Principal ...

Azure Connectivity

Yes, you can add connectivity configurations, such as service principal authentication details, to your Terraform file structure. Here's how you can organize your Terraform configuration files to include connectivity settings: terraform/ ├── modules/ │   └── resource_group/ │       ├── main.tf │       ├── variables.tf │       └── outputs.tf ├── connectivity/ │   └── azure/ │       ├── main.tf │       └── variables.tf ├── dev/ │   ├── main.tf │   ├── variables.tf │   ├── outputs.tf │   └── terraform.tfvars ├── qa/ │   ├── main.tf │   ├── variables.tf │   ├── outputs.tf │   └── terraform.tfvars ├── uat/ │   ├── main.tf │   ├── variables.tf │   ├── outputs.tf │   └── terraform.tfvars └── prod/  ...