Hi,
I'm trying to model something like this:
resource "calico_profile" "myprofile" {
name = "myprofile"
labels = { endpointlabel = "myvalue" }
spec {
ingress {
rule {
action = "deny"
source {
net = "10.0.0.0/24"
}
icmp {
code = 100
}
}
rule {
action = "allow"
source {
net = "11.0.0.0/24"
}
}
}
egress {
rule {
action = "deny"
protocol = "tcp"
source {
net = "12.0.0.0/24"
}
}
rule {
action = "allow"
protocol = "udp"
source {
net = "13.0.0.0/24"
}
}
}
}
} But am having trouble with the schema. Code here ->
https://github.com/wleese/terraform-provider-calico/blob/master/calico/resource_calico_profile.goHere's a snippet:
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"labels": &schema.Schema{
Type: schema.TypeMap,
Optional: true,
ForceNew: false,
},
"spec": &schema.Schema{
Type: schema.TypeList,
Optional: true,
ForceNew: false,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ingress": &schema.Schema{
Type: schema.TypeList,
Basically all these lists is not what I want. I want a map but them it seems I can't use Elem to define structure. I can't find much documentation on any of this and would like some advice on how to proceed. Basically I want to get rid of the useless arrays:
spec.#: "2" => "1"
spec.0.ingress.#: "0" => "1"
spec.0.ingress.0.rule.#: "0" => "2"
spec.0.ingress.0.rule.0.action: "" => "deny"
spec.0.ingress.0.rule.0.icmp.#: "0" => "1"
spec.0.ingress.0.rule.0.icmp.0.code: "" => "100"
spec.0.ingress.0.rule.0.icmp.0.type: "" => "101"
spec.0.ingress.0.rule.0.protocol: "" => "tcp"
spec.0.ingress.0.rule.0.source.#: "0" => "1"
spec.0.ingress.0.rule.0.source.0.net: "" => "10.0.0.0/24"
spec.0.ingress.0.rule.0.source.0.notPorts.#: "0" => "1"
spec.0.ingress.0.rule.0.source.0.notPorts.0: "" => "40:60"
spec.0.ingress.0.rule.0.source.0.ports.#: "0" => "2"
spec.0.ingress.0.rule.0.source.0.ports.0: "" => "1:10"
spec.0.ingress.0.rule.0.source.0.ports.1: "" => "20:30"
spec.0.ingress.0.rule.0.source.0.selector: "" => "profile == 'test'"
spec.0.ingress.0.rule.1.action: "" => "allow"
spec.0.ingress.0.rule.1.protocol: "" => "udp"
spec.0.ingress.0.rule.1.source.#: "0" => "1"
spec.0.ingress.0.rule.1.source.0.net: "" => "11.0.0.0/24" ('ports' and 'notports' are the only valid use of arrays here)
Should I be using TypeSets instead?
-- William