This repository serves the purpose of provisioning the essential resources needed for an Azure Function App, followed by the deployment of a Node.js-based HTTP-triggered function application.
- Terraform
- NodeJs
- Express
- NPM
- Github Actions
Repository includes 3 main directories
.github
: Includes pipeline filesApplication
: Includes nodejs function appInfra
: Includes terraform files to deploy Infrastructure.
├── azure-function-app
│ ├── .github
│ │ ├── **/*.yml
├── Application
│ ├── UserFa
│ │ ├── index.js
│ │ ├── function.json
├── Infra
│ │ ├── main.tf
└── .gitignore
- Azure Account with an Active Subscription
- Azure CLI
- Terraform CLI
Note
Make sure you are in Infra Directory
# login to azure account
az login
terraform init
terraform plan
terraform apply
In the repository, Terraform is set up to utilize an Azure Storage Account as a backend to store the state file. If you prefer not to use a remote backend, you can safely remove the following code block from Infra/main.tf
Tip
It's good to use remote backend for production env.
backend "azurerm" {
resource_group_name = "Infra-Resource"
storage_account_name = "configterraformsa"
container_name = "tfstate"
key = "terraform.tfstate"
use_oidc = true
}
├── azure-function-app
│ ├── .github
│ │ ├── tf-unit-tests.yml
│ │ ├── tf-plan/apply.yml
│ │ ├── tf-destriy.yml
This action is triggered by any push to a branch, specifically checking for changes within the Infra directory. This ensures that unnecessary runs are avoided when there are no changes in the Infra. The pipeline then proceeds to conduct basic testing using Terraform commands.
This has 2 Jobs to run based on conditions.
Upon the raising of a pull request and the presence of changes within the Infra directory, this process automatically executes. Upon successful completion, it appends the Terraform plan to the pull request for review.
This process is initiated either upon the merging of a pull request into the main branch or if there are direct changes made to the main branch. It then proceeds to deploy the infrastructure as defined in the main.tf file.
This action is manually triggered to clean up resources after a successful test on lower environments.