Skip to content

Commit

Permalink
fix: Lazy eval data source only if enabled (#76)
Browse files Browse the repository at this point in the history
* eval data if enabled

* add a simple test for disabled path

* test with an unused api
  • Loading branch information
bharathkkb authored Sep 2, 2020
1 parent 37b52e8 commit f2c9913
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
11 changes: 11 additions & 0 deletions examples/simple_example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,14 @@ module "cli" {
create_cmd_body = "services enable youtube.googleapis.com --project ${var.project_id}"
destroy_cmd_body = "services disable youtube.googleapis.com --project ${var.project_id}"
}

module "cli-disabled" {
source = "../.."

platform = "linux"
additional_components = ["kubectl", "beta"]

enabled = false
create_cmd_body = "services enable datastore.googleapis.com --project ${var.project_id}"
destroy_cmd_body = "services disable datastore.googleapis.com --project ${var.project_id}"
}
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ locals {
gcloud_bin_abs_path = abspath(local.gcloud_bin_path)
components = join(",", var.additional_components)

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

gcloud = local.skip_download ? "gcloud" : "${local.gcloud_bin_path}/gcloud"
Expand Down
1 change: 1 addition & 0 deletions test/integration/simple_example/controls/gcloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
its(:exit_status) { should eq 0 }
its(:stderr) { should eq "" }
its(:stdout) { should match "youtube.googleapis.com" }
its(:stdout) { should_not match "datastore.googleapis.com" }
end
end

0 comments on commit f2c9913

Please sign in to comment.