I have a no. of API management services setup on Azure already but they are not provisioned using Terraform. Now I want to using terraform to update the backend HTTP endpoint and policies. Is it possible to do so? Is there any data sources for apim I can use? Any example I can refer to?
2
Answers
I tried in my environment and got below results:
Initially, I created
Azure APIM management service
using below terraform code.main.tf
Portal:
You can use the below terraform code to create resources that manage the backend HTTP endpoint and policies of that service.
main.tf
Console:
Portal:
Reference:
azurerm_api_management_backend | Resources | hashicorp/azurerm | Terraform Registry
azurerm_api_management_policy | Resources | hashicorp/azurerm | Terraform Registry
If you want to change an Azure resource (in this case Azure APIM), you’ll have to first declare the resource with the corresponding resource type (in this case azurerm_api_management) and then to import your existing resource into your Terraform’s state.
After importing, on the subsequent execution of
terraform plan
, you’ll see the changes terraform would like to execute based on the difference between your declaration and the current state of your APIM instance.You cannot use a terraform data source (like this) if you want to change (=manage) the resource. Data sources can only be used to read attributes from resources.