Create only properties?

Is there a way to define a property that is only used at creation time, but ignored for updates?

  1. I tried a diffsupressfunc that always returns true, but that suppresses the property even at creation time.
  2. I was going to try a custom diff func, but I cannot clear out a diff of a property unless it is a Computed value, which this is not since the user needs to set it at creation time.
  3. I tried enhancing my diffsuppressfunc by checking if d.IsResourceNew() to only suppress if not new, but to my surprise, d.IsResourceNew returns false even during creation.
  4. I tried setting both Computed and Optional as true which kind of works, but when the user changes the value, it still generates a diff which I want to ignore

Hello!

Have you tried the following? It’s similar to your first attempt but registers a diff at creation time.

DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
    // checks if the old/new values are nil, if they're both nil, then no state exist, so register a diff
    if old == "" && new == "" {
        return false
    }
    return true
},

I’m interested in the use case in which a property should be set at create time and have its changes ignored. Normally you’d want to use something like ForceNew, forcing re-creation when the create-time-only field changes. Otherwise, the configuration isn’t really being captured as a code, as a terraform destroy followed by a terraform apply won’t yield the same result.

I think you could set it to optional and computed, and then error out in the CustomizeDiff function if it’s not set at Create time, simulating Required. And the CustomizeDiff could suppress the diff as you indicated.