Skip to content

A repo using GitHub actions and Terraform to create cloud services using the GitHub Flow to preview the changes in ephemeral environments before being deployed to production.

License

OscarSantosMu/terraform-preview-envs

Repository files navigation

terraform-preview-envs

Conference at Talent Land 2023

This repository contains infrastructure as code written in Terraform that creates cloud services using GitHub actions, allowing changes to be previewed in ephemeral environments before being deployed to production.

Workflows

tf-unit-tests.yml: Runs unit tests for Terraform code and creates code scanning reports.

tf-drift.yml: Detects drifts between Terraform configuration and the actual state of the cloud resources, then creates issue.

tf-plan-apply.yml: Applies the Terraform changes in the cloud production environment.

tf-prev.yml: Creates a preview environment for a pull request, allowing changes to be tested before they are merged.

Getting started

  1. Create an Azure Storage account.
  2. Update Storage account info on main.tf at the backend block.
  3. Create 2 apps on Azure Active Directory (Write and Read)
  4. Register federated credentials for each of them (using environments, pull requests and branches)
  5. Assign RBAC to the Storage Account with Reader and Data Access to both apps.
  6. Assign RBAC to your Azure Subscription with Contributor for the Write app and Reader for the other app.
  7. Get Client Id, Object Id and Tenant Id from both apps.
  8. Register them as GitHub secrets and separating Client Id on environment secrets.
  9. Create a branch called prevenvs
  10. Create a branch with your feature and make a pr. Compare it with prevenvs.
  11. A GitHub Action workflow will be triggered

  1. Once deployed and success on the checks. Merge the pull request and check the ephemeral environments has gone.

Contributing

Contributions to this project are welcome. If you would like to contribute, please read the CONTRIBUTING.md file for guidelines.

Resources

Terraform

Tutorials

Examples

Terraform

Docker sample

About

A repo using GitHub actions and Terraform to create cloud services using the GitHub Flow to preview the changes in ephemeral environments before being deployed to production.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published