Skip to content

Commit

Permalink
Merge pull request #450 from cloudflare/fw-rules-dynamic-keys
Browse files Browse the repository at this point in the history
cloudflare_ruleset: support writing map type nested blocks
  • Loading branch information
tamas-jozsa authored Aug 26, 2022
2 parents 8e21fee + 42b5b07 commit b68dec6
Show file tree
Hide file tree
Showing 4 changed files with 236 additions and 187 deletions.
12 changes: 12 additions & 0 deletions internal/app/cf-terraforming/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,18 @@ func generateResources() func(cmd *cobra.Command, args []string) {
actionParams.(map[string]interface{})[logCustomFields] = newLogCustomFields
}
}
// check if our ruleset is of action 'skip'
if rules.([]interface{})[ruleCounter].(map[string]interface{})["action"] == "skip" {
for rule := range actionParams.(map[string]interface{}) {
for key, value := range actionParams.(map[string]interface{})[rule].(map[string]interface{}) {
var rulesList []string
for _, val := range value.([]interface{}) {
rulesList = append(rulesList, val.(string))
}
actionParams.(map[string]interface{})[rule].(map[string]interface{})[key] = strings.Join(rulesList, ", ")
}
}
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions internal/app/cf-terraforming/cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ func writeNestedBlock(attributes []string, schemaBlock *tfjson.SchemaBlock, attr
}
case ty.IsListType(), ty.IsSetType():
nestedBlockOutput += writeAttrLine(attrName, attrStruct[attrName], true)
case ty.IsMapType():
nestedBlockOutput += writeAttrLine(attrName, attrStruct[attrName], false)
default:
log.Debugf("unexpected nested type %T for %s", ty, attrName)
}
Expand Down
Loading

0 comments on commit b68dec6

Please sign in to comment.