github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/pkg/terraform/presets.go (about) 1 package terraform 2 3 import ( 4 "strings" 5 6 "github.com/zclconf/go-cty/cty" 7 ) 8 9 func createPresetValues(b *Block) map[string]cty.Value { 10 presets := make(map[string]cty.Value) 11 12 // here we set up common "id" values that are set by the provider - this ensures all blocks have a default 13 // referencable id/arn. this isn't perfect, but the only way to link blocks in certain circumstances. 14 presets["id"] = cty.StringVal(b.ID()) 15 16 if strings.HasPrefix(b.TypeLabel(), "aws_") { 17 presets["arn"] = cty.StringVal(b.ID()) 18 } 19 20 // workaround for weird iam feature 21 switch b.TypeLabel() { 22 case "aws_iam_policy_document": 23 presets["json"] = cty.StringVal(b.ID()) 24 } 25 26 return presets 27 28 } 29 30 func postProcessValues(b *Block, input map[string]cty.Value) map[string]cty.Value { 31 32 // alias id to "bucket" (bucket name) for s3 bucket resources 33 if strings.HasPrefix(b.TypeLabel(), "aws_s3_bucket") { 34 if bucket, ok := input["bucket"]; ok { 35 input["id"] = bucket 36 } else { 37 input["bucket"] = cty.StringVal(b.ID()) 38 } 39 } 40 41 return input 42 }