-
Notifications
You must be signed in to change notification settings - Fork 5
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
Do not create a random password if a admin_password is provided to the VM module #135
Comments
Might not be possible, see #119. Depends on how your custom admin password is generated though. |
In our case, we already have our VMs with a random password stored in the state. With the current config, we will have two |
@hknutsen What value will not be known during the planning? |
Consider the following example configuration: resource "random_password" "custom" {
length = 128
lower = true
upper = true
numeric = true
special = true
min_lower = 1
min_upper = 1
min_numeric = 1
min_special = 1
}
resource "random_password" "default" {
count = random_password.custom.result == null ? 1 : 0
length = 16
lower = true
upper = true
numeric = true
special = true
min_lower = 1
min_upper = 1
min_numeric = 1
min_special = 1
} Assumptions:
Running $ terraform plan
╷
│ Error: Invalid count argument
│
│ on main.tf line 14, in resource "random_password" "default":
│ 14: count = random_password.custom.result == null ? 1 : 0
│
│ The "count" value depends on resource attributes that cannot be determined until apply, so Terraform cannot predict how many instances will be created. To work around this, use the -target argument to first apply only the resources
│ that the count depends on.
╵ This is because the Note that the error message specifies that you can use |
I would agree if you relied on the output result from another resource within the module for the count = local.is_windows ? 0 : 1 |
But if the provided value of that variable comes from a resource, you can run into the same problem. Basically, the suggested implementation would completely remove the possibility of providing a custom password generated by Terraform. The current implementation of this module has no such issues, the only downside is that if you provide a custom password, the password generated by this module will still exist in your state, though remain unused. |
I have used the same strategy before without encountering any problems. But it is not a big deal and we can leave the random password resource in 😄 |
Leaving the issue open for a little longer though, in case we come up with a solution 🙌 |
Might be worth taking a new look at this once Terraform 1.9 has been released:
From changelog. |
There has been no activity on this issue for 60 days. |
As of today, the "deferred actions" feature is still labed as an experiment in the alpha pre-release of Terraform 1.10, so we might have to wait a while for it. I think we can close this issue for now and rather keep an eye on the changelog for when the "deferred actions" feature moves out from the experimentation stage. Any other thoughts @equinor/terraform-baseline-maintainers? |
Module Name
vm
Description
Only create the random password resource if an admin_password has not been provided.
Example Terraform Configuration
The text was updated successfully, but these errors were encountered: