Skip to content

Commit

Permalink
Merge branch 'master' into invalid_tf_files_in_subfolders
Browse files Browse the repository at this point in the history
  • Loading branch information
yaronya committed Oct 21, 2020
2 parents df4bd47 + cace701 commit 3353c0f
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 8 deletions.
@@ -0,0 +1,31 @@
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"
}
}
@@ -0,0 +1,31 @@
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"
}
}
23 changes: 15 additions & 8 deletions tfschema/tfschema.go
Expand Up @@ -21,7 +21,7 @@ func IsTaggable(dir string, resource hclwrite.Block) bool {
resourceType := terraform.GetResourceType(resource)

if providers.IsSupportedResource(resourceType) {
providerName, _ := detectProviderName(resourceType)
providerName, _ := detectProviderName(resource)
client := getClient(providerName, dir)
typeSchema, err := client.GetResourceTypeSchema(resourceType)
if err != nil {
Expand Down Expand Up @@ -54,14 +54,21 @@ type TfSchemaAttribute struct {
Type string
}

// shamefully copied from
// https://github.com/minamijoyo/tfschema/blob/8e65902597e0eb9ce7d5ac2b56bf948a1bf17429/command/meta.go#L20
func detectProviderName(name string) (string, error) {
s := strings.SplitN(name, "_", 2)
if len(s) < 2 {
return "", fmt.Errorf("Failed to detect a provider name: %s", name)
func detectProviderName(resource hclwrite.Block) (string, error) {
providerAttribute := resource.Body().GetAttribute("provider")

if providerAttribute == nil {
resourceType := resource.Labels()[0]
s := strings.SplitN(resourceType, "_", 2)
if len(s) < 2 {
return "", fmt.Errorf("Failed to detect a provider name: %s", resourceType)
}
return s[0], nil
} else {
providerTokens := providerAttribute.Expr().BuildTokens(hclwrite.Tokens{})
providerName := strings.Trim(string(providerTokens.Bytes()), "\" ")
return providerName, nil
}
return s[0], nil
}

func getClient(providerName string, dir string) tfschema.Client {
Expand Down

0 comments on commit 3353c0f

Please sign in to comment.