Terraform Azure Tags for user who executed the code.

Amjad Nagori 286 Reputation points
2021-05-08T10:41:10.57+00:00

Hi,
I have to add a tag in Azure Resource while deploying it through Terraform, this tag should automatically fetch username/email who executing the code. Is there anyway we can refer this in Terraform code like some function?
I want to add CreatedBy tag which should automatically put username in Azure-

    tags                =   {
                          Business = var.business
                          Organization = var.company
                          Environment = var.env
                          CreatedOn =  formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp())
                          CreatedBy = **<> (this value should be automatically popup based on user who executed Terraform code)**
                        }
Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,175 questions
{count} votes

Accepted answer
  1. Andreas Baumgarten 102.6K Reputation points MVP
    2021-05-08T11:12:37.917+00:00

    Hi @Amjad Nagori ,

    I haven't tried this by myself. But maybe it helps to get started:

    https://thegrayzone.co.uk/blog/2017/03/external-terraform-provider-powershell/

    The stdout of the PowerShell could be done like this:

    Write-Output $env:USER  
    

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten


0 additional answers

Sort by: Most helpful