Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty properties cause terraform configuration to fail #640

Open
lengors opened this issue Feb 11, 2025 · 0 comments
Open

Empty properties cause terraform configuration to fail #640

lengors opened this issue Feb 11, 2025 · 0 comments

Comments

@lengors
Copy link

lengors commented Feb 11, 2025

First off, not sure this is the appropriate repository to report the issue, though it can be directly fixed from here.

Problem description

Second, the issue is that certain resources fail (at least, authentik_policy_event_matcher, though I expect similar models to fail as well) due to how models with are being serialized into JSON.

The generated serializer ignores a property and does not include it in the serialized json, if the property is not set. This combined with the terrafom provider code, means that empty properties . For example, the app property from the model_policy_event_matcher, is not set to anything on the serialized JSON when not defined in the resource.

This on it's own is fine, but the authentik API expects it to be defined as either null or enum. And it does not assume null when missing.

These 3 behaviors combined, cause the resource to fail when left empty. Example of a resource that fails with 405 Method Not Allowed:

resource "authentik_policy_event_matcher" "events" {
  name = "events"
}

Proposed solution

One possible solution is to always set the property in the terraform provider (to null when empty). An example with app property from model_policy_event_matcher:

if a, ok := d.Get("app").(string); ok && a != "" {
  r.App.Set(api.AppEnum(a).Ptr())
} else {
  r.App.Set(null)
}

Edit: Seems like some resources already follow this pattern, so it just needs to be applied to the resources missing it.

Edit 2: Created PR for it: #645

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant