CICD Pipelines Archives - For all your terraform needs https://terraformarchitect.com/category/cicd-pipelines/ Automation cannot be an afterthought (TM) Wed, 24 Jul 2024 23:11:05 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 Workspaces in TerraforM https://terraformarchitect.com/cicd-pipelines/workspaces-in-terraform/?utm_source=rss&utm_medium=rss&utm_campaign=workspaces-in-terraform https://terraformarchitect.com/cicd-pipelines/workspaces-in-terraform/#respond Wed, 24 Jul 2024 23:11:05 +0000 https://terraformarchitect.com/?p=383 workspaces allow you to manage multiple environments or configurations within a single Terraform configuration directory. Each workspace maintains its own state file, enabling you to isolate environments such as development, […]

The post Workspaces in TerraforM appeared first on For all your terraform needs.

]]>
workspaces allow you to manage multiple environments or configurations within a single Terraform configuration directory. Each workspace maintains its own state file, enabling you to isolate environments such as development, staging, and production.

Key Concepts

  1. Default Workspace: When you initialize a Terraform project, a default workspace is created. This is where Terraform commands operate if no other workspace is specified.
  2. Custom Workspaces: You can create additional workspaces to manage separate states for different environments or configurations.

Creating and Switching Workspaces

  • Create a Workspace:
    sh

    terraform workspace new <workspace_name>
  • List Workspaces:
    sh

    terraform workspace list
  • Switch to a Workspace:
    sh

    terraform workspace select <workspace_name>
  • Delete a Workspace:
    sh

    terraform workspace delete <workspace_name>

Example Use Cases

Example 1: Managing Multiple Environments

Suppose you have a Terraform configuration that sets up infrastructure for a web application. You want to manage separate environments (development, staging, production) using workspaces.

  1. Create Workspaces:
    sh

    terraform workspace new development
    terraform workspace new staging
    terraform workspace new production
  2. Configure Variables: Use workspace-specific variable files or conditionals within your configuration files to manage environment-specific settings.
    hcl

    variable "environment" {
    description = "The environment for this configuration"
    type = string
    }

    locals {
    environment = terraform.workspace
    }

    resource "aws_instance" "web" {
    count = local.environment == "production" ? 3 : 1
    ami = "ami-0c55b159cbfafe1f0"
    instance_type = "t2.micro"
    tags = {
    Name = "web-server-${local.environment}"
    }
    }

  3. Switch and Apply Configuration:
    sh

    terraform workspace select development
    terraform apply

    terraform workspace select staging
    terraform apply

    terraform workspace select production
    terraform apply

Each workspace maintains a separate state file, ensuring that the resources for each environment are managed independently.

Example 2: Isolating Client Configurations

Imagine you are managing infrastructure for multiple clients, and you want to keep each client’s resources isolated.

  1. Create Workspaces for Clients:
    sh

    terraform workspace new clientA
    terraform workspace new clientB
  2. Client-Specific Variables: Define variables or use conditionals based on the workspace name to configure resources for each client.
    hcl

    variable "client_name" {
    description = "The client for this configuration"
    type = string
    }

    locals {
    client = terraform.workspace
    }

    resource "aws_s3_bucket" "client_bucket" {
    bucket = "myapp-${local.client}-bucket"
    acl = "private"
    }

  3. Switch and Apply Configuration:
    sh

    terraform workspace select clientA
    terraform apply

    terraform workspace select clientB
    terraform apply

This ensures that each client’s resources are managed separately, preventing any accidental overlap or interference.

Summary

Workspaces in Terraform provide a powerful way to manage multiple environments or configurations within a single codebase. By using workspaces, you can maintain separate state files and easily switch between different setups, whether for different environments (like development, staging, production) or different clients. This isolation helps to ensure that changes in one workspace do not affect resources in another, providing a more organized and secure way to manage infrastructure.

The post Workspaces in TerraforM appeared first on For all your terraform needs.

]]>
https://terraformarchitect.com/cicd-pipelines/workspaces-in-terraform/feed/ 0
How many Pipelines? https://terraformarchitect.com/cicd-pipelines/how-many-pipelines/?utm_source=rss&utm_medium=rss&utm_campaign=how-many-pipelines https://terraformarchitect.com/cicd-pipelines/how-many-pipelines/#respond Mon, 12 Jul 2021 02:17:01 +0000 https://terraformarchitect.com/?p=149 Also read How many Non Prod Environments should you have? The TWO most commonly implemented ones would be the managed infrastructure services pipeline (or just infra pipeline) and the app […]

The post How many Pipelines? appeared first on For all your terraform needs.

]]>
Also read How many Non Prod Environments should you have?

The TWO most commonly implemented ones would be the managed infrastructure services pipeline (or just infra pipeline) and the app pipeline.

A Foundational Pipeline would include setting up the original organization and folder structure in GCP.

application and infrastructure pipelines GCP
application and infrastructure pipelines GCP




Need an experienced Data Protection Expert?  Anuj has successfully delivered over a dozen deployments on each of the public clouds (AWS/GCP/Azure) including several DevSecOps engagements. Set up a time with Anuj Varma.

 

 

The post How many Pipelines? appeared first on For all your terraform needs.

]]>
https://terraformarchitect.com/cicd-pipelines/how-many-pipelines/feed/ 0
Terraform Landing Zones https://terraformarchitect.com/landing-zones-in-terraform/terraform-landing-zones/?utm_source=rss&utm_medium=rss&utm_campaign=terraform-landing-zones https://terraformarchitect.com/landing-zones-in-terraform/terraform-landing-zones/#respond Fri, 11 Jun 2021 16:30:26 +0000 https://terraformarchitect.com/?p=140 Where does Terraform fit in? Terraform modules can be common to any CI CD pipeline (whether Azure Devops or gitops).  One typically starts with a baseline module – sometimes called […]

The post Terraform Landing Zones appeared first on For all your terraform needs.

]]>
Where does Terraform fit in?

Terraform modules can be common to any CI CD pipeline (whether Azure Devops or gitops).  One typically starts with a baseline module – sometimes called a Landing Zone.

GCP

GCP Terraform Landing Zone ( Cloud Foundation Toolkit)

Azure

Azure Terraform Landing Zone

AWS

A fairly simple landing zone. AWS itself has some Cloud formation and terraform modules available for landing zones.



Need an experienced AWS/GCP/Azure/DevSecOps Professional to help out with your Public Cloud Strategy? Set up a time with Anuj Varma.

The post Terraform Landing Zones appeared first on For all your terraform needs.

]]>
https://terraformarchitect.com/landing-zones-in-terraform/terraform-landing-zones/feed/ 0
Azure Devops versus Gitops https://terraformarchitect.com/cicd-pipelines/azure-devops-versus-gitops/?utm_source=rss&utm_medium=rss&utm_campaign=azure-devops-versus-gitops https://terraformarchitect.com/cicd-pipelines/azure-devops-versus-gitops/#respond Fri, 11 Jun 2021 16:20:56 +0000 https://terraformarchitect.com/?p=137 Azure Devops has tooling for the entire CI CD pipeline and also the Agile management of the delivery. Azure Boards, Azure Repos and Azure Credentialing is what will be part […]

The post Azure Devops versus Gitops appeared first on For all your terraform needs.

]]>
Azure Devops has tooling for the entire CI CD pipeline and also the Agile management of the delivery.

Azure Boards, Azure Repos and Azure Credentialing is what will be part of any Azure Devops project.

With Git, you have gitlab (preferably over github), git repos and git credentialing.

User friendliness wise, Azure Devops wins hands down. However, there is a  cost associated with ADO adoption across the enterprise.

Where does Terraform fit in? 

See this post for cloud landing zones created with terraform.



Need an experienced AWS/GCP/Azure/DevSecOps Professional to help out with your Public Cloud Strategy? Set up a time with Anuj Varma.

The post Azure Devops versus Gitops appeared first on For all your terraform needs.

]]>
https://terraformarchitect.com/cicd-pipelines/azure-devops-versus-gitops/feed/ 0