Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/pagopa/rtp-apis into SRTP-4…
Browse files Browse the repository at this point in the history
…1-send-rtp-openapi
  • Loading branch information
petretiandrea committed Oct 18, 2024
2 parents 1a0634f + bfc0671 commit 6459f75
Show file tree
Hide file tree
Showing 21 changed files with 336 additions and 3 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/validate-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: Run Spectral on Pull Requests
on:
pull_request:
paths:
- 'openapi/**/*.yaml'
- 'openapi/**/*.yml'
- '**/api/**/*.yaml'
- '**/api/**/*.yml'

permissions:
checks: write
Expand All @@ -19,5 +19,5 @@ jobs:
# Run Spectral
- uses: stoplightio/spectral-action@2ad0b9302e32a77c1caccf474a9b2191a8060d83 #v0.8.11
with:
file_glob: 'openapi/**/(*.yaml|*.yml)'
file_glob: '**/api/**/(*.yaml|*.yml)'
repo_token: ${{ secrets.GITHUB_TOKEN }}
42 changes: 42 additions & 0 deletions src/rtp/.terraform.lock.hcl

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

4 changes: 4 additions & 0 deletions src/rtp/00_data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
data "azurerm_api_management" "this" {
name = local.apim_name
resource_group_name = local.apim_rg
}
30 changes: 30 additions & 0 deletions src/rtp/01_apim_core.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# ------------------------------------------------------------------------------
# Product.
# ------------------------------------------------------------------------------
resource "azurerm_api_management_product" "rtp" {
api_management_name = data.azurerm_api_management.this.name
resource_group_name = data.azurerm_api_management.this.resource_group_name

product_id = "rtp"
display_name = "RTP Request To Pay"
description = "RTP Request To Pay"

subscription_required = false
published = true
}

resource "azurerm_api_management_product_policy" "rtp_api_product" {
product_id = azurerm_api_management_product.rtp.product_id
api_management_name = data.azurerm_api_management.this.name
resource_group_name = data.azurerm_api_management.this.resource_group_name

xml_content = file("./api_product/base_policy.xml")
}

resource "azurerm_api_management_group" "rtp_group" {
name = var.domain
resource_group_name = data.azurerm_api_management.this.resource_group_name
api_management_name = data.azurerm_api_management.this.name
display_name = upper(var.domain)
}

50 changes: 50 additions & 0 deletions src/rtp/02_api_mock.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
## RTP Mock API ##
resource "azurerm_api_management_api" "rtp_mock_api" {
name = "${var.env_short}-rtp-mock-api"
api_management_name = data.azurerm_api_management.this.name
resource_group_name = data.azurerm_api_management.this.resource_group_name

revision = "1"
description = "RTP MOCK API"
display_name = "RTP MOCK API"
path = "rtp/mock"
protocols = ["https"]
subscription_required = false

depends_on = [azurerm_api_management_product.rtp]
}

resource "azurerm_api_management_product_api" "rtp_mock_product_api" {
api_management_name = data.azurerm_api_management.this.name
resource_group_name = data.azurerm_api_management.this.resource_group_name
api_name = azurerm_api_management_api.rtp_mock_api.name
product_id = azurerm_api_management_product.rtp.product_id
depends_on = [azurerm_api_management_product.rtp, azurerm_api_management_api.rtp_mock_api]
}


## RTP Mock Operations ##
resource "azurerm_api_management_api_operation" "rtp_mock_create_ticket" {
operation_id = "rtp_mock_create_ticket"
api_name = azurerm_api_management_api.rtp_mock_api.name
api_management_name = data.azurerm_api_management.this.name
resource_group_name = data.azurerm_api_management.this.resource_group_name
display_name = "RTP Mock create ticket"
method = "POST"
url_template = "/api/v1/create"
description = "Endpoint for create a rtp ticket api"
}

resource "azurerm_api_management_api_operation_policy" "rtp_mock_create_ticket_policy" {
api_name = azurerm_api_management_api_operation.rtp_mock_create_ticket.api_name
api_management_name = azurerm_api_management_api_operation.rtp_mock_create_ticket.api_management_name
resource_group_name = azurerm_api_management_api_operation.rtp_mock_create_ticket.resource_group_name
operation_id = azurerm_api_management_api_operation.rtp_mock_create_ticket.operation_id

xml_content = templatefile("./api/test/mock_policy.xml", {
env = var.env
})

depends_on = [azurerm_api_management_api_operation.rtp_mock_create_ticket]

}
7 changes: 7 additions & 0 deletions src/rtp/99_locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
locals {
project = "${var.prefix}-${var.env_short}-${var.location_short}-${var.domain}"
product = "${var.prefix}-${var.env_short}"

apim_name = "${local.product}-apim"
apim_rg = "${local.product}-api-rg"
}
29 changes: 29 additions & 0 deletions src/rtp/99_main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
terraform {
required_version = ">=1.3.0"

required_providers {
azuread = {
source = "hashicorp/azuread"
version = "~> 2.52"
}
azurerm = {
source = "hashicorp/azurerm"
version = "~> 3.108"
}
}

backend "azurerm" {}
}

provider "azurerm" {
features {
key_vault {
purge_soft_delete_on_destroy = false
}
}
}

module "__v3__" {
# https://github.com/pagopa/terraform-azurerm-v3/releases/tag/v8.39.0
source = "git::https://github.com/pagopa/terraform-azurerm-v3.git?ref=e64f39b63d46e8c05470e30eca873f44a0ab7f1b"
}
50 changes: 50 additions & 0 deletions src/rtp/99_variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
variable "prefix" {
type = string
validation {
condition = (
length(var.prefix) <= 6
)
error_message = "Max length is 6 chars."
}
}

variable "env" {
type = string
description = "Environment"
}

variable "env_short" {
type = string
validation {
condition = (
length(var.env_short) <= 1
)
error_message = "Max length is 1 chars."
}
}

variable "location" {
type = string
}

variable "location_short" {
type = string
description = "Location short like eg: neu, weu.."
}

variable "tags" {
type = map(any)
default = {
CreatedBy = "Terraform"
}
}

variable "domain" {
type = string
validation {
condition = (
length(var.domain) <= 12
)
error_message = "Max length is 12 chars."
}
}
File renamed without changes.
31 changes: 31 additions & 0 deletions src/rtp/api/test/mock_policy.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!--
IMPORTANT:
- Policy elements can appear only within the <inbound>, <outbound>, <backend> section elements.
- To apply a policy to the incoming request (before it is forwarded to the backend service), place a corresponding policy element within the <inbound> section element.
- To apply a policy to the outgoing response (before it is sent back to the caller), place a corresponding policy element within the <outbound> section element.
- To add a policy, place the cursor at the desired insertion point and select a policy from the sidebar.
- To remove a policy, delete the corresponding policy statement from the policy document.
- Position the <base> element within a section element to inherit all policies from the corresponding section element in the enclosing scope.
- Remove the <base> element to prevent inheriting policies from the corresponding section element in the enclosing scope.
- Policies are applied in the order of their appearance, from the top down.
- Comments within policy elements are not supported and may disappear. Place your comments between policy elements or at a higher level scope.
-->
<policies>
<inbound>
<return-response>
<set-status code="200" reason="OK" />
<set-header name="Content-Type" exists-action="override">
<value>application/json</value>
</set-header>
</return-response>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
26 changes: 26 additions & 0 deletions src/rtp/api_product/base_policy.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!--
IMPORTANT:
- Policy elements can appear only within the <inbound>, <outbound>, <backend> section elements.
- To apply a policy to the incoming request (before it is forwarded to the backend service), place a corresponding policy element within the <inbound> section element.
- To apply a policy to the outgoing response (before it is sent back to the caller), place a corresponding policy element within the <outbound> section element.
- To add a policy, place the cursor at the desired insertion point and select a policy from the sidebar.
- To remove a policy, delete the corresponding policy statement from the policy document.
- Position the <base> element within a section element to inherit all policies from the corresponding section element in the enclosing scope.
- Remove the <base> element to prevent inheriting policies from the corresponding section element in the enclosing scope.
- Policies are applied in the order of their appearance, from the top down.
- Comments within policy elements are not supported and may disappear. Place your comments between policy elements or at a higher level scope.
-->
<policies>
<inbound>
<base />
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
1 change: 1 addition & 0 deletions src/rtp/env/dev/backend.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
subscription=DEV-CSTAR
4 changes: 4 additions & 0 deletions src/rtp/env/dev/backend.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource_group_name = "io-infra-rg"
storage_account_name = "cstarinfrastterraformdev"
container_name = "azurermstate"
key = "rtp-apim-product-rtp-dev.terraform.tfstate"
16 changes: 16 additions & 0 deletions src/rtp/env/dev/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# general
prefix = "cstar"
env_short = "d"
env = "dev"
domain = "rtp"
location = "westeurope"
location_short = "weu"

tags = {
CreatedBy = "Terraform"
Environment = "DEV"
Owner = "CSTAR"
Source = "https://github.com/pagopa/cstar-infrastructure"
CostCenter = "TS310 - PAGAMENTI & SERVIZI"
Application = "RTP"
}
1 change: 1 addition & 0 deletions src/rtp/env/prod/backend.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
subscription=PROD-CSTAR
4 changes: 4 additions & 0 deletions src/rtp/env/prod/backend.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource_group_name = "io-infra-rg"
storage_account_name = "cstarinfrastterraform"
container_name = "azurermstate"
key = "rtp-apim-product-rtp-prod.terraform.tfstate"
16 changes: 16 additions & 0 deletions src/rtp/env/prod/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# general
prefix = "cstar"
env_short = "p"
env = "prod"
domain = "rtp"
location = "westeurope"
location_short = "weu"

tags = {
CreatedBy = "Terraform"
Environment = "PROD"
Owner = "CSTAR"
Source = "https://github.com/pagopa/cstar-infrastructure"
CostCenter = "TS310 - PAGAMENTI & SERVIZI"
Application = "RTP"
}
1 change: 1 addition & 0 deletions src/rtp/env/uat/backend.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
subscription=UAT-CSTAR
4 changes: 4 additions & 0 deletions src/rtp/env/uat/backend.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource_group_name = "io-infra-rg"
storage_account_name = "cstarinfrastterraformuat"
container_name = "azurermstate"
key = "rtp-apim-product-rtp-uat.terraform.tfstate"
16 changes: 16 additions & 0 deletions src/rtp/env/uat/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# general
prefix = "cstar"
env_short = "u"
env = "uat"
domain = "rtp"
location = "westeurope"
location_short = "weu"

tags = {
CreatedBy = "Terraform"
Environment = "UAT"
Owner = "CSTAR"
Source = "https://github.com/pagopa/cstar-infrastructure"
CostCenter = "TS310 - PAGAMENTI & SERVIZI"
Application = "RTP"
}
1 change: 1 addition & 0 deletions src/rtp/terraform.sh

0 comments on commit 6459f75

Please sign in to comment.