cisagov / cool-sharedservices-freeipa

Terraform code to create the FreeIPA shared service in the COOL environment.
Creative Commons Zero v1.0 Universal
4 stars 0 forks source link

Make 'COOL' a variable name instead of hard coding #60

Open bra1ncramp opened 2 years ago

bra1ncramp commented 2 years ago

💡 Summary

What is the work, as a high-level summary?

Motivation and context

In order to make this project more environment agnostic, it would be good to make references to cool variable.

This would allow implementers to simply modify their tfvars file for variances.

Implementation notes

Recommend adding a variable in variables.tf that takes the netbios_name, and converts to lowercase. Throughout other .tf files, insert this variable instead of hard-coding 'cool'.

netbios_name then, can be set in the .tfvars file.

key examples where this would be used would be in remote_states.tf and backend.tf

Acceptance criteria

How do we know when this work is done?

bra1ncramp commented 2 years ago

add the following variable in variables.tf - then replace cool with ${var.cool_realm} in remote_states.tf and backend.tf

variable "cool_realm" {
  type        = string
  description = "The realm name for your enviroment. Used to set object names."
  default     = "cool"
}

example from remote_states.tf

data "terraform_remote_state" "images_parameterstore" {
  backend = "s3"

  config = {
    encrypt        = true
    bucket         = "cisa-${var.cool_realm}-terraform-state"
    dynamodb_table = "terraform-state-lock"
    profile        = "${var.cool_realm}-terraform-backend"
    region         = "us-east-1"
    key            = "${var.cool_realm}-images-parameterstore/terraform.tfstate"
  }

  workspace = terraform.workspace
}

this value can be overwritten in the tfvars file with cool_realm = "my_realm"

bra1ncramp commented 2 years ago

This may not be possible - apparently, we cannot use variables in backend https://github.com/hashicorp/terraform/issues/13022