Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port 8078 update git hub actions for azure #1208

Merged
merged 11 commits into from
May 26, 2024
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\" }}",
"context": {
phalbert marked this conversation as resolved.
Show resolved Hide resolved
"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:
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.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.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.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\" }}",
"context": {
phalbert marked this conversation as resolved.
Show resolved Hide resolved
"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:
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.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.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.context).runId }}
TF_VAR_storage_account_name: ${{ fromJson(inputs.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.context).runId}}
logMessage: Failed to tag azure resource ${{ fromJson(inputs.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.context).runId}}
logMessage: Added tags to ${{ fromJson(inputs.context).entity.identifier }}
```

</details>
Expand Down Expand Up @@ -436,7 +410,7 @@ jobs:
clientId: ${{ secrets.PORT_CLIENT_ID }}
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
operation: PATCH_RUN
runId: ${{ fromJson(inputs.port_payload).context.runId }}
runId: ${{ fromJson(inputs.context).runId }}
logMessage: |
Starting a GitHub worklfow to tag the Azure resource: ${{fromJson(inputs.port_payload).context.entity}} ... ⛴️

Expand Down Expand Up @@ -468,7 +442,7 @@ jobs:
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
baseUrl: https://api.getport.io
operation: PATCH_RUN
runId: ${{fromJson(inputs.port_payload).context.runId}}
runId: ${{fromJson(inputs.context).runId}}
logMessage: Added tags to ${{fromJson(inputs.port_payload).context.entity}}

```
Expand Down