Generated sample from henglu examples
This commit is contained in:
parent
482e26632b
commit
4958b3bdff
@ -0,0 +1,28 @@
|
|||||||
|
# Azure API Management
|
||||||
|
|
||||||
|
This template deploys an Azure API Management service, containing an API based on a provided Open API spec, a Group, and a Product that is associated with both.
|
||||||
|
|
||||||
|
## Terraform resource types
|
||||||
|
|
||||||
|
- [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet)
|
||||||
|
- [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group)
|
||||||
|
- [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string)
|
||||||
|
- [azurerm_api_management](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/api_management)
|
||||||
|
- [azurerm_api_management_api](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/api_management_api)
|
||||||
|
- [azurerm_api_management_product](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/api_management_product)
|
||||||
|
- [azurerm_api_management_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/api_management_group)
|
||||||
|
- [azurerm_api_management_product_api](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/api_management_product_api)
|
||||||
|
- [azurerm_api_management_product_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/api_management_product_group)
|
||||||
|
|
||||||
|
## Variables
|
||||||
|
|
||||||
|
| Name | Description | Default |
|
||||||
|
|-|-|-|
|
||||||
|
| `resource_group_name_prefix` | Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription. | rg |
|
||||||
|
| `resource_group_location` | Location of the resource group. | eastus |
|
||||||
|
| `open_api_spec_content_format` | The format of the content from which the API Definition should be imported. Possible values are: openapi, openapi+json, openapi+json-link, openapi-link, swagger-json, swagger-link-json, wadl-link-json, wadl-xml, wsdl and wsdl-link. | "" |
|
||||||
|
| `open_api_spec_content_value` | The Content from which the API Definition should be imported. When a content_format of *-link-* is specified this must be a URL, otherwise this must be defined inline. | "" |
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
[Quickstart: Deploy an Azure API Management service](https://learn.microsoft.com/azure/api-management/deploy-api-management-service-terraform)
|
110
quickstart/101-azure-api-management-create-with-api/main.tf
Normal file
110
quickstart/101-azure-api-management-create-with-api/main.tf
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
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 "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
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
output "resource_group_name" {
|
||||||
|
value = azurerm_resource_group.rg.name
|
||||||
|
}
|
||||||
|
|
||||||
|
output "apim_service_name" {
|
||||||
|
value = azurerm_api_management.apim_service.name
|
||||||
|
}
|
||||||
|
|
||||||
|
output "api_name" {
|
||||||
|
value = azurerm_api_management_api.api.name
|
||||||
|
}
|
||||||
|
|
||||||
|
output "product_name" {
|
||||||
|
value = azurerm_api_management_product.product.product_id
|
||||||
|
}
|
||||||
|
|
||||||
|
output "group_name" {
|
||||||
|
value = azurerm_api_management_group.group.name
|
||||||
|
}
|
||||||
|
|
||||||
|
output "service_id" {
|
||||||
|
description = "The ID of the API Management Service created"
|
||||||
|
value = azurerm_api_management.apim_service.id
|
||||||
|
}
|
||||||
|
|
||||||
|
output "gateway_url" {
|
||||||
|
description = "The URL of the Gateway for the API Management Service"
|
||||||
|
value = azurerm_api_management.apim_service.gateway_url
|
||||||
|
}
|
||||||
|
|
||||||
|
output "service_public_ip_addresses" {
|
||||||
|
description = "The Public IP addresses of the API Management Service"
|
||||||
|
value = azurerm_api_management.apim_service.public_ip_addresses
|
||||||
|
}
|
||||||
|
|
||||||
|
output "api_outputs" {
|
||||||
|
description = "The IDs, state, and version outputs of the APIs created"
|
||||||
|
value = {
|
||||||
|
id = azurerm_api_management_api.api.id
|
||||||
|
is_current = azurerm_api_management_api.api.is_current
|
||||||
|
is_online = azurerm_api_management_api.api.is_online
|
||||||
|
version = azurerm_api_management_api.api.version
|
||||||
|
version_set_id = azurerm_api_management_api.api.version_set_id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
output "product_ids" {
|
||||||
|
description = "The ID of the Product created"
|
||||||
|
value = azurerm_api_management_product.product.id
|
||||||
|
}
|
||||||
|
|
||||||
|
output "product_api_ids" {
|
||||||
|
description = "The ID of the Product/API association created"
|
||||||
|
value = azurerm_api_management_product_api.product_api.id
|
||||||
|
}
|
||||||
|
|
||||||
|
output "product_group_ids" {
|
||||||
|
description = "The ID of the Product/Group association created"
|
||||||
|
value = azurerm_api_management_product_group.product_group.id
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
terraform {
|
||||||
|
required_version = ">=1.0"
|
||||||
|
|
||||||
|
required_providers {
|
||||||
|
azurerm = {
|
||||||
|
source = "hashicorp/azurerm"
|
||||||
|
version = "~>3.0"
|
||||||
|
}
|
||||||
|
random = {
|
||||||
|
source = "hashicorp/random"
|
||||||
|
version = "~>3.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
provider "azurerm" {
|
||||||
|
features {}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
variable "resource_group_name_prefix" {
|
||||||
|
type = string
|
||||||
|
default = "rg"
|
||||||
|
description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription."
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "resource_group_location" {
|
||||||
|
type = string
|
||||||
|
default = "eastus"
|
||||||
|
description = "Location of the resource group."
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "open_api_spec_content_format" {
|
||||||
|
type = string
|
||||||
|
default = ""
|
||||||
|
description = "The format of the content from which the API Definition should be imported. Possible values are: openapi, openapi+json, openapi+json-link, openapi-link, swagger-json, swagger-link-json, wadl-link-json, wadl-xml, wsdl and wsdl-link."
|
||||||
|
validation {
|
||||||
|
condition = contains(["openapi", "openapi+json", "openapi+json-link", "openapi-link", "swagger-json", "swagger-link-json", "wadl-link-json", "wadl-xml", "wsdl", "wsdl-link"], var.open_api_spec_content_format)
|
||||||
|
error_message = "open_api_spec_content_format must be one of the following: openapi, openapi+json, openapi+json-link, openapi-link, swagger-json, swagger-link-json, wadl-link-json, wadl-xml, wsdl and wsdl-link."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "open_api_spec_content_value" {
|
||||||
|
type = string
|
||||||
|
default = ""
|
||||||
|
description = "The Content from which the API Definition should be imported. When a content_format of *-link-* is specified this must be a URL, otherwise this must be defined inline."
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user