mirror of
https://github.com/outbackdingo/terraform-provider-util.git
synced 2026-01-27 10:20:41 +00:00
da83c2d11446a04eb634eab116fc37f47549bf89
util_register resource for storing a value
* Set a register value to persist in state, even after
the value is no longer set in the Terraform resource
* Setting the value to `null` or "" (empty string)
won't alter the resource value (or show a diff)
* Allow the value to be updated (plan shows a diff)
This differs from conditional expressions that check that
a value isn't null or default to a value (which may be a
data reference to the old value):
```tf
locals {
out = var.foo == null ? data.old_foo : var.foo
}
data "old_foo" ...
```
Instead, it allows a Terraform resource value to retain
a value from a previous declarative state. This can be
useful in cases where querying and referencing the value
again is expensive and the value cannot change externally.
```tf
resource "util_register" "example" {
set = null # previously "bar"
}
output "out" {
value = util_register.example.value # "bar"
}
```
terraform-provider-util 
terraform-provider-util provides some low-level utility functions.
Usage
Configure the util provider (e.g. providers.tf).
provider "util" {}
terraform {
required_providers {
ct = {
source = "poseidon/util"
version = "0.2.0"
}
}
}
Perform a set of replacements on content with replace.
data "util_replace" "example" {
content = "hello world"
replacements = {
"/(h|H)ello/": "Hallo",
"world": "Welt",
}
}
# Hallo Welt
output "example" {
value = data.ct_replace.example.replaced
}
Store a value in state that persists until changed to a non-empty value.
resource "util_register" "example" {
set = "a1b2c3"
}
Later, the register's value may be updated, but setting it to null or "" is ignored.
resource "util_register" "example" {
set = null
}
output "sha" {
value = util_register.example.value # "a1b2c3"
}
Run terraform init to ensure plugin version requirements are met.
$ terraform init
Requirements
- Terraform v0.13+ installed
Development
Binary
To develop the provider plugin locally, build an executable with Go v1.16+.
make
Languages
Go
89.9%
Makefile
9.1%
HCL
1%