<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>azurerm &#8211; Johnny Morano&#039;s Tech Articles</title>
	<atom:link href="https://jmorano.moretrix.com/tag/azurerm/feed/" rel="self" type="application/rss+xml" />
	<link>https://jmorano.moretrix.com</link>
	<description>Ramblings of an old-fashioned space cowboy</description>
	<lastBuildDate>Sat, 30 Apr 2022 12:37:27 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.2</generator>

<image>
	<url>https://jmorano.moretrix.com/wp-content/uploads/2022/04/cropped-jmorano_emblem-32x32.png</url>
	<title>azurerm &#8211; Johnny Morano&#039;s Tech Articles</title>
	<link>https://jmorano.moretrix.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Use multiple Azure subscriptions in Terraform modules</title>
		<link>https://jmorano.moretrix.com/2022/04/use-multiple-azure-subscriptions-in-terraform-modules/</link>
					<comments>https://jmorano.moretrix.com/2022/04/use-multiple-azure-subscriptions-in-terraform-modules/#comments</comments>
		
		<dc:creator><![CDATA[Johnny Morano]]></dc:creator>
		<pubDate>Sat, 30 Apr 2022 12:37:27 +0000</pubDate>
				<category><![CDATA[Automation]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Terraform]]></category>
		<category><![CDATA[Azure]]></category>
		<category><![CDATA[azurerm]]></category>
		<category><![CDATA[DevOps]]></category>
		<guid isPermaLink="false">https://jmorano.moretrix.com/?p=1523</guid>

					<description><![CDATA[Due to billing or organizational structures, certain parts of the infrastructure could be divided over several Azure subscriptions.&#8230;]]></description>
										<content:encoded><![CDATA[
<p>Due to billing or organizational structures, certain parts of the infrastructure could be divided over several Azure subscriptions. From an infrastructure management point of view however, it might be interesting to manage the resources in those multiple subscriptions in one Terraform playbook.</p>



<p>In the <code>required_providers</code> section, the <code>configuration_aliases</code> must be configured first (usually in the <code>main.tf</code> file). This parameter must contain the same name (or names as the parameter takes a list of strings as input) as the <code>alias</code> parameter further below in the second <code>provider</code> section. Each <code>provider</code> section can have its own configuration parameters, such as for instance the <code>subscription_id</code>.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "3.4.0"
      configuration_aliases = [ azurerm.other-sub ]
    }
}

provider "azurerm" {
  subscription_id = var.subscription_id
  features {}
}

provider "azurerm" {
  alias           = "other-sub"
  subscription_id = var.other_subscription_id
  features {}
}
</pre>



<p>When calling a module, each <code>provider</code> containing an <code>alias</code> and which is required in the module, must be specified in the <code>providers</code> parameter. The key is the name configured in the <code>configuration_aliases</code> in the <code>required_providers</code> section of the module (see below), the value is the name of the provider <code>alias</code> in the playbook.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">module "diagnostic_sa_private_endpoint" {
  source = "../terraform_modules/private_endpoint/"
  providers = {
      azurerm.other-sub = azurerm.other-sub
  }

  for_each = { for snet in data.azurerm_subnet.subnets : snet.id => snet }
  ...
}</pre>



<p>The module itself (in <code>../terraform_modules/private_endpoint/</code>) however must again define the alias in a &#8220;<code>required_providers</code>&#8221; section. This means that a file must be include in the directory <code>../terraform_modules/private_endpoint </code>which includes:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">terraform {
  required_providers {
    azurerm = {
      source = "hashicorp/azurerm"
      configuration_aliases = [ azurerm.other-sub ]
    }
  }
}
</pre>



<p>Finally, all Azure resources which require the other Azure subscription, must include a &#8220;<code>provider</code>&#8221; line similar as:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">data "azurerm_private_dns_zone" "dns_zone" {
  provider            = azurerm.other-sub
  name                = var.private_dns_zone_name
}</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://jmorano.moretrix.com/2022/04/use-multiple-azure-subscriptions-in-terraform-modules/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Terraform: Create a map of subnet IDs in Azure</title>
		<link>https://jmorano.moretrix.com/2022/03/terraform-create-a-map-of-subnet-ids-in-azure/</link>
					<comments>https://jmorano.moretrix.com/2022/03/terraform-create-a-map-of-subnet-ids-in-azure/#respond</comments>
		
		<dc:creator><![CDATA[Johnny Morano]]></dc:creator>
		<pubDate>Fri, 04 Mar 2022 11:27:16 +0000</pubDate>
				<category><![CDATA[Automation]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Terraform]]></category>
		<category><![CDATA[Azure]]></category>
		<category><![CDATA[azurerm]]></category>
		<category><![CDATA[DevOps]]></category>
		<category><![CDATA[Hashicorp]]></category>
		<guid isPermaLink="false">https://jmorano.moretrix.com/?p=1295</guid>

					<description><![CDATA[The subnets accessor in the azurerm_virtual_network Terraform data source returns a list of subnet names only. In most&#8230;]]></description>
										<content:encoded><![CDATA[
<p>The <code>subnets</code> accessor in the <code>azurerm_virtual_network</code> Terraform data source returns a list of subnet names only. In most cases however, you will need to use a or multiple subnet IDs, for instance when deploying virtual machines. Instead of creating a new <code>datasource</code> (for possibly a small list of subnets) for each virtual machine you want to deploy, creating a <code>locals</code> map, which can be looked up afterwards, is going to be faster on the <code>apply</code> run.</p>



<p>Create a list of the existing virtual network subnets:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="monokai" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">data azurerm_subnet "subnets" {
  count = length(data.azurerm_virtual_network.my_vnet.subnets)

  name                 = data.azurerm_virtual_network.my_vnet.subnets[count.index]
  virtual_network_name = var.vnet_name
  resource_group_name  = var.resource_group
}

locals {
  subnets = tomap({
      for snet in data.azurerm_subnet.subnets: snet.name => snet.id
  })
}</pre>



<p>In the above example, we first loop over all subnet names, returned by <code>data.azurerm_virtual_network.my_vnet.subnets</code>, to create a list of Azure virtual network subnet objects.</p>



<p>Afterwards we create a <code>locals</code> map called <code>subnets</code>, which contains mapping like &#8220;subnet name points to subnet ID&#8221;.</p>



<p>Finally, when creating Azure network interfaces with an IP configuration, you can easily lookup the correct subnet ID based on the subnet name (which you might have configured per virtual machine)</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="monokai" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">resource "azurerm_network_interface" "my_nic" {
...
  ip_configuration {
    ...
    subnet_id = lookup(local.subnets, "my_subnet_name")
  }
...</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://jmorano.moretrix.com/2022/03/terraform-create-a-map-of-subnet-ids-in-azure/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
