Skip to content

Commit

Permalink
Merge pull request #920 from aztfmod/sm-apim-gateway
Browse files Browse the repository at this point in the history
Add support for APIM Gateway
  • Loading branch information
arnaudlh authored Feb 8, 2022
2 parents ca090de + c4c76a5 commit 5a0627e
Show file tree
Hide file tree
Showing 22 changed files with 453 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/workflows/standalone-scenarios-longrunners.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"apim/108-api_management_user",
"apim/110-api_management_diagnostic",
"apim/111-api_management_certificate",
"apim/112-api_management_gateway",
"apim/113-api_management_gateway_api",
"apim/114-api-management-group"
"app_gateway/301-agw-v1",
"compute/vmware_cluster/101-vmware_cluster",
"logic_app/101-integration_service_environment",
Expand Down
53 changes: 53 additions & 0 deletions api_management.tf
Original file line number Diff line number Diff line change
Expand Up @@ -404,4 +404,57 @@ module "api_management_user" {
}
output "api_management_user" {
value = module.api_management_user
}

module "api_management_gateway" {
source = "./modules/apim/api_management_gateway"
for_each = local.apim.api_management_gateway

global_settings = local.global_settings
client_config = local.client_config
settings = each.value

remote_objects = {
api_management = local.combined_objects_api_management
resource_group = local.combined_objects_resource_groups
}
}
output "api_management_gateway" {
value = module.api_management_gateway
}

module "api_management_gateway_api" {
source = "./modules/apim/api_management_gateway_api"
for_each = local.apim.api_management_gateway_api

global_settings = local.global_settings
client_config = local.client_config
settings = each.value

remote_objects = {
api_management_api = local.combined_objects_api_management_api
api_management = local.combined_objects_api_management
resource_group = local.combined_objects_resource_groups
api_management_gateway = local.combined_objects_api_management_gateway
}
}
output "api_management_gateway_api" {
value = module.api_management_gateway_api
}

module "api_management_group" {
source = "./modules/apim/api_management_group"
for_each = local.apim.api_management_group

global_settings = local.global_settings
client_config = local.client_config
settings = each.value

remote_objects = {
api_management = local.combined_objects_api_management
resource_group = local.combined_objects_resource_groups
}
}
output "api_management_group" {
value = module.api_management_group
}
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ rover login --tenant <tenant_name>.onmicrosoft.com -s <subscription_id>
```bash
rover -lz /tf/caf/landingzones/caf_launchpad \
-launchpad \
-var-folder /tf/caf/landingzones/caf_launchpad/scenario/100 \
-var-folder /tf/caf/landingzones/caf_launchpad/scenario/100 \
-a apply
```

Expand Down
52 changes: 52 additions & 0 deletions examples/apim/112-api_management_gateway/configuration.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
global_settings = {
default_region = "region1"
regions = {
region1 = "southeastasia"
}
}

resource_groups = {
rg1 = {
name = "example-agw"
region = "region1"
}
}


api_management = {
apim1 = {
name = "example-apim"
region = "region1"
resource_group = {
key = "rg1"
}
publisher_name = "My Company"
publisher_email = "[email protected]"

sku_name = "Developer_1"
}
}

api_management_gateway = {
apimgw1= {
name = "example-gateway"
api_management = {
key = "apim1"
#lz_key = ""
#name = ""
}
description = "Example API Management gateway"
resource_group = {
key = "rg1"
#lz_key = ""
#name = ""
}

location_data = {
name = "example name"
city = "example city"
district = "example district"
region = "example region"
}
}
}
88 changes: 88 additions & 0 deletions examples/apim/113-api_management_gateway_api/configuration.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
global_settings = {
default_region = "region1"
regions = {
region1 = "southeastasia"
}
}

resource_groups = {
rg1 = {
name = "example-agw"
region = "region1"
}
}


api_management = {
apim1 = {
name = "example-apim"
region = "region1"
resource_group = {
key = "rg1"
}
publisher_name = "My Company"
publisher_email = "[email protected]"

sku_name = "Developer_1"
}
}

api_management_api = {
apima1 = {
name = "example-api"
resource_group = {
key = "rg1"
}
api_management = {
key = "apim1"
}
revision = "1"
display_name = "Example API"
path = "example"
protocols = ["https"]

import = {
content_format = "swagger-link-json"
content_value = "http://conferenceapi.azurewebsites.net/?format=json"
}
}
}

api_management_gateway = {
apimgw1= {
name = "example-gateway"
api_management = {
key = "apim1"
#lz_key = ""
#name = ""
}
description = "Example API Management gateway"
resource_group = {
key = "rg1"
#lz_key = ""
#name = ""
}

location_data = {
name = "example name"
city = "example city"
district = "example district"
region = "example region"
}
}
}

api_management_gateway_api = {
apimgwapi1 = {
api_management_gateway = {
key = "apimgw1"
#lz_key = ""
#id = ""
}
api_management_api = {
key = "apima1"
#lz_key = ""
#id = ""
}
}
}
43 changes: 43 additions & 0 deletions examples/apim/114-api-management-group/configuration.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
global_settings = {
default_region = "region1"
regions = {
region1 = "southeastasia"
}
}

resource_groups = {
rg1 = {
name = "example-agw"
region = "region1"
}
}


api_management = {
apim1 = {
name = "example-apim"
region = "region1"
resource_group = {
key = "rg1"
}
publisher_name = "My Company"
publisher_email = "[email protected]"

sku_name = "Developer_1"
}
}

api_management_group = {
apimg1 = {

name = "example-apimg"
resource_group = {
key = "rg1"
}
api_management = {
key = "apim1"
}
display_name = "Example Group"
description = "This is an example API management group."
}
}
3 changes: 3 additions & 0 deletions examples/module.tf
Original file line number Diff line number Diff line change
Expand Up @@ -304,5 +304,8 @@ module "example" {
api_management_custom_domain = var.api_management_custom_domain
api_management_diagnostic = var.api_management_diagnostic
api_management_certificate = var.api_management_certificate
api_management_gateway = var.api_management_gateway
api_management_gateway_api = var.api_management_gateway_api
api_management_group = var.api_management_group
}
}
9 changes: 9 additions & 0 deletions examples/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,15 @@ variable "api_management_diagnostic" {
variable "api_management_certificate" {
default = {}
}
variable "api_management_gateway" {
default = {}
}
variable "api_management_gateway_api" {
default = {}
}
variable "api_management_group" {
default = {}
}
variable "lb" {
default = {}
}
Expand Down
1 change: 1 addition & 0 deletions locals.combined_objects.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ locals {
combined_objects_api_management = merge(tomap({ (local.client_config.landingzone_key) = module.api_management }), try(var.remote_objects.api_management, {}))
combined_objects_api_management_api = merge(tomap({ (local.client_config.landingzone_key) = module.api_management_api }), try(var.remote_objects.api_management_api, {}))
combined_objects_api_management_api_operation = merge(tomap({ (local.client_config.landingzone_key) = module.api_management_api_operation }), try(var.remote_objects.api_management_api_operation, {}))
combined_objects_api_management_gateway = merge(tomap({ (local.client_config.landingzone_key) = module.api_management_gateway }), try(var.remote_objects.api_management_gateway, {}))
combined_objects_api_management_logger = merge(tomap({ (local.client_config.landingzone_key) = module.api_management_logger }), try(var.remote_objects.api_management_logger, {}))
combined_objects_app_config = merge(tomap({ (local.client_config.landingzone_key) = module.app_config }), try(var.remote_objects.app_config, {}))
combined_objects_app_service_environments = merge(tomap({ (local.client_config.landingzone_key) = module.app_service_environments }), try(var.remote_objects.app_service_environments, {}))
Expand Down
3 changes: 3 additions & 0 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -347,5 +347,8 @@ locals {
api_management_custom_domain = try(var.apim.api_management_custom_domain, {})
api_management_diagnostic = try(var.apim.api_management_diagnostic, {})
api_management_certificate = try(var.apim.api_management_certificate, {})
api_management_gateway = try(var.apim.api_management_gateway, {})
api_management_gateway_api = try(var.apim.api_management_gateway_api, {})
api_management_group = try(var.apim.api_management_group, {})
}
}
8 changes: 8 additions & 0 deletions modules/apim/api_management_gateway/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
azurecaf = {
source = "aztfmod/azurecaf"
}
}
required_version = ">= 0.13"
}
41 changes: 41 additions & 0 deletions modules/apim/api_management_gateway/module.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
resource "azurecaf_name" "apim" {
name = var.settings.name
resource_type = "azurerm_data_factory" #"azurerm_api_management_api"
prefixes = var.global_settings.prefixes
random_length = var.global_settings.random_length
clean_input = true
passthrough = var.global_settings.passthrough
use_slug = var.global_settings.use_slug
}

resource "azurerm_api_management_gateway" "apim" {
name = azurecaf_name.apim.result

api_management_id = coalesce(
try(var.remote_objects.api_management[var.settings.api_management.lz_key][var.settings.api_management.key].id, null),
try(var.remote_objects.api_management[var.client_config.landingzone_key][var.settings.api_management.key].id, null),
try(var.settings.api_management.id, null)
)

# resource_group_name exists in the documentation but not in the provider Source code
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/api_management_gateway
#
#
# resource_group_name = coalesce(
# try(var.remote_objects.resource_group[var.settings.resource_group.lz_key][var.settings.resource_group.key].name, null),
# try(var.remote_objects.resource_group[var.client_config.landingzone_key][var.settings.resource_group.key].name, null),
# try(var.settings.resource_group.name, null)
# )

description = try(var.settings.description, null)

dynamic "location_data" {
for_each = try(var.settings.location_data, null) != null ? [var.settings.location_data] : []
content {
name = try(location_data.value.name, null)
region = try(location_data.value.region, null)
city = try(location_data.value.city, null)
district = try(location_data.value.district, null)
}
}
}
4 changes: 4 additions & 0 deletions modules/apim/api_management_gateway/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "id" {
value = azurerm_api_management_gateway.apim.id
description = "The ID of the API Management Gateway."
}
18 changes: 18 additions & 0 deletions modules/apim/api_management_gateway/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
variable "global_settings" {
description = "Global settings object (see module README.md)"
}
variable "client_config" {
description = "Client configuration object (see module README.md)."
}
variable "settings" {
description = "(Required) Used to handle passthrough paramenters."
}
variable "remote_objects" {
description = "(Required) Specifies the supported Azure location where to create the resource. Changing this forces a new resource to be created."
default = {}
}
variable "base_tags" {
description = "Base tags for the resource to be inherited from the resource group."
type = map(any)
default = {}
}
8 changes: 8 additions & 0 deletions modules/apim/api_management_gateway_api/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
azurecaf = {
source = "aztfmod/azurecaf"
}
}
required_version = ">= 0.13"
}
Loading

0 comments on commit 5a0627e

Please sign in to comment.