Skip to content

Commit

Permalink
start terraform configuration with apim
Browse files Browse the repository at this point in the history
  • Loading branch information
Tschonti committed Mar 29, 2024
1 parent 174a293 commit 102c388
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ Thumbs.db
local.settings.json
az-login.bat
/.nx/cache
/infra/.terraform/
22 changes: 22 additions & 0 deletions infra/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

113 changes: 113 additions & 0 deletions infra/apim.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
variable "MTFSZ_CLIENT_ID" {
type = string
sensitive = true
}

variable "MTFSZ_CLIENT_SECRET" {
type = string
sensitive = true
}

resource "azurerm_api_management" "apim" {
name = "pontozo-apim-tf"
location = "West Europe"
resource_group_name = azurerm_resource_group.tf-rg.name
publisher_name = "Fekete Sámuel"
publisher_email = "[email protected]"

sku_name = "Consumption_0"
}

resource "azurerm_api_management_api" "mtfsz-api" {
name = "mtfsz"
resource_group_name = azurerm_resource_group.tf-rg.name
api_management_name = azurerm_api_management.apim.name
revision = "1"
display_name = "MTFSZ API"
protocols = ["https"]
service_url = "https://api.mtfsz.hu/api/v1_0"
subscription_required = true
subscription_key_parameter_names {
header = "Ocp-Apim-Subscription-Key"
query = "subscription-key"
}
}

resource "azurerm_api_management_api_operation" "get-events" {
operation_id = "get-events"
api_name = azurerm_api_management_api.mtfsz-api.name
api_management_name = azurerm_api_management_api.mtfsz-api.api_management_name
resource_group_name = azurerm_api_management_api.mtfsz-api.resource_group_name
display_name = "Get all events"
method = "GET"
url_template = "/esemenyek"

request {
query_parameter {
name = "esemeny_id"
type = "integer"
required = false
}
}


response {
status_code = 200
}

}

resource "azurerm_api_management_api_policy" "mtfsz-api-policy" {
api_name = azurerm_api_management_api.mtfsz-api.name
api_management_name = azurerm_api_management_api.mtfsz-api.api_management_name
resource_group_name = azurerm_api_management_api.mtfsz-api.resource_group_name


xml_content = <<XML
<policies>
<inbound>
<base />
<cors allow-credentials="false">
<allowed-origins>
<origin>http://localhost:3001/</origin>
<origin>https://pontozo.mtfsz.hu/</origin>
</allowed-origins>
<allowed-methods>
<method>GET</method>
</allowed-methods>
</cors>
<get-authorization-context provider-id="mtfsz" authorization-id="mtfsz" context-variable-name="auth-context" identity-type="managed" ignore-error="false" />
<set-header name="Authorization" exists-action="override">
<value>@("Bearer " + ((Authorization)context.Variables.GetValueOrDefault("auth-context"))?.AccessToken)</value>
</set-header>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
XML
}

resource "azurerm_api_management_authorization_server" "mtfsz-oauth" {
name = "mtfsz"
api_management_name = azurerm_api_management.apim.name
resource_group_name = azurerm_api_management.apim.resource_group_name
display_name = "MTFSZ OAuth 2.0"
authorization_endpoint = "https://api.mtfsz.hu/oauth/v2/auth"
client_registration_endpoint = "https://api.mtfsz.hu/oauth/v2/token"
client_id = var.MTFSZ_CLIENT_ID
client_secret = var.MTFSZ_CLIENT_SECRET

grant_types = [
"clientCredentials",
]
authorization_methods = [
"GET",
]
}
23 changes: 23 additions & 0 deletions infra/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">=3.96.0"
}
}
cloud {
organization = "feketesamu"
workspaces {
name = "pontozo"
}
}
}

provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "tf-rg" {
name = "pontozo-tf"
location = "Poland Central"
}

0 comments on commit 102c388

Please sign in to comment.