Skip to content

Commit f2c9913

Browse files
authored
fix: Lazy eval data source only if enabled (#76)
* eval data if enabled * add a simple test for disabled path * test with an unused api
1 parent 37b52e8 commit f2c9913

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

examples/simple_example/main.tf

+11
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,14 @@ module "cli" {
2727
create_cmd_body = "services enable youtube.googleapis.com --project ${var.project_id}"
2828
destroy_cmd_body = "services disable youtube.googleapis.com --project ${var.project_id}"
2929
}
30+
31+
module "cli-disabled" {
32+
source = "../.."
33+
34+
platform = "linux"
35+
additional_components = ["kubectl", "beta"]
36+
37+
enabled = false
38+
create_cmd_body = "services enable datastore.googleapis.com --project ${var.project_id}"
39+
destroy_cmd_body = "services disable datastore.googleapis.com --project ${var.project_id}"
40+
}

main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ locals {
2222
gcloud_bin_abs_path = abspath(local.gcloud_bin_path)
2323
components = join(",", var.additional_components)
2424

25-
download_override = data.external.env_override[0].result.download
25+
download_override = var.enabled ? data.external.env_override[0].result.download : ""
2626
skip_download = local.download_override == "always" ? false : (local.download_override == "never" ? true : var.skip_download)
2727

2828
gcloud = local.skip_download ? "gcloud" : "${local.gcloud_bin_path}/gcloud"

test/integration/simple_example/controls/gcloud.rb

+1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@
1919
its(:exit_status) { should eq 0 }
2020
its(:stderr) { should eq "" }
2121
its(:stdout) { should match "youtube.googleapis.com" }
22+
its(:stdout) { should_not match "datastore.googleapis.com" }
2223
end
2324
end

0 commit comments

Comments
 (0)