Skip to content

Commit 58c9428

Browse files
[SELC-6294] feat: Added action for newman (#631)
1 parent b25a127 commit 58c9428

19 files changed

+1963
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
on:
2+
workflow_call:
3+
inputs:
4+
environment:
5+
type: string
6+
required: true
7+
8+
jobs:
9+
integration-test:
10+
environment: ${{ inputs.environment }}-ci
11+
name: "Run Postman collection on ${{ inputs.environment }}"
12+
runs-on: ubuntu-20.04
13+
steps:
14+
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
15+
name: Checkout
16+
- name: "Download postman environment"
17+
env:
18+
INTEGRATION_ENVIRONMENT: ${{ secrets.INTEGRATION_ENVIRONMENT }}
19+
run: 'echo "$INTEGRATION_ENVIRONMENT" | base64 --decode > Selfcare-external-Integration.postman_environment.json'
20+
shell: bash
21+
- uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af
22+
with:
23+
node-version: "16.x"
24+
- name: Install newman
25+
shell: bash
26+
run: npm install -g newman
27+
- name: Run newman
28+
shell: bash
29+
run: newman run ./integration-test/newman/Selfcare-external-Integration.postman_collection.json -e ./infra/integration-test/Selfcare-external-Integration.postman_environment.json --reporters cli,json --reporter-json-export ./integration-test/integration-test-result.json
30+
- name: Send newman report
31+
shell: bash
32+
run: node ./integration-test/convert.js
33+
- name: "Send message on Slack"
34+
shell: bash
35+
run: >
36+
curl -X POST ${{ secrets.SLACK_WEBHOOK_URL }} -H 'Content-type: application/json' -d @integration-test/stats.json
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Integration test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- releases/*
8+
9+
workflow_dispatch:
10+
inputs:
11+
env:
12+
type: choice
13+
description: Environment
14+
default: dev
15+
options:
16+
- dev
17+
- uat
18+
19+
jobs:
20+
test_dev:
21+
uses: ./.github/workflows/call_integration_test.yml
22+
name: "[DEV] Integration test"
23+
if: ${{ (startsWith(github.ref_name, 'releases/') != true && inputs.env == null) || inputs.env == 'dev' }}
24+
secrets: inherit
25+
with:
26+
environment: dev
27+
28+
test_uat:
29+
uses: ./.github/workflows/call_integration_test.yml
30+
name: "[UAT] Integration test"
31+
if: ${{ (startsWith(github.ref_name, 'releases/') != true && inputs.env == null) || inputs.env == 'uat' }}
32+
secrets: inherit
33+
with:
34+
environment: uat

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,7 @@ app/.DS_Store
5454
override.tf
5555
override.tf.json
5656
*_override.tf
57-
*_override.tf.json
57+
*_override.tf.json
58+
59+
### NODE
60+
**/node_modules/*

infra/container_apps/locals.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ locals {
44

55
container_app_environment_name = "${local.project}${local.pnpg_suffix}-${var.cae_name}"
66
ca_resource_group_name = "${local.project}-container-app${var.suffix_increment}-rg"
7-
}
7+
}

infra/integration-test/.terraform.lock.hcl

+67
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"id": "12505d2b-8642-4ff6-8a13-d7eba9922973",
3+
"name": "Selfcare-Integration",
4+
"values": [
5+
{
6+
"key": "apiBaseUrl",
7+
"value": "https://api${env}.selfcare.pagopa.it",
8+
"type": "default",
9+
"enabled": true
10+
},
11+
{
12+
"key": "productId",
13+
"value": "prod-pn",
14+
"type": "default",
15+
"enabled": true
16+
},
17+
{
18+
"key": "apimKeyPN",
19+
"value": "${apimKeyPN}",
20+
"type": "default",
21+
"enabled": true
22+
},
23+
{
24+
"key": "institutionId",
25+
"value": "a634f83b-e8e4-49c9-86cc-307f6aa31bbb",
26+
"type": "default",
27+
"enabled": true
28+
},
29+
{
30+
"key": "userId",
31+
"value": "6a33a28c-8415-4741-86ad-229ac274932e",
32+
"type": "default",
33+
"enabled": true
34+
}
35+
],
36+
"_postman_variable_scope": "environment",
37+
"_postman_exported_at": "2024-11-11T16:36:58.194Z",
38+
"_postman_exported_using": "Postman/11.19.0"
39+
}

infra/integration-test/data.tf

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
data "azurerm_resource_group" "rg_vnet" {
2+
name = format("%s-vnet-rg", local.project)
3+
}
4+
5+
data "azurerm_resource_group" "rg_monitor" {
6+
name = local.monitor_rg_name
7+
}
8+
9+
data "azurerm_application_insights" "application_insights" {
10+
name = local.monitor_appinsights_name
11+
resource_group_name = data.azurerm_resource_group.rg_monitor.name
12+
}
13+
14+
data "azurerm_virtual_network" "vnet" {
15+
name = format("%s-vnet", local.project)
16+
resource_group_name = data.azurerm_resource_group.rg_vnet.name
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
subscription=DEV-SelfCare
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
resource_group_name = "terraform-state-rg"
2+
storage_account_name = "tfappdevselfcare"
3+
container_name = "terraform-state"
4+
key = "selfcare-external-api-backend.integration-test.tfstate"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
env_short = "d"
2+
suffix_increment = "-002"
3+
cae_name = "cae-002"
4+
prefix = "selc"
5+
env = "dev"
6+
location = "westeurope"
7+
8+
tags = {
9+
CreatedBy = "Terraform"
10+
Environment = "Dev"
11+
Owner = "SelfCare"
12+
Source = "https://github.com/pagopa/selfcare-external-api-backend"
13+
CostCenter = "TS310 - PAGAMENTI & SERVIZI"
14+
}
15+
16+
key_vault = {
17+
resource_group_name = "selc-d-sec-rg"
18+
name = "selc-d-kv"
19+
}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
data "azurerm_key_vault" "key_vault" {
2+
resource_group_name = var.key_vault.resource_group_name
3+
name = var.key_vault.name
4+
}
5+
6+
data "azurerm_key_vault_secret" "apim_product_pn_sk" {
7+
name = "apim-product-pn-sk"
8+
key_vault_id = data.azurerm_key_vault.key_vault.id
9+
}
10+
11+
data "github_repository" "repo" {
12+
full_name = "pagopa/selfcare-external-api-backend"
13+
}
14+
15+
resource "github_repository_environment" "repo_environment" {
16+
repository = data.github_repository.repo.name
17+
environment = "dev-ci"
18+
}
19+
20+
resource "github_actions_environment_secret" "integration_environment" {
21+
repository = data.github_repository.repo.name
22+
environment = github_repository_environment.repo_environment.environment
23+
secret_name = "integration_environment"
24+
plaintext_value = base64encode(templatefile("Selfcare-external-Integration.postman_environment.json",
25+
{
26+
env = local.env_url
27+
apimKeyPN = data.azurerm_key_vault_secret.apim_product_pn_sk.value
28+
}))
29+
}

infra/integration-test/locals.tf

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
locals {
2+
pnpg_suffix = var.is_pnpg == true ? "-pnpg" : ""
3+
project = "selc-${var.env_short}"
4+
env_url = var.env_short == "p" ? "" : ".${var.env}"
5+
6+
container_app_environment_name = "${local.project}${local.pnpg_suffix}-${var.cae_name}"
7+
ca_resource_group_name = "${local.project}-container-app${var.suffix_increment}-rg"
8+
monitor_rg_name = "${local.project}-monitor-rg"
9+
monitor_appinsights_name = "${local.project}-appinsights"
10+
}

infra/integration-test/main.tf

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
terraform {
2+
required_version = ">=1.6.0"
3+
4+
required_providers {
5+
azuread = {
6+
source = "hashicorp/azuread"
7+
version = "2.30.0"
8+
}
9+
azurerm = {
10+
source = "hashicorp/azurerm"
11+
version = "<= 3.86.0"
12+
}
13+
github = {
14+
source = "integrations/github"
15+
version = "5.18.3"
16+
}
17+
}
18+
19+
backend "azurerm" {}
20+
}
21+
22+
provider "azurerm" {
23+
features {}
24+
skip_provider_registration = true
25+
}
26+
27+
provider "github" {
28+
owner = "pagopa"
29+
}
30+
31+
data "azurerm_subscription" "current" {}
32+
33+
data "azurerm_client_config" "current" {}

infra/integration-test/terraform.sh

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
action=$1
6+
env=$2
7+
shift 2
8+
other=$@
9+
# must be subscription in lower case
10+
subscription=""
11+
BACKEND_CONFIG_PATH="./env/${ENV}/backend.tfvars"
12+
13+
if [ -z "$action" ]; then
14+
echo "Missed action: init, apply, plan"
15+
exit 0
16+
fi
17+
18+
if [ -z "$env" ]; then
19+
echo "env should be: dev, uat or prod."
20+
exit 0
21+
fi
22+
23+
source "./env/$env/backend.ini"
24+
25+
az account set -s "${subscription}"
26+
27+
# if using cygwin, we have to transcode the WORKDIR
28+
if [[ $WORKDIR == /cygdrive/* ]]; then
29+
WORKDIR=$(cygpath -w $WORKDIR)
30+
fi
31+
32+
if [ "$action" = "force-unlock" ]; then
33+
echo "🧭 terraform INIT in env: ${env}"
34+
terraform init -reconfigure -backend-config="./env/$env/backend.tfvars" $other
35+
warn_message="You are about to unlock Terraform's remote state.
36+
This is a dangerous task you want to be aware of before going on.
37+
This operation won't affect your infrastructure directly.
38+
However, please note that you may lose pieces of information about partially-applied configurations.
39+
Please refer to the official Terraform documentation about the command:
40+
https://developer.hashicorp.com/terraform/cli/commands/force-unlock"
41+
printf "\n\e[33m%s\e[0m\n\n" "$warn_message"
42+
43+
read -r -p "Please enter the LOCK ID: " lock_id
44+
terraform force-unlock "$lock_id"
45+
46+
exit 0 # this line prevents the script to go on
47+
fi
48+
49+
if echo "init plan apply refresh import output state taint destroy" | grep -w "$action" > /dev/null; then
50+
if [ "$action" = "init" ]; then
51+
echo "🧭 terraform INIT in env: ${env}"
52+
terraform "$action" -reconfigure -backend-config="./env/$env/backend.tfvars" $other
53+
elif [ "$action" = "output" ] || [ "$action" = "state" ] || [ "$action" = "taint" ]; then
54+
# init terraform backend
55+
echo "🧭 terraform (output|state|taint) launched with action: ${action} in env: ${env}"
56+
terraform init -reconfigure -backend-config="./env/$env/backend.tfvars"
57+
terraform "$action" $other
58+
else
59+
# init terraform backend
60+
echo "🧭 terraform launched with action: ${action} in env: ${env}"
61+
62+
terraform init -reconfigure -backend-config="./env/$env/backend.tfvars"
63+
terraform "$action" -var-file="./env/$env/terraform.tfvars" $other
64+
fi
65+
else
66+
echo "Action not allowed."
67+
exit 1
68+
fi

0 commit comments

Comments
 (0)