Dalton Hubble da83c2d114 Add 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"
}
```
2022-03-29 20:32:08 -07:00
2022-03-18 20:50:45 -07:00

terraform-provider-util Build Status

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

Development

Binary

To develop the provider plugin locally, build an executable with Go v1.16+.

make
Description
No description provided
Readme MIT 188 KiB
Languages
Go 89.9%
Makefile 9.1%
HCL 1%