diff --git a/.github/workflows/apim-ci.yml b/.github/workflows/apim-ci.yml new file mode 100644 index 0000000..ffb2189 --- /dev/null +++ b/.github/workflows/apim-ci.yml @@ -0,0 +1,64 @@ +name: Validate_APIM_On_PR_to_Dev + +on: + pull_request: + branches: + - develop + paths: + - "service/**" + - ".github/workflows/apim-ci.yml" + - ".github/workflows/apim-develop.yml" + +jobs: + validate-apim: + runs-on: ubuntu-latest + + env: + Environment: dev + UrlEnvPrefix: dev- + SubscriptionId: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + resourceGroup: rg-apim-dev + AZURE_CREDENTIALS: ${{ secrets.DEV_AZURE_CREDENTIALS }} + ApimServiceName: apim-iati-dev + ApimGatewayHostname: dev-api.iatistandard.org + ApimDevPortalHostname: dev-developer.iatistandard.org + ApimSKU: Developer + ApimCapacity: 1 + repoUrl: https://raw.githubusercontent.com/iati/apim-iati-gateway + repoApimPath: service + RedisConnectionString: ${{ secrets.DEV_REDIS_CONNECTION_STRING }} + + steps: + - name: "Checkout GitHub Action" + uses: actions/checkout@v2 + + - name: "Login to Azure" + uses: azure/login@v1.3.0 + with: + creds: ${{ env.AZURE_CREDENTIALS }} + + # ARM deployment tasks + - name: Validate APIM ARM Templates with what-if + working-directory: ./service + env: + LinkedTemplatesBaseUrl: ${{ env.repoUrl }}/${{ github.HEAD_REF }}/${{ env.repoApimPath }} + PolicyXMLBaseUrl: ${{ env.repoUrl }}/${{ github.HEAD_REF }}/${{ env.repoApimPath }}/policies + deploymentName: --name GH_what_if_deployment_apim + rg: --resource-group ${{ env.resourceGroup }} + apiNamePrefix: apim-iati-dev + run: | + az deployment group what-if ${{env.deploymentName}} \ + ${{env.rg}} \ + --template-file ./${{env.apiNamePrefix}}-master.template.json \ + --parameters ./${{env.apiNamePrefix}}-parameters.json \ + --parameters ApimServiceName=${{ env.ApimServiceName }} \ + --parameters LinkedTemplatesBaseUrl=${{ env.LinkedTemplatesBaseUrl }} \ + --parameters PolicyXMLBaseUrl=${{ env.PolicyXMLBaseUrl }} \ + --parameters Environment=${{ env.Environment }} \ + --parameters UrlEnvPrefix=${{ env.UrlEnvPrefix }} \ + --parameters SubscriptionId=${{ env.SubscriptionId }} \ + --parameters ApimSKU=${{ env.ApimSKU }} \ + --parameters ApimCapacity=${{ env.ApimCapacity }} \ + --parameters ApimGatewayHostname=${{ env.ApimGatewayHostname }} \ + --parameters ApimDevPortalHostname=${{ env.ApimDevPortalHostname }} \ + --parameters RedisConnectionString=${{ env.RedisConnectionString }} diff --git a/.github/workflows/apim-develop.yml b/.github/workflows/apim-develop.yml index d164cb9..6dbe5fd 100644 --- a/.github/workflows/apim-develop.yml +++ b/.github/workflows/apim-develop.yml @@ -9,7 +9,7 @@ on: - ".github/workflows/apim-develop.yml" jobs: - validate-deploy-apim: + deploy-apim-dev: runs-on: ubuntu-latest env: @@ -26,6 +26,7 @@ jobs: repoUrl: https://raw.githubusercontent.com/iati/apim-iati-gateway repoBranch: ${GITHUB_REF##*/} repoApimPath: service + RedisConnectionString: ${{ secrets.DEV_REDIS_CONNECTION_STRING }} steps: - name: "Checkout GitHub Action" @@ -59,4 +60,5 @@ jobs: --parameters ApimSKU=${{ env.ApimSKU }} \ --parameters ApimCapacity=${{ env.ApimCapacity }} \ --parameters ApimGatewayHostname=${{ env.ApimGatewayHostname }} \ - --parameters ApimDevPortalHostname=${{ env.ApimDevPortalHostname }} + --parameters ApimDevPortalHostname=${{ env.ApimDevPortalHostname }} \ + --parameters RedisConnectionString=${{ env.RedisConnectionString }} diff --git a/.github/workflows/apim-prod.yml b/.github/workflows/apim-prod.yml index 9b58909..593dae5 100644 --- a/.github/workflows/apim-prod.yml +++ b/.github/workflows/apim-prod.yml @@ -6,7 +6,7 @@ on: types: [published] jobs: - validate-deploy-apim: + deploy-apim-prod: runs-on: ubuntu-latest env: @@ -23,6 +23,7 @@ jobs: repoUrl: https://raw.githubusercontent.com/iati/apim-iati-gateway repoBranch: ${GITHUB_REF##*/} repoApimPath: service + RedisConnectionString: ${{ secrets.PROD_REDIS_CONNECTION_STRING }} steps: - name: "Checkout GitHub Action" @@ -56,4 +57,5 @@ jobs: --parameters ApimSKU=${{ env.ApimSKU }} \ --parameters ApimCapacity=${{ env.ApimCapacity }} \ --parameters ApimGatewayHostname=${{ env.ApimGatewayHostname }} \ - --parameters ApimDevPortalHostname=${{ env.ApimDevPortalHostname }} + --parameters ApimDevPortalHostname=${{ env.ApimDevPortalHostname }} \ + --parameters RedisConnectionString=${{ env.RedisConnectionString }} diff --git a/service/apim-iati-dev-caches.template.json b/service/apim-iati-dev-caches.template.json new file mode 100644 index 0000000..5d772c7 --- /dev/null +++ b/service/apim-iati-dev-caches.template.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "ApimServiceName": { + "type": "string" + }, + "Environment": { + "type": "string" + }, + "RedisConnectionString": { + "type": "string" + }, + "SubscriptionId": { + "type": "string" + } + }, + "resources": [ + { + "type": "Microsoft.ApiManagement/service/caches", + "apiVersion": "2020-12-01", + "name": "[concat(parameters('ApimServiceName'), '/uksouth')]", + "properties": { + "useFromLocation": "uksouth", + "description": "[concat('redis-iati-',parameters('Environment'),'.redis.cache.windows.net')]", + "connectionString": "[parameters('RedisConnectionString')]", + "resourceId": "[concat('https://management.azure.com/subscriptions/',parameters('SubscriptionId'),'/resourceGroups/rg-sharedresources-',parameters('Environment'), '/providers/Microsoft.Cache/Redis/redis-iati-', parameters('Environment'))]" + } + } + ] +} diff --git a/service/apim-iati-dev-master.template.json b/service/apim-iati-dev-master.template.json index 4aaec2a..899c256 100644 --- a/service/apim-iati-dev-master.template.json +++ b/service/apim-iati-dev-master.template.json @@ -85,6 +85,12 @@ "metadata": { "description": "Capacity of the APIM Instance" } + }, + "RedisConnectionString": { + "type": "string", + "metadata": { + "description": "Connection string for external redis cache" + } } }, "resources": [ @@ -121,6 +127,35 @@ "apiVersion": "2018-05-01", "dependsOn": [] }, + { + "properties": { + "mode": "Incremental", + "templateLink": { + "uri": "[concat(parameters('LinkedTemplatesBaseUrl'), '/apim-iati-dev-caches.template.json')]", + "contentVersion": "1.0.0.0" + }, + "parameters": { + "ApimServiceName": { + "value": "[parameters('ApimServiceName')]" + }, + "Environment": { + "value": "[parameters('Environment')]" + }, + "SubscriptionId": { + "value": "[parameters('SubscriptionId')]" + }, + "RedisConnectionString": { + "value": "[parameters('RedisConnectionString')]" + } + } + }, + "name": "cachesTemplate", + "type": "Microsoft.Resources/deployments", + "apiVersion": "2018-05-01", + "dependsOn": [ + "[resourceId('Microsoft.Resources/deployments', 'apimTemplate')]" + ] + }, { "properties": { "mode": "Incremental", diff --git a/service/apim-iati-dev-parameters.json b/service/apim-iati-dev-parameters.json index 4f1cea0..4ccbca6 100644 --- a/service/apim-iati-dev-parameters.json +++ b/service/apim-iati-dev-parameters.json @@ -18,10 +18,10 @@ "value": "dev-" }, "LinkedTemplatesBaseUrl": { - "value": "https://raw.githubusercontent.com/IATI/apim-iati-gateway/main/service/" + "value": "https://raw.githubusercontent.com/IATI/apim-iati-gateway/develop/service/" }, "PolicyXMLBaseUrl": { - "value": "https://raw.githubusercontent.com/IATI/apim-iati-gateway/main/service/policies/" + "value": "https://raw.githubusercontent.com/IATI/apim-iati-gateway/develop/service/policies/" }, "SubscriptionId": { "value": "bcaf7a00-7a14-4932-ac41-7bb0dee0d2a9" @@ -51,7 +51,9 @@ }, "ApimCapacity": { "value": 1 + }, + "RedisConnectionString": { + "value": "placeholderstring" } - }, - "resources": [] + } }