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

Support null values in config - from Incus #492

Merged
merged 2 commits into from
Jul 8, 2024

Conversation

MusicDin
Copy link
Member

@MusicDin MusicDin commented Jul 5, 2024

Cherry picked from lxc/terraform-provider-incus#82

@MusicDin MusicDin requested a review from simondeziel July 5, 2024 10:14
@MusicDin MusicDin marked this pull request as ready for review July 5, 2024 10:14
Copy link
Member

@simondeziel simondeziel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit 1st message would need a s/incus/lxd/g, please.

stgraber added 2 commits July 8, 2024 08:09
Terraform allows for configuration to be set to NULL.
This is generally assumed to be equivalent to not having put the
configuration line in question and is particularly useful when dealing
with conditional behaviors.

A couple of examples:
```
resource "lxd_network" "this" {
  name = "foo"

  config = {
    "ipv4.address" = var.deploy == "production" ? "none" : null
  }
}

resource "lxd_profile" "this" {
  name = "foo"

  config = {
    "environment.http_proxy" = var.deploy == "production" ? "http://my-proxy:3128" : null
    "environment.https_proxy" = var.deploy == "production" ? "http://my-proxy:3128" : null
  }
}
```

To handle this properly, a few changes are needed:
 - Read the Terraform config as a map[string]*string to allow for NULL
 - When set to NULL and config key doesn't exist, tell Terraform it's NULL
 - When set to NULL and config key is computed, tell Terraform it's NULL

Signed-off-by: Stéphane Graber <[email protected]>
(cherry picked from commit 5f8effa895a4edb3324402c66276534750b0bb7e)
Signed-off-by: Din Music <[email protected]>
Signed-off-by: Stéphane Graber <[email protected]>
(cherry picked from commit 97258f8d4bc2bd5d58345f148f422f27c1687b5e)
Signed-off-by: Din Music <[email protected]>
Copy link
Member

@simondeziel simondeziel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@simondeziel simondeziel merged commit f7f0752 into terraform-lxd:main Jul 8, 2024
9 checks passed
@MusicDin MusicDin deleted the cp/null-config branch July 8, 2024 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants