Skip to content

Commit

Permalink
skip any non-aws resources (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
roni-frantchi authored Mar 1, 2020
1 parent cb4039d commit f869851
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions tfschema/tfschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,39 @@ import (
"github.com/env0/terratag/errors"
"github.com/mitchellh/mapstructure"
"os/exec"
"strings"
)

func IsTaggable(dir string, resourceType string) (bool, bool) {
command := exec.Command("tfschema", "resource", "show", "-format=json", resourceType)
command.Dir = dir
output, err := command.Output()
outputAsString := string(output)
errors.PanicOnError(err, &outputAsString)

var schema map[string]interface{}

err = json.Unmarshal(output, &schema)
errors.PanicOnError(err, nil)

isTaggable := false
isTaggableViaSpecialTagBlock := false

attributes := schema["attributes"].([]interface{})
for _, attributeMap := range attributes {
var attribute TfSchemaAttribute
err := mapstructure.Decode(attributeMap, &attribute)
if strings.HasPrefix(resourceType, "aws_") {
command := exec.Command("tfschema", "resource", "show", "-format=json", resourceType)
command.Dir = dir
output, err := command.Output()
outputAsString := string(output)
errors.PanicOnError(err, &outputAsString)

var schema map[string]interface{}

err = json.Unmarshal(output, &schema)
errors.PanicOnError(err, nil)

if attribute.Name == "tags" {
isTaggable = true
attributes := schema["attributes"].([]interface{})
for _, attributeMap := range attributes {
var attribute TfSchemaAttribute
err := mapstructure.Decode(attributeMap, &attribute)
errors.PanicOnError(err, nil)

if attribute.Name == "tags" {
isTaggable = true
}
}
}

if resourceType == "aws_autoscaling_group" {
isTaggableViaSpecialTagBlock = true
if resourceType == "aws_autoscaling_group" {
isTaggableViaSpecialTagBlock = true
}
}

return isTaggable, isTaggableViaSpecialTagBlock
Expand Down

0 comments on commit f869851

Please sign in to comment.