We are using Terraform to manage our infrastructure.
One of the tags that we use is called updatedBy and it's supposed to show the e-mail of the person that updated that resource:
tags = {
"updatedBY" = "name.surname@contoso.com"
}
As you can imagine so many times people input the wrong e-mail.
Is there a way I can put that e-mail in a variable using:
WHOAMI
: for Linux usersgit config user.email
: for bothIn my opinion git config user.email
should be the way to go because it's OS agnostic and all our Terraform engineers use Git.
But how to put that into a variable so they cannot be wrong again?
Use the AzureRM Client Config provider and the AADUser provider to update with the Deploying Users UPN
data "azurerm_client_config" "current" {}
data "azuread_user" "current_user" {
object_id = data.azurerm_client_config.current.object_id
}
resource "azurerm_resource_group" "rg" {
name = var.resourceGroupName
location = var.location
tags = {
"updatedBY" = data.azuread_user.current_user.user_principal_name
}
}