118 lines
3.4 KiB
HCL
118 lines
3.4 KiB
HCL
resource "random_pet" "rg_name" {
|
|
prefix = var.resource_group_name_prefix
|
|
}
|
|
|
|
resource "azurerm_resource_group" "rg" {
|
|
location = var.resource_group_location
|
|
name = random_pet.rg_name.id
|
|
}
|
|
|
|
resource "random_string" "apim_service_name" {
|
|
length = 8
|
|
lower = true
|
|
numeric = false
|
|
special = false
|
|
upper = false
|
|
}
|
|
|
|
resource "azurerm_api_management" "apim_service" {
|
|
name = "${random_string.apim_service_name.result}-apim-service"
|
|
location = azurerm_resource_group.rg.location
|
|
resource_group_name = azurerm_resource_group.rg.name
|
|
publisher_name = "Example Publisher"
|
|
publisher_email = "publisher@example.com"
|
|
sku_name = "Developer_1"
|
|
tags = {
|
|
Environment = "Example"
|
|
}
|
|
policy {
|
|
xml_content = <<XML
|
|
<policies>
|
|
<inbound />
|
|
<backend />
|
|
<outbound />
|
|
<on-error />
|
|
</policies>
|
|
XML
|
|
}
|
|
}
|
|
|
|
resource "random_string" "api_name" {
|
|
length = 8
|
|
lower = true
|
|
numeric = false
|
|
special = false
|
|
upper = false
|
|
}
|
|
|
|
resource "random_string" "content_value" {
|
|
length = 8
|
|
lower = true
|
|
numeric = false
|
|
special = false
|
|
upper = false
|
|
}
|
|
|
|
resource "azurerm_api_management_api" "api" {
|
|
name = "${random_string.api_name.result}-api"
|
|
resource_group_name = azurerm_resource_group.rg.name
|
|
api_management_name = azurerm_api_management.apim_service.name
|
|
revision = "1"
|
|
display_name = "${random_string.api_name.result}-api"
|
|
path = "example"
|
|
protocols = ["https", "http"]
|
|
description = "An example API"
|
|
import {
|
|
content_format = var.open_api_spec_content_format
|
|
content_value = var.open_api_spec_content_value
|
|
}
|
|
}
|
|
|
|
resource "random_string" "product_name" {
|
|
length = 8
|
|
lower = true
|
|
numeric = false
|
|
special = false
|
|
upper = false
|
|
}
|
|
|
|
resource "azurerm_api_management_product" "product" {
|
|
product_id = "${random_string.product_name.result}-product"
|
|
resource_group_name = azurerm_resource_group.rg.name
|
|
api_management_name = azurerm_api_management.apim_service.name
|
|
display_name = "${random_string.product_name.result}-product"
|
|
subscription_required = true
|
|
approval_required = false
|
|
published = true
|
|
description = "An example Product"
|
|
}
|
|
|
|
resource "random_string" "group_name" {
|
|
length = 8
|
|
lower = true
|
|
numeric = false
|
|
special = false
|
|
upper = false
|
|
}
|
|
|
|
resource "azurerm_api_management_group" "group" {
|
|
name = "${random_string.group_name.result}-group"
|
|
resource_group_name = azurerm_resource_group.rg.name
|
|
api_management_name = azurerm_api_management.apim_service.name
|
|
display_name = "${random_string.group_name.result}-group"
|
|
description = "An example group"
|
|
}
|
|
|
|
resource "azurerm_api_management_product_api" "product_api" {
|
|
resource_group_name = azurerm_resource_group.rg.name
|
|
api_management_name = azurerm_api_management.apim_service.name
|
|
product_id = azurerm_api_management_product.product.product_id
|
|
api_name = azurerm_api_management_api.api.name
|
|
}
|
|
|
|
resource "azurerm_api_management_product_group" "product_group" {
|
|
resource_group_name = azurerm_resource_group.rg.name
|
|
api_management_name = azurerm_api_management.apim_service.name
|
|
product_id = azurerm_api_management_product.product.product_id
|
|
group_name = azurerm_api_management_group.group.name
|
|
} |