Skip to content

Commit

Permalink
Rename register set field to content
Browse files Browse the repository at this point in the history
* The noun `content` is a better field name than the verb `set`
  • Loading branch information
dghubble committed Mar 30, 2022
1 parent 9136f37 commit 373096a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 23 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Notable changes between releases.

## Latest

## v0.2.1

* Rename `util_register` field from `set` to `content`
* Fix `util_register` to mark `value` attribute as computed to propagate changes

## v0.2.0

* Add `util_register` resource for storing values
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ output "example" {
}
```

Store a value in state that persists until changed to a non-empty value.
Store a content value that persists in state until changed to a non-empty value.

```tf
resource "util_register" "example" {
set = "a1b2c3"
content = "a1b2c3"
}
```

Later, the register's value may be updated, but setting it to `null` or `""` is ignored.
Later, the register's content may be updated, but empty values (`null` or `""`) are ignored.

```tf
resource "util_register" "example" {
set = null
content = null
}
output "sha" {
Expand Down
12 changes: 6 additions & 6 deletions docs/resources/register.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Register

Store a value in state that persists until changed to a non-empty value.
Store a content value that persists in state until changed to a non-empty value.

```tf
resource "util_register" "example" {
set = "a1b2c3"
content = "a1b2c3"
}
```

Later, the register's value may be updated, but setting it to `null` or `""` is ignored.
Later, the register's content may be updated, but empty values (`null` or `""`) are ignored.

```tf
resource "util_register" "example" {
set = null
content = null
}
output "sha" {
Expand All @@ -22,8 +22,8 @@ output "sha" {

## Argument Reference

* `set` - set the register value (`""` or `null` values ignored)
* `content` - set the register value (`""` or `null` values ignored)

## Attribute Reference

* `value` - computed value of the register
* `value` - computed register value
2 changes: 1 addition & 1 deletion example/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
resource "util_register" "example" {
set = "a1b2c3"
content = "a1b2c3"
}
18 changes: 9 additions & 9 deletions util/resource_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func resourceRegister() *schema.Resource {
UpdateContext: registerUpdate,
DeleteContext: registerDelete,
Schema: map[string]*schema.Schema{
"set": &schema.Schema{
"content": &schema.Schema{
Type: schema.TypeString,
// Allow content to be null
Optional: true,
Expand All @@ -36,19 +36,19 @@ func resourceRegister() *schema.Resource {
Description: "Computed register value",
},
},
// Changes to set (that are non-empty) mark value as computed
// Changes to content (that are non-empty) mark value as computed
CustomizeDiff: customdiff.ComputedIf("value", func(ctx context.Context, d *schema.ResourceDiff, meta interface{}) bool {
return d.HasChange("set") && d.Get("set").(string) != ""
return d.HasChange("content") && d.Get("content").(string) != ""
}),
}
}

// registerCreate stores content as the register value.
func resourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
set := d.Get("set").(string)
d.Set("value", set)
d.SetId(strconv.Itoa(hashcode.String(set)))
content := d.Get("content").(string)
d.Set("value", content)
d.SetId(strconv.Itoa(hashcode.String(content)))
return diags
}

Expand All @@ -62,9 +62,9 @@ func registerRead(ctx context.Context, d *schema.ResourceData, meta interface{})
func registerUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics

set := d.Get("set").(string)
if set != "" {
d.Set("value", set)
content := d.Get("content").(string)
if content != "" {
d.Set("value", content)
}
return diags
}
Expand Down
6 changes: 3 additions & 3 deletions util/resource_register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

const registerInitial = `
resource "util_register" "example" {
set = "a1b2c3"
content = "a1b2c3"
}
output "out" {
Expand All @@ -18,7 +18,7 @@ output "out" {

const registerUnsetSHA = `
resource "util_register" "example" {
set = ""
content = ""
}
output "out" {
Expand All @@ -28,7 +28,7 @@ output "out" {

const registerUpdateSHA = `
resource "util_register" "example" {
set = "b2c3d4"
content = "b2c3d4"
}
output "out" {
Expand Down

0 comments on commit 373096a

Please sign in to comment.