Terraform your Terraform

Use the Scalr Provider to automate the creation of Scalr resources to manage your Terraform and OpenTofu structure.

Standardize your Terraform structure at scale:

  • Integrate with your existing cloud vending machines for end-to-end automation
  • Build modules for environment and workspace deployments
  • Automatically add OPA policies and provider configurations to environments
  • Onboard teams and apply RBAC

terraform {
    required_providers {
        scalr = {
            source = "registry.scalr.io/scalr/scalr"
            version= "~> 1.0.0"
        }
    }
}

data "scalr_vcs_provider" demo {
  name = var.provider_name
}

resource "scalr_environment" "demo" {
  name                            = "Workspace-Vending"
  account_id                      = "acc-sscctbisjkl1234"
  cost_estimation_enabled         = true
  default_provider_configurations = ["pcfg-uagarqni8a81234"]
  policy_groups                   = ["pgrp-sse7lrbdp2i1234"]
}

resource "scalr_workspace" "dev" {
  name                  = "dev"
  environment_id        = scalr_environment.demo.id
  vcs_provider_id       = data.scalr_vcs_provider.demo.id
  terraform_version     = "1.4.0"
  auto_apply            = true
  working_directory     = "app"
  var_files             = ["variables/dev/inputs.tfvars"]

  vcs_repo {
      identifier        = "repo/example-module"
      branch            = "main"
      trigger_prefixes  = ["app", "variables/dev"]
  }
      
  hooks {
      pre_plan          = "./hello-world.sh"
 }
  
}

resource "scalr_workspace" "prod" {
  name                   = "prod"
  environment_id         = scalr_environment.demo.id
  vcs_provider_id        = data.scalr_vcs_provider.demo.id
  terraform_version      = "1.4.0"
  working_directory      = "app"
  var_files              = ["variables/prod/inputs.tfvars"]

  vcs_repo {
      identifier         = "repo/example-module"
      branch             = "main"
      trigger_prefixes   = ["app", "variables/prod"]
  }

  hooks {
      pre_plan          = "./hello-world.sh"
 }

}