Skip to content

Commit

Permalink
Port 8078 update git hub actions for azure (#1208)
Browse files Browse the repository at this point in the history
* Update create-azure-resource.md

* Update tag azure resource action

* Update context to port_context

* Update azure workflows
  • Loading branch information
phalbert committed May 26, 2024
1 parent 0998889 commit d734a6e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ For secure Azure interactions, we'll use a Service Principal. If you need help c
- `ARM_CLIENT_SECRET`: Service Principal Password
- `ARM_SUBSCRIPTION_ID`: Your Azure Subscription ID
- `ARM_TENANT_ID`: Your Azure [Tenant ID](https://learn.microsoft.com/en-us/azure/azure-portal/get-subscription-tenant-id)
- `AZURE_RESOURCE_GROUP`; Your Azure resource group

## Port Configuration

Expand Down Expand Up @@ -156,39 +157,13 @@ Import Azure resources into your Port account using the [Azure Exporter](/build-
"repo": "<GITHUB-REPO-NAME>",
"workflow": "terraform-azure.yml",
"workflowInputs": {
"{{if (.inputs | has(\"ref\")) then \"ref\" else null end}}": "{{.inputs.\"ref\"}}",
"{{if (.inputs | has(\"storage_name\")) then \"storage_name\" else null end}}": "{{.inputs.\"storage_name\"}}",
"{{if (.inputs | has(\"storage_location\")) then \"storage_location\" else null end}}": "{{.inputs.\"storage_location\"}}",
"port_payload": {
"action": "{{ .action.identifier[(\"service_\" | length):] }}",
"resourceType": "run",
"status": "TRIGGERED",
"trigger": "{{ .trigger | {by, origin, at} }}",
"context": {
"entity": "{{.entity.identifier}}",
"blueprint": "{{.action.blueprint}}",
"runId": "{{.run.id}}"
},
"payload": {
"entity": "{{ (if .entity == {} then null else .entity end) }}",
"action": {
"invocationMethod": {
"type": "GITHUB",
"org": "<GITHUB-ORG>",
"repo": "<GITHUB-REPO-NAME>",
"workflow": "terraform-azure.yml",
"omitUserInputs": false,
"omitPayload": false,
"reportWorkflowStatus": true
},
"trigger": "{{.trigger.operation}}"
},
"properties": {
"{{if (.inputs | has(\"storage_name\")) then \"storage_name\" else null end}}": "{{.inputs.\"storage_name\"}}",
"{{if (.inputs | has(\"storage_location\")) then \"storage_location\" else null end}}": "{{.inputs.\"storage_location\"}}"
},
"censoredProperties": "{{.action.encryptedProperties}}"
}
"storage_name": "{{ .inputs.\"storage_name\" }}",
"storage_location": "{{ .inputs.\"storage_location\" }}",
"port_context": {
"entity": "{{ .entity }}",
"blueprint": "{{ .action.blueprint }}",
"runId": "{{ .run.id }}",
"trigger": "{{ .trigger }}"
}
},
"reportWorkflowStatus": true
Expand Down Expand Up @@ -333,7 +308,7 @@ output "endpoint_url" {
<summary>GitHub workflow script</summary>

```yaml showLineNumbers title="terraform-azure.yml"
name: "Terraform Infrastructure Change"
name: "Deploy Azure Resource"

on:
workflow_dispatch:
Expand All @@ -344,26 +319,25 @@ on:
storage_location:
required: true
type: string
port_payload:
port_context:
required: true
description:
Port's payload, including details for who triggered the action and
general context (blueprint, run id, etc...)
type: string
description: >-
Action and general context (blueprint, run id, etc...)
env:
TF_LOG: INFO
TF_INPUT: false
# BUCKET_TF_STATE: # Uncomment this if you using a storage backend

jobs:
terraform:
name: "Deploy Azure Resource"
name: "Terraform Infrastructure Change Management"
runs-on: ubuntu-latest
defaults:
run:
shell: bash
# We keep Terraform files in the terraform directory.
working-directory: ./terraform
# working-directory: ./


steps:
Expand Down Expand Up @@ -397,7 +371,8 @@ jobs:
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
TF_VAR_port_client_id: ${{ secrets.PORT_CLIENT_ID }}
TF_VAR_port_client_secret: ${{ secrets.PORT_CLIENT_SECRET }}
TF_VAR_port_run_id: ${{fromJson(inputs.port_payload).context.runId}}
TF_VAR_port_run_id: ${{ fromJson(inputs.port_context).runId }}
TF_VAR_resource_group_name: ${{ secrets.AZURE_RESOURCE_GROUP }}
run: |
terraform plan \
-input=false \
Expand All @@ -421,7 +396,8 @@ jobs:
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
TF_VAR_port_client_id: ${{ secrets.PORT_CLIENT_ID }}
TF_VAR_port_client_secret: ${{ secrets.PORT_CLIENT_SECRET }}
TF_VAR_port_run_id: ${{fromJson(inputs.port_payload).context.runId}}
TF_VAR_port_run_id: ${{fromJson(inputs.port_context).runId}}
TF_VAR_resource_group_name: arete-resources
run: |
terraform plan \
-input=false \
Expand All @@ -442,7 +418,8 @@ jobs:
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
baseUrl: https://api.getport.io
operation: PATCH_RUN
runId: ${{fromJson(inputs.port_payload).context.runId}}
status: "SUCCESS"
runId: ${{fromJson(inputs.port_context).runId}}
logMessage: Created ${{ inputs.storage_name }}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,37 +152,12 @@ Import Azure resources into your Port account using the [Azure Exporter](/build-
"repo": "<GITHUB-REPO-NAME>",
"workflow": "tag-azure-resource.yml",
"workflowInputs": {
"{{if (.inputs | has(\"ref\")) then \"ref\" else null end}}": "{{.inputs.\"ref\"}}",
"{{if (.inputs | has(\"tags\")) then \"tags\" else null end}}": "{{.inputs.\"tags\"}}",
"port_payload": {
"action": "{{ .action.identifier[(\"service_\" | length):] }}",
"resourceType": "run",
"status": "TRIGGERED",
"trigger": "{{ .trigger | {by, origin, at} }}",
"context": {
"entity": "{{.entity.identifier}}",
"blueprint": "{{.action.blueprint}}",
"runId": "{{.run.id}}"
},
"payload": {
"entity": "{{ (if .entity == {} then null else .entity end) }}",
"action": {
"invocationMethod": {
"type": "GITHUB",
"org": "<GITHUB-ORG>",
"repo": "<GITHUB-REPO-NAME>",
"workflow": "tag-azure-resource.yml",
"omitUserInputs": false,
"omitPayload": false,
"reportWorkflowStatus": true
},
"trigger": "{{.trigger.operation}}"
},
"properties": {
"{{if (.inputs | has(\"tags\")) then \"tags\" else null end}}": "{{.inputs.\"tags\"}}"
},
"censoredProperties": "{{.action.encryptedProperties}}"
}
"tags": "{{ .inputs.\"tags\" }}",
"port_context": {
"entity": "{{ .entity }}",
"blueprint": "{{ .action.blueprint }}",
"runId": "{{ .run.id }}",
"trigger": "{{ .trigger }}"
}
},
"reportWorkflowStatus": true
Expand Down Expand Up @@ -272,12 +247,11 @@ on:
tags:
required: true
type: string
port_payload:
port_context:
required: true
description:
Port's payload, including details for who triggered the action and
general context (blueprint, run id, etc...)
type: string
description: >-
Action and general context (blueprint, run id, etc...)
env:
TF_LOG: INFO
Expand All @@ -299,9 +273,9 @@ jobs:
clientId: ${{ secrets.PORT_CLIENT_ID }}
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
operation: PATCH_RUN
runId: ${{ fromJson(inputs.port_payload).context.runId }}
runId: ${{ fromJson(inputs.port_context).runId }}
logMessage: |
Starting a GitHub workflow to tag the Azure resource: ${{fromJson(inputs.port_payload).context.entity}} ... ⛴️
Starting a GitHub workflow to tag the Azure resource: ${{ fromJson(inputs.port_context).entity.identifier }} ... ⛴️
- name: Checkout the repository to the runner
uses: actions/checkout@v2
Expand Down Expand Up @@ -349,8 +323,8 @@ jobs:
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
TF_VAR_port_client_id: ${{ secrets.PORT_CLIENT_ID }}
TF_VAR_port_client_secret: ${{ secrets.PORT_CLIENT_SECRET }}
TF_VAR_port_run_id: ${{fromJson(inputs.port_payload).context.runId}}
TF_VAR_storage_account_name: ${{fromJson(inputs.port_payload).context.entity}}
TF_VAR_port_run_id: ${{ fromJson(inputs.port_context).runId }}
TF_VAR_storage_account_name: ${{ fromJson(inputs.port_context).entity.identifier }}
TF_VAR_resource_tags: ${{ github.event.inputs.tags }}
run: |
terraform plan \
Expand All @@ -367,8 +341,8 @@ jobs:
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
baseUrl: https://api.getport.io
operation: PATCH_RUN
runId: ${{fromJson(inputs.port_payload).context.runId}}
logMessage: Failed to tag azure resource ${{fromJson(inputs.port_payload).context.entity}}
runId: ${{fromJson(inputs.port_context).runId}}
logMessage: Failed to tag azure resource ${{ fromJson(inputs.port_context).entity.identifier }}


- name: Create a log message
Expand All @@ -378,8 +352,8 @@ jobs:
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
baseUrl: https://api.getport.io
operation: PATCH_RUN
runId: ${{fromJson(inputs.port_payload).context.runId}}
logMessage: Added tags to ${{fromJson(inputs.port_payload).context.entity}}
runId: ${{fromJson(inputs.port_context).runId}}
logMessage: Added tags to ${{ fromJson(inputs.port_context).entity.identifier }}
```

</details>
Expand Down Expand Up @@ -417,11 +391,10 @@ on:
tags:
required: true
type: string
port_payload:
port_context:
required: true
description:
Port's payload, including details for who triggered the action and
general context (blueprint, run id, etc...)
Details for who triggered the action and general context (blueprint, run id, etc...)
type: string


Expand All @@ -436,9 +409,9 @@ jobs:
clientId: ${{ secrets.PORT_CLIENT_ID }}
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
operation: PATCH_RUN
runId: ${{ fromJson(inputs.port_payload).context.runId }}
runId: ${{ fromJson(inputs.port_context).runId }}
logMessage: |
Starting a GitHub worklfow to tag the Azure resource: ${{fromJson(inputs.port_payload).context.entity}} ... ⛴️
Starting a GitHub worklfow to tag the Azure resource: ${{fromJson(inputs.port_context).entity.identifier}} ... ⛴️
- uses: azure/login@v1
Expand All @@ -451,7 +424,7 @@ jobs:
// highlight-start
RESOURCE_GROUP: YourResourceGroup
// highlight-end
STORAGE_NAME: ${{ fromJson(inputs.port_payload).context.entity }}
STORAGE_NAME: ${{ fromJson(inputs.port_context).entity.identifier }}
TAGS: ${{ github.event.inputs.tags }}
with:
azcliversion: latest
Expand All @@ -468,8 +441,8 @@ jobs:
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
baseUrl: https://api.getport.io
operation: PATCH_RUN
runId: ${{fromJson(inputs.port_payload).context.runId}}
logMessage: Added tags to ${{fromJson(inputs.port_payload).context.entity}}
runId: ${{fromJson(inputs.port_context).runId}}
logMessage: Added tags to ${{fromJson(inputs.port_context).entity.identifier}}

```
</details>
Expand Down

0 comments on commit d734a6e

Please sign in to comment.