Skip to content

Commit

Permalink
✨ terraform.settings.backend (#1995)
Browse files Browse the repository at this point in the history
  • Loading branch information
arlimus authored Sep 30, 2023
1 parent 6d76369 commit b18ce89
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
15 changes: 15 additions & 0 deletions providers/terraform/resources/hcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,12 +556,14 @@ func initTerraformSettings(runtime *plugin.Runtime, args map[string]*llx.RawData
return nil, &mqlTerraformSettings{
Block: plugin.TValue[*mqlTerraformBlock]{State: plugin.StateIsSet | plugin.StateIsNull},
RequiredProviders: plugin.TValue[interface{}]{State: plugin.StateIsSet, Data: []interface{}{}},
Backend: plugin.TValue[interface{}]{State: plugin.StateIsSet, Data: []interface{}{}},
}, nil
}

settingsBlock := blocks[0].(*mqlTerraformBlock)
args["block"] = llx.ResourceData(settingsBlock, "terraform.block")
args["requiredProviders"] = llx.DictData(map[string]interface{}{})
args["backend"] = llx.DictData(map[string]interface{}{})

if settingsBlock.block.State == plugin.StateIsSet {
hb := settingsBlock.block.Data
Expand All @@ -574,6 +576,19 @@ func initTerraformSettings(runtime *plugin.Runtime, args map[string]*llx.RawData
}
args["requiredProviders"] = llx.DictData(dict)
}

backendBlock := getBlockByName(hb, "backend")
if backendBlock != nil {
attributes, _ := backendBlock.Body.JustAttributes()
dict, err := hclResolvedAttributesToDict(attributes)
if err != nil {
return nil, nil, err
}
if len(backendBlock.Labels) != 0 {
dict["type"] = backendBlock.Labels[0]
}
args["backend"] = llx.DictData(dict)
}
}

return args, nil, nil
Expand Down
2 changes: 2 additions & 0 deletions providers/terraform/resources/terraform.lr
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ terraform.settings {
block terraform.block
// Provider Requirements
requiredProviders dict
// Backend configuration
backend dict
}

// Terraform State
Expand Down
12 changes: 12 additions & 0 deletions providers/terraform/resources/terraform.lr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion providers/terraform/resources/terraform.lr.manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ resources:
terraform.module:
fields:
block:
min_mondoo_version: latest
min_mondoo_version: 9.0.0
dir: {}
key: {}
source: {}
Expand Down Expand Up @@ -132,6 +132,8 @@ resources:
- terraform
terraform.settings:
fields:
backend:
min_mondoo_version: latest
block: {}
requiredProviders: {}
min_mondoo_version: 5.31.0
Expand Down

0 comments on commit b18ce89

Please sign in to comment.