Skip to content

Commit

Permalink
Merge branch 'profiles'
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Burnett committed Mar 17, 2016
2 parents 6159a1d + af642ba commit 0bcf028
Show file tree
Hide file tree
Showing 13 changed files with 1,505 additions and 116 deletions.
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,64 @@ resource "bigip_ltm_virtual_address" "vs_va" {

`traffic_group` - (Optional, Default=/Common/traffic-group-1) Specify the partition and traffic group

## bigip_ltm_policy

Configure [local traffic policies](https://support.f5.com/kb/en-us/solutions/public/15000/000/sol15085.html).
This is a fairly low level resource that does little to make actually using policies any simpler. A solid
understanding of how policies and their associated rules, actions and conditions
are managed through iControlREST is recommended.

### Example

```
resource "bigip_ltm_policy" "policy" {
name = "my_policy"
strategy = "/Common/first-match"
requires = ["http"]
controls = ["forwarding"]
rule {
name = "rule1"
condition {
httpUri = true
startsWith = true
values = ["/foo"]
}
condition {
httpMethod = true
values = ["GET"]
}
action {
forward = true
pool = "/Common/my_pool"
}
}
}
```

### Reference

`name` - (Required) Name of the policy

`strategy` - (Required) Strategy selection when more than one rule matches.

`requires` - (Required) Defines the types of conditions that you can use when configuring a rule.

`controls` - (Required) Defines the types of actions that you can use when configuring a rule.

`rule` - defines a single rule to add to the policy. Multiple rules can be defined for a single policy.

**Rules**

Actions and Conditions support all fields available via the iControlREST API. You can see all of the
available fields in the [iControlREST API documentation](https://devcentral.f5.com/d/icontrol-rest-api-reference-version-120).
Each field in the actions and conditions objects is available. Pro tip: Create your policy via the GUI first then use
the REST API to figure out how to configure the terraform resource.

`name` (Required) - Name of the rule

`action` - Defines a single action. Multiple actions can exist per rule.

`condition` - Defines a single condition. Multiple conditions can exist per rule.
40 changes: 34 additions & 6 deletions bigip/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package bigip
import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
"log"
"reflect"
"strings"
)

const DEFAULT_PARTITION = "Common"
Expand Down Expand Up @@ -30,7 +33,7 @@ func Provider() terraform.ResourceProvider {
Optional: true,
Default: false,
Description: "Enable to use an external authentication source (LDAP, TACACS, etc)",
},
},
"login_ref": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Expand All @@ -40,12 +43,13 @@ func Provider() terraform.ResourceProvider {
},

ResourcesMap: map[string]*schema.Resource{
"bigip_ltm_virtual_server": resourceBigipLtmVirtualServer(),
"bigip_ltm_node": resourceBigipLtmNode(),
"bigip_ltm_pool": resourceBigipLtmPool(),
"bigip_ltm_monitor": resourceBigipLtmMonitor(),
"bigip_ltm_irule": resourceBigipLtmIRule(),
"bigip_ltm_virtual_server": resourceBigipLtmVirtualServer(),
"bigip_ltm_node": resourceBigipLtmNode(),
"bigip_ltm_pool": resourceBigipLtmPool(),
"bigip_ltm_monitor": resourceBigipLtmMonitor(),
"bigip_ltm_irule": resourceBigipLtmIRule(),
"bigip_ltm_virtual_address": resourceBigipLtmVirtualAddress(),
"bigip_ltm_policy": resourceBigipLtmPolicy(),
},

ConfigureFunc: providerConfigure,
Expand All @@ -65,6 +69,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
return config.Client()
}

//Convert slice of strings to schema.Set
func makeStringSet(list *[]string) *schema.Set {
ilist := make([]interface{}, len(*list))
for i, v := range *list {
Expand All @@ -73,10 +78,33 @@ func makeStringSet(list *[]string) *schema.Set {
return schema.NewSet(schema.HashString, ilist)
}

//Convert schema.Set to a slice of strings
func setToStringSlice(s *schema.Set) []string {
list := make([]string, s.Len())
for i, v := range s.List() {
list[i] = v.(string)
}
return list
}

//Copy map values into an object where map key == object field name (e.g. map[foo] == &{Foo: ...}
func mapEntity(d map[string]interface{}, obj interface{}) {
val := reflect.ValueOf(obj).Elem()
for field, _ := range d {
f := val.FieldByName(strings.Title(field))
if f.IsValid() {
if f.Kind() == reflect.Slice {
incoming := d[field].([]interface{})
s := reflect.MakeSlice(f.Type(), len(incoming), len(incoming))
for i := 0; i < len(incoming); i++ {
s.Index(i).Set(reflect.ValueOf(incoming[i]))
}
f.Set(s)
} else {
f.Set(reflect.ValueOf(d[field]))
}
} else {
log.Printf("[WARN] You probably weren't expecting %s to be an invalid field", field)
}
}
}
2 changes: 1 addition & 1 deletion bigip/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ func TestProvider(t *testing.T) {
if err := Provider().(*schema.Provider).InternalValidate(); err != nil {
t.Fatalf("err: %s", err)
}
}
}
28 changes: 14 additions & 14 deletions bigip/resource_bigip_ltm_irule.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package bigip
import (
"log"

"github.com/scottdware/go-bigip"
"github.com/hashicorp/terraform/helper/schema"
"github.com/scottdware/go-bigip"
)

func resourceBigipLtmIRule() *schema.Resource {
Expand All @@ -17,22 +17,22 @@ func resourceBigipLtmIRule() *schema.Resource {

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
Type: schema.TypeString,
Required: true,
Description: "Name of the iRule",
ForceNew: true,
ForceNew: true,
},

"partition": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
Description: "LTM Partition",
ForceNew: true,
ForceNew: true,
},

"irule": &schema.Schema{
Type: schema.TypeString,
Required: true,
Type: schema.TypeString,
Required: true,
Description: "The iRule body",
},
},
Expand All @@ -58,7 +58,7 @@ func resourceBigipLtmIRuleRead(d *schema.ResourceData, meta interface{}) error {
name := d.Id()

irule, err := client.IRule(name)
if err != nil{
if err != nil {
return err
}
d.Set("partition", irule.Partition)
Expand All @@ -75,7 +75,7 @@ func resourceBigipLtmIRuleExists(d *schema.ResourceData, meta interface{}) (bool

_, err := client.IRule(name)
if err != nil {
return false, nil
return false, err
}

return true, nil
Expand All @@ -87,9 +87,9 @@ func resourceBigipLtmIRuleUpdate(d *schema.ResourceData, meta interface{}) error
name := d.Id()

r := &bigip.IRule{
Name: name,
Name: name,
Partition: d.Get("partition").(string),
Rule: d.Get("irule").(string),
Rule: d.Get("irule").(string),
}

return client.ModifyIRule(name, r)
Expand All @@ -99,4 +99,4 @@ func resourceBigipLtmIRuleDelete(d *schema.ResourceData, meta interface{}) error
client := meta.(*bigip.BigIP)
name := d.Id()
return client.DeleteIRule(name)
}
}
84 changes: 42 additions & 42 deletions bigip/resource_bigip_ltm_monitor.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package bigip

import (
"log"
"fmt"
"log"

"github.com/scottdware/go-bigip"
"github.com/hashicorp/terraform/helper/schema"
"github.com/scottdware/go-bigip"
)

func resourceBigipLtmMonitor() *schema.Resource {
Expand All @@ -18,89 +18,89 @@ func resourceBigipLtmMonitor() *schema.Resource {

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
Type: schema.TypeString,
Required: true,
Description: "Name of the monitor",
ForceNew: true,
ForceNew: true,
},

"parent": &schema.Schema{
Type: schema.TypeString,
Required: true,
Type: schema.TypeString,
Required: true,
ValidateFunc: validateParent,
ForceNew: true,
Description: "Existing monitor to inherit from. Must be one of http, https, icmp or gateway-icmp.",
ForceNew: true,
Description: "Existing monitor to inherit from. Must be one of http, https, icmp or gateway-icmp.",
},

"interval": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Type: schema.TypeInt,
Optional: true,
Description: "Check interval in seconds",
Default: 3,
Default: 3,
},

"timeout": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Type: schema.TypeInt,
Optional: true,
Description: "Timeout in seconds",
Default: 16,
Default: 16,
},

"send": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Default: "GET /\\r\\n",
Type: schema.TypeString,
Optional: true,
Default: "GET /\\r\\n",
Description: "Request string to send.",
},

"receive": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
Description: "Expected response string.",
},

"receive_disable": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
Description: "Expected response string.",
},

"partition": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Default: DEFAULT_PARTITION,
Type: schema.TypeString,
Optional: true,
Default: DEFAULT_PARTITION,
Description: "LTM Partition",
ForceNew: true,
ForceNew: true,
},

"reverse": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Default: false,
Default: false,
},

"transparent": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Default: false,
Default: false,
},

"manual_resume": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Default: false,
Default: false,
},

"ip_dscp": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Default: 0,
Default: 0,
},

"time_until_up": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Default: 0,
Type: schema.TypeInt,
Optional: true,
Default: 0,
Description: "Time in seconds",
},
},
Expand Down Expand Up @@ -182,16 +182,16 @@ func resourceBigipLtmMonitorUpdate(d *schema.ResourceData, meta interface{}) err
name := d.Id()

m := &bigip.Monitor{
Interval: d.Get("interval").(int),
Timeout: d.Get("timeout").(int),
SendString: d.Get("send").(string),
ReceiveString: d.Get("receive").(string),
Interval: d.Get("interval").(int),
Timeout: d.Get("timeout").(int),
SendString: d.Get("send").(string),
ReceiveString: d.Get("receive").(string),
ReceiveDisable: d.Get("receive_disable").(string),
Reverse: d.Get("reverse").(bool),
Transparent: d.Get("transparent").(bool),
IPDSCP: d.Get("ip_dscp").(int),
TimeUntilUp: d.Get("time_until_up").(int),
ManualResume: d.Get("manual_resume").(bool),
Reverse: d.Get("reverse").(bool),
Transparent: d.Get("transparent").(bool),
IPDSCP: d.Get("ip_dscp").(int),
TimeUntilUp: d.Get("time_until_up").(int),
ManualResume: d.Get("manual_resume").(bool),
}

return client.ModifyMonitor(name, d.Get("parent").(string), m)
Expand Down
Loading

0 comments on commit 0bcf028

Please sign in to comment.