Change Infrastructure

Now that we have bucket created, let’s modify it. Here’s the demo/ again.


resource "random_pet" "this" {
  length = 2

module "bucket" {
  source = "../../modules/example"

  name                        = "bucket-${}"
  uniform_bucket_level_access = var.uniform_bucket_level_access
  location                    = var.location

As you can see there’s a var.uniform_bucket_level_access variable. One way to update the infrastructure is to change the variable in the file directly.


variable "uniform_bucket_level_access" {
  description = "uniform_bucket_level_access"
  type        = bool
  default     = false

variable "location" {
  description = "location"
  type        = string
  default     = "US"

However, you can also use tfvars files. Terraspace will automatically use config/stacks/demo/tfvars files according the TS_ENV value. The default value is TS_ENV=dev. We’ll use tfvars files so we can use the same code for different environments.

Generate Starter Tfvars Files

Addtionally, Terraspace can generate starter tfvar files for us with the terraspace seed command.

$ terraspace seed demo
Reading: .terraspace-cache/us-central1/dev/stacks/demo/
      create  config/stacks/demo/tfvars/dev.tfvars

The produced file looks something like this:


# Optional variables:
# uniform_bucket_level_access = false
# location                    = "US"

Terraspace parses the demo/ file to generate the tfvars/dev.tfvars file. It detected that all the variables are optional. We’ll uncomment uniform_bucket_level_access and change it to uniform_bucket_level_access = true.


# Optional variables:
uniform_bucket_level_access = true
# location                    = "US"

Next, we’ll update the infrastructure.

More tools: