Skip to content

Commit

Permalink
fix: invalid local vars
Browse files Browse the repository at this point in the history
This fixes an issue where Terraform complains because the default of network and subnetwork is `null`.

```
│ Error: Inconsistent conditional result types
│
│   on .terraform/modules/spacelift/main.tf line 6, in locals:
│    6:   network                   = var.enable_network ? module.network.network : var.network
│     ├────────────────
│     │ module.network.network is object with 16 attributes
│     │ var.enable_network is true
│     │ var.network is null
│
│ The true and false result expressions must have consistent types. The 'true' value includes object attribute "auto_create_subnetworks", which is absent in the 'false' value.
```

The hack here is to transform those to a tuple and use the ternary operator to set the proper tuple index to use.

I'm not sure why I did not catched that while working on it back in December ...
  • Loading branch information
eliecharra committed Jan 13, 2025
1 parent 211d646 commit f601168
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ resource "random_id" "seed" {
}

locals {
network = var.enable_network ? module.network.network : var.network
subnetwork = var.enable_network ? module.network.subnetwork : var.subnetwork
network = [ module.network.network, var.network ][var.enable_network ? 0 : 1]
subnetwork = [ module.network.subnetwork,var.subnetwork ][var.enable_network ? 0 : 1]
gke_service_account_email = var.enable_gke ? module.iam.gke_service_account_email : var.node_service_account.email
}

Expand Down

0 comments on commit f601168

Please sign in to comment.