Azure Policy Export to Terraform Pipeline

Dave O'Donohoe 170 Reputation points
2024-10-08T07:45:26.4333333+00:00

Hi,

Is it possibe to export an Azure Policy configuration code (or a selection of definitions) for use in a Terraform pipeline?

I see the Azure Export Tool, but not sure how valid or suitable it might be:

https://learn.microsoft.com/en-us/azure/developer/terraform/azure-export-for-terraform/export-terraform-overview

Any guidance on experiences here very much appreciated :)

 

Azure Policy
Azure Policy
An Azure service that is used to implement corporate governance and standards at scale for Azure resources.
1,014 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2024-10-29T09:02:26.2966667+00:00

    Hi @YogiBear
    Welcome to the Microsoft Q&A Platform! Thank you for asking your question here. 

    it is possible to export an Azure Policy configuration code for use in a Terraform pipeline. The Azure Export Tool that you mentioned can be used to export Azure Policy definitions and assignments to Terraform configuration files. 

    The Azure Export Tool generates Terraform configuration files that can be used to create and manage Azure Policy definitions and assignments. The generated files include the necessary Terraform code to create and manage the Azure Policy resources, including the policy definitions, policy assignments, and policy initiatives. 

    To use the Azure Export Tool, you need to have the Azure CLI installed on your machine. Once you have installed the Azure CLI, you can run the following command to export the Azure Policy configuration to Terraform: 
    az policy export --type terraform --output-directory <output_directory>
    Replace <output_directory> with the path to the directory where you want to save the Terraform configuration files. 

    After running this command, the Azure Export Tool will generate the Terraform configuration files in the specified directory. You can then use these files in your Terraform pipeline to create and manage Azure Policy resources. 
    If you have any further queries, do let us know


    If the answer is helpful, please click "Accept Answer" and "Upvote it"


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.