This example demonstrates how to deploy a storage account in Azure using Terraform templates via Port Actions.
The workflow is executed through a Jenkins pipeline.
- Install the following plugins in Jenkins:
- Azure Credentials - This plugin provides the
Azure Service Principal
kind in Jenkins Credentials. - Terraform Plugin
- Generic Webhook Trigger
- Azure Credentials - This plugin provides the
Follow these steps to get started:
-
Create the following as Jenkins Credentials:
- Create the Port Credentials using the
Username with password
kind.PORT_CLIENT_ID
- Port Client ID learn more.PORT_CLIENT_SECRET
- Port Client Secret learn more.
- Create the Azure Credentials using the
Azure Service Principal
kind. You can create a service principal in order to get the Azure credentials using this guide.ARM_CLIENT_ID
- Azure Client ID (APP ID) of the application.ARM_CLIENT_SECRET
- Azure Client Secret (Password) of the application.ARM_SUBSCRIPTION_ID
- Azure Subscription ID.ARM_TENANT_ID
- The Azure Tenant ID.
WEBHOOK_TOKEN
- The webhook token so that the job can only be triggered if that token is supplied.
- Create the Port Credentials using the
-
Create a Port blueprint: Azure Storage Blueprint
Keep in mind this can be any blueprint you would like and this is just an example.
- Create a Port Action in the self-service hub using this JSON definition
- Create the terraform templates in the root of your GitHub repository. You can them in the terraform folder:
main.tf
- This file will contain the resource blocks which define the Storage Account to be created in the Azure cloud and the entity to be createed in Port.variables.tf
– This file will contain the variable declarations that will be used in the resource blocks e.g. the port credentials and port run id.output.tf
– This file will contain the url of the Storage Account that needs to be generated on successful completion of “apply” operation. This url will be used on creating the Port entity in theendpoint
property.
In the
variables.tf
, replace the defaultresource_group_name
with your resource group from your Azure account. Check this guide to find your resource groups. You may also wish to set the default values of other variables.
-
Create a Jenkins pipeline using the provided file:
- Enable webhook trigger for a pipeline
- Define variables for a pipeline: Define the STORAGE_NAME, STORAGE_LOCATION, PORT_RUN_ID and BLUEPRINT_ID variables.
- Token Setup: Define the token to match
JOB_TOKEN
as configured in your Port Action.
NB: The pipeline includes a post run task of
cleanWs
whosedeleteDirs
parameter means that all generated files and temporary build artifacts will be deleted. Therefore, be sure to either change it or add backend for your terraform state on initialisation. -
Trigger the action from the self-service tab of your Port application.