Getting Started
This document provides a guide on how to set up and run the AEP API in Azure.
- Getting Started
- Terraform Setup and Usage
- Secrets Setup
- Prerequisites
- Linting
- Initialization
- Planning
- Applying
- Destroying
- Continuous Deployment with GitHub Actions
Terraform Setup and Usage
This project uses Terraform to manage infrastructure. The Terraform scripts are located in the terraform/envs/stable
directory.
Secrets Setup
Secrets
To setup using Terraform, the following environment variables need to be set in your environment or in a .env
file in the root of the project directory:
ARM_CLIENT_ID=<arm_client_id>
ARM_CLIENT_SECRET=<arm_client_secret>
ARM_SUBSCRIPTION_ID=<arm_subscription_id>
ARM_TENANT_ID<arm_tenant_id>
BACKEND_RESOURCE_GROUP=<backend_resource_group>
BACKEND_STORAGE_ACCOUNT=<backend_resource_group>
BACKEND_CONTAINER_NAME=<backend_container_name>
SYSTEM_API_KEY=<system_api_key>
The ARM_CLIENT_ID
, ARM_CLIENT_SECRET
, ARM_SUBSCRIPTION_ID
, and ARM_TENANT_ID
are your Azure service principal credentials.
The BACKEND_RESOURCE_GROUP
is the Azure resource group where your terraform state is located.
The BACKEND_STORAGE_ACCOUNT
is the Azure storage account where your terraform state is located.
The BACKEND_CONTAINER_NAME
is the Azure storage container where your terraform state is located.
The SYSTEM_API_KEY
is the API key for the 'system' consumer that can be used to interact with the AEP API.
To use make, these secrets must be written to a .env
file in the root of the project directory.
Secrets with GitHub Actions
Using the secrets outlined in the previous section, you can set up your GitHub repository secrets by following these steps:
- Go to your GitHub repository.
- Click on the
Settings
tab. - Click on the
Secrets
tab. - Click on the
New repository secret
button. - Add the required secrets as outlined in the previous section.
Prerequisites
- Terraform >= 0.14
- Azure CLI
- Make
Linting
Before running any Terraform commands, it's a good practice to lint your Terraform scripts to catch any syntax or formatting issues. You can do this by running the following command:
make tf-lint
If the linting fails, you will need to fix the issues before you can proceed. You can also run the following command to automatically fix some of the issues:
make tf-fmt
Initialization
Before you can apply any Terraform configuration, you need to initialize your Terraform working directory. You can do this by running the following command:
make tf-init
This command is also defined in the Makefile and it runs the init_terraform.sh script located in the buildscripts directory.
Planning
The terraform plan command is used to create an execution plan. This step is necessary to see which actions Terraform will perform to reach the desired state defined in the Terraform scripts.
You can do this by running the following command:
make tf-plan
Applying
After planning, the next step is to apply the changes required to reach the desired state of the configuration, or the pre-determined set of actions generated by a terraform plan execution plan.
You can do this by running the following command:
make tf-apply
Destroying
If you want to destroy all resources created by Terraform, you can do this by running the following command:
make tf-destroy
Please note that this command will destroy all resources managed by Terraform in your Azure subscription.
Continuous Deployment with GitHub Actions
This project is set up to use GitHub Actions for continuous deployment. The workflow is defined in deploy-terraform.yml. On every push to the main branch, the workflow lints and initializes Terraform, creates an execution plan, and applies it. Ensure that the required environment variables are set in your GitHub repository secrets.