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

Unable to tag google-beta resources #17

Closed
roni-frantchi opened this issue May 11, 2020 · 1 comment · Fixed by #65
Closed

Unable to tag google-beta resources #17

roni-frantchi opened this issue May 11, 2020 · 1 comment · Fixed by #65
Labels
bug Something isn't working P4 tfschema

Comments

@roni-frantchi
Copy link
Contributor

roni-frantchi commented May 11, 2020

Samle Terraform file:

data "google_billing_account" "account" {
  provider = google-beta
  billing_account = "000000-0000000-0000000-000000"
}

resource "google_billing_budget" "budget" {
  provider = google-beta
  billing_account = data.google_billing_account.account.id
  display_name = "Example Billing Budget"

  budget_filter {
    projects = ["projects/my-project-name"]
    credit_types_treatment = "EXCLUDE_ALL_CREDITS"
    services = ["services/24E6-581D-38E5"] # Bigquery
  }

  amount {
    specified_amount {
      currency_code = "USD"
      units = "100000"
    }
  }

  threshold_rules {
    threshold_percent = 0.5
  }
  threshold_rules {
    threshold_percent = 0.9
    spend_basis = "FORECASTED_SPEND"
  }
}

Trying to tag it will fail:

2020/05/11 16:00:06 Processing resource [google_billing_budget service_budget]
2020/05/11 16:00:07 Failed to find resource type: google_billing_budget
panic: exit status 1
goroutine 1 [running]:
github.com/env0/terratag/errors.PanicOnError(...)
	/home/runner/work/terratag/terratag/errors/errors.go:10
github.com/env0/terratag/tfschema.IsTaggable(0x6a302a, 0x1, 0x0, 0xc0004cef70, 0xc0004ef920, 0xc0004ef950, 0xc0004ef8f0, 0x0, 0xc00054c1e0, 0x0, ...)
	/home/runner/work/terratag/terratag/tfschema/tfschema.go:22 +0x565
main.tagFileResources(0xc0001343f0, 0x83, 0x6a302a, 0x1, 0x7fff9a869cbc, 0x68, 0xc)
	/home/runner/work/terratag/terratag/main.go:72 +0x3d2
main.tagDirectoryResources(0x6a302a, 0x1, 0x7fff9a869cbc, 0x68, 0x400001, 0xc)
	/home/runner/work/terratag/terratag/main.go:49 +0x2e1
main.main()
	/home/runner/work/terratag/terratag/main.go:31 +0xbb

That's tfschema failing to resolve that resource type.
That is because tfschema resolves the provider based on the resource first underscore prefix.
But in this case, the resource is named google_billing_budget despite only existing for google-beta provider.

Running tfschema resource list google-beta shows:

...
google_billing_account
...

But trying to run tfschema resource google_billing_account won't find that resource.
Trying to runt tfschema resource google-beta_billing_account won't work either, as while here the provider is found, the resource name is wrong.

Workaround

Opened #18 to short-circuit and skip these resources for now - keeping this issue open till we figure out how to tag these resources as well.

Note If you see this error:

Failed to NewClient: Failed to find plugin: google. Plugin binary was not found in any of the following directories: [., /opt, terraform.d/plugins/linux_amd64, .terraform/plugins/linux_amd64, /home/node/.terraform.d/plugins, /home/node/.terraform.d/plugins/linux_amd64, /home/node/go/bin]

That is because tfschema couldn't find google provider at all - you should add that provider (in conjunction to the google-beta provider) - even if not used and terraform init

@roni-frantchi
Copy link
Contributor Author

shlomimatichin added a commit to shlomimatichin/terratag that referenced this issue Oct 18, 2020
shlomimatichin added a commit to env0/tfschema that referenced this issue Oct 18, 2020
referencing env0/terratag#17

look at the example below: `google_billing_budget` resource
comes from `google-beta` provider. previously, code assumed
the provider name is the first part by underscore, e.g., `google`.

```
data "google_billing_account" "account" {
  provider = google-beta
  billing_account = "000000-0000000-0000000-000000"
}

resource "google_billing_budget" "budget" {
  provider = google-beta
  billing_account = data.google_billing_account.account.id
  display_name = "Example Billing Budget"

  budget_filter {
    projects = ["projects/my-project-name"]
    credit_types_treatment = "EXCLUDE_ALL_CREDITS"
    services = ["services/24E6-581D-38E5"] # Bigquery
  }

  amount {
    specified_amount {
      currency_code = "USD"
      units = "100000"
    }
  }

  threshold_rules {
    threshold_percent = 0.5
  }
  threshold_rules {
    threshold_percent = 0.9
    spend_basis = "FORECASTED_SPEND"
  }
}
```
roni-frantchi added a commit that referenced this issue Oct 19, 2020
Co-authored-by: Roni Frantchi <roni-frantchi@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P4 tfschema
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant