Skip to content

script commands create

Yann Hervé edited this page Oct 18, 2019 · 2 revisions

resource creation

The resource creation is done via the 'resource' keyword.

The syntax is the following:

resource HNAME {
    ELEMENT
}

Example:

create an ipv6 host:

resource "#host" {
    host "myhost1" {
        ipv6_address = fd12::11
    }
}

create an ntp server

resource "#ntp" {
    ntp_server "fr_ntp" {
        ntp_host_name     = "fr.pool.ntp.org"
        address           = 151.80.124.104
        ntp_auth_key_type = none
    }
}

create an access rule in a policy

resource "#fw_policy/mypolicy/fw_ipv6_access_rules/myrule1/add_before" {
    fw_ipv6_access_rule "iamfirst" {
        destinations.dst "#network/lan8int";
        sources.src "#host/myhost1";
        services.service "#tcp_service/SSH";
        action.action = discard
        options.log_level = stored
    }
}

simplified notation

As you can see, the hnames can become quite long, so there are a few trick that help improving readability.

You don't have to use these tricks if you are not comfortable with them.

First trick: the hname can be split in two parts

For example, in the previous example, you could emphasize the action

"#single_fw/fw1/add_route"

can be expressed as:

- first part: "#single_fw/fw1"
- second part: "add_route"

Or you can emphasize the fact that the element is part of a another element

- first part: "#fw_policy/mypolicy"
- second part: "fw_ipv6_access_rules/myrule1/add_before"


resource HNAME_SECOND_PART {
    target=HNAME_FIRST_PART
    ELEMENT
}

So the previous example could be written

resource "fw_ipv6_access_rules/myrule1/add_before" {
    target="#fw_policy/mypolicy"
    fw_ipv6_access_rule "iamfirst" {
        destinations.dst "#network/lan8int";
        sources.src "#host/myhost1";
        services.service "#tcp_service/SSH";
        action.action = discard
        options.log_level = stored
    }
}

Second trick: the hname can be omitted

when it is the same as the resource element.

Example:

resource "#host" {
    host "myhost1" {
        ipv6_address = fd12::11
    }
}

could be written

resource {
    host "myhost1" { ipv6_address = fd12::11 }
}

Third trick: the '#' can be omitted

ONLY in the context of a resource command or a 'target' attribute. Else it is mandatory.

resource "#ntp" {
}

can be written

resource ntp {
}

Clone this wiki locally