Skip to content

Commit

Permalink
Merge branch 'identifier-refactor'
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Burnett committed May 31, 2016
2 parents e4a540c + 7160541 commit e5918d8
Show file tree
Hide file tree
Showing 21 changed files with 893 additions and 166 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*.tfstate*
.idea/
bin/

target/
#test files
bigip.test
17 changes: 5 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
language: go

go:
- 1.5
- 1.6

before_install:
- go get github.com/mitchellh/gox

script:
- go test -v ./...
- gox -output="target/bin/{{.OS}}_{{.Arch}}/{{.Dir}}" -osarch="linux/amd64 linux/386" -os="windows darwin"
install: make get-deps

after_success:
- mkdir target/pkg
- tar czf target/pkg/terraform-provider-bigip_darwin_386.tar.gz -C target/bin/darwin_386 .
- tar czf target/pkg/terraform-provider-bigip_darwin_amd64.tar.gz -C target/bin/darwin_amd64 .
- tar czf target/pkg/terraform-provider-bigip_linux_386.tar.gz -C target/bin/linux_386 .
- tar czf target/pkg/terraform-provider-bigip_linux_amd64.tar.gz -C target/bin/linux_amd64 .
- tar czf target/pkg/terraform-provider-bigip_windows_386.tar.gz -C target/bin/windows_386 .
- tar czf target/pkg/terraform-provider-bigip_windows_amd64.tar.gz -C target/bin/windows_amd64 .
script: make bin

after_success: make dist

deploy:
provider: releases
Expand Down
67 changes: 67 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
TEST = ./bigip
TESTARGS = -v
PROJ = terraform-provider-bigip

ARCHS = amd64 386
OS = windows darwin linux

OUT_DIR = target
BIN_DIR = $(OUT_DIR)/bin
PKG_DIR = $(OUT_DIR)/pkg

PKGS = $(foreach arch,$(ARCHS),$(foreach os,$(OS),$(PKG_DIR)/$(PROJ)_$(os)_$(arch)$(PKG_SUFFIX)))
BINS = $(foreach arch,$(ARCHS),$(foreach os,$(OS),$(BIN_DIR)/$(os)_$(arch)/$(PROJ)))

default: bin

build: fmt get-deps
@go build ./...

bin: test
@gox -help >/dev/null 2>&1 ; if [ $$? -ne 2 ]; then \
go get github.com/mitchellh/gox; \
fi
@gox -output="$(BIN_DIR)/{{.OS}}_{{.Arch}}/{{.Dir}}" -arch="$(ARCHS)" -os="$(OS)"

dist:
@mkdir -p $(PKG_DIR) 2>/dev/null
@for arch in $(ARCHS); do \
for os in $(OS); do \
echo "$(PKG_DIR)/$(PROJ)_$${os}_$${arch}.tar.gz"; \
tar czf $(PKG_DIR)/$(PROJ)_$${os}_$${arch}.tar.gz -C $(BIN_DIR)/$${os}_$${arch} .; \
done \
done

get-deps:
@go get -t -v ./...

fmt:
@gofmt -l -w . bigip/

# vet runs the Go source code static analysis tool `vet` to find
# any common errors.
vet:
@go tool vet 2>/dev/null ; if [ $$? -eq 3 ]; then \
go get golang.org/x/tools/cmd/vet; \
fi
@echo "go tool vet $(VETARGS) ."
@go tool vet $(VETARGS) $$(ls -d */ | grep -v vendor) ; if [ $$? -eq 1 ]; then \
echo ""; \
echo "Vet found suspicious constructs. Please check the reported constructs"; \
echo "and fix them if necessary before submitting the code for review."; \
exit 1; \
fi

test: build
@TF_ACC= go test $(TEST) $(TESTARGS) -timeout=30s -parallel=4

testacc: fmt build
@if [[ "$(BIGIP_USER)" == "" || "$(BIGIP_HOST)" == "" || "-z $(BIGIP_PASSWORD)" == "" ]]; then \
echo "ERROR: BIGIP_USER, BIGIP_PASSWORD and BIGIP_HOST must be set."; \
exit 1; \
fi
@TF_ACC=1 go test $(TEST) $(TESTARGS) -timeout 120m

clean:
@go clean
@rm -rf target/
57 changes: 39 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Overview

A [Terraform](terraform.io) provider for F5 BigIP. Resources are currently available for LTM. [![Build Status](https://travis-ci.org/DealerDotCom/terraform-provider-bigip.svg?branch=master)](https://travis-ci.org/DealerDotCom/terraform-provider-bigip)
A [Terraform](terraform.io) provider for F5 BigIP. Resources are currently available for LTM.

[![Build Status](https://travis-ci.org/DealerDotCom/terraform-provider-bigip.svg?branch=master)](https://travis-ci.org/DealerDotCom/terraform-provider-bigip)


# Installation

Expand Down Expand Up @@ -38,14 +41,17 @@ provider "bigip" {

# Resources

For resources should be named with their "full path". The full path is the combination of the partition + name of the resource.
For example `/Common/my-pool`.

## bigip_ltm_monitor

Configures a custom monitor for use by health checks.

### Example
```
resource "bigip_ltm_monitor" "monitor" {
name = "terraform_monitor"
name = "/Common/terraform_monitor"
parent = "http"
send = "GET /some/path\r\n"
timeout = "999"
Expand All @@ -59,8 +65,6 @@ resource "bigip_ltm_monitor" "monitor" {

`parent` - (Required) Existing LTM monitor to inherit from

`partition` - (Required) LTM partition to create the resource in. Default = Common.

`interval` - (Optional) Check interval in seconds

`timeout` - (Optional) Timeout in seconds
Expand Down Expand Up @@ -89,7 +93,7 @@ Manages a node configuration

```
resource "bigip_ltm_node" "node" {
name = "terraform_node1"
name = "/Common/terraform_node1"
address = "10.10.10.10"
}
```
Expand All @@ -106,7 +110,7 @@ resource "bigip_ltm_node" "node" {

```
resource "bigip_ltm_pool" "pool" {
name = "terraform-pool"
name = "/Common/terraform-pool"
load_balancing_mode = "round-robin"
nodes = ["${bigip_ltm_node.node.name}:80"]
monitors = ["${bigip_ltm_monitor.monitor.name}","${bigip_ltm_monitor.monitor2.name}"]
Expand All @@ -118,8 +122,6 @@ resource "bigip_ltm_pool" "pool" {

`name` - (Required) Name of the pool

`partition` - (Required) LTM partition to create the resource in. Default = Common.

`nodes` - (Optional) Nodes to add to the pool. Format node_name:port. e.g. `node01:443`

`monitors` - (Optional) List of monitor names to associate with the pool
Expand All @@ -138,7 +140,7 @@ Configures a Virtual Server

```
resource "bigip_ltm_virtual_server" "vs" {
name = "terraform_vs_http"
name = "/Common/terraform_vs_http"
destination = "10.12.12.12"
port = 80
pool = "${bigip_ltm_pool.pool.name}"
Expand All @@ -149,8 +151,6 @@ resource "bigip_ltm_virtual_server" "vs" {

`name` - (Required) Name of the virtual server

`partition` - (Required, Default=Common) LTM partition to create the resource in.

`port` - (Required) Listen port for the virtual server

`destination` - (Required) Destination IP
Expand All @@ -172,12 +172,12 @@ Creates iRules
```
# Loading from a file is the preferred method
resource "bigip_ltm_irule" "rule" {
name = "terraform_irule"
name = "/Common/terraform_irule"
irule = "${file("myirule.tcl")}"
}
resource "bigip_ltm_irule" "rule2" {
name = "terraform_irule2"
name = "/Common/terraform_irule2"
irule = <<EOF
when CLIENT_ACCEPTED {
log local0. "test"
Expand All @@ -204,7 +204,7 @@ with the corresponding virtual server.
```
resource "bigip_ltm_virtual_address" "vs_va" {
name = "${bigip_ltm_virtual_server.vs.destination}"
name = "/Common/${bigip_ltm_virtual_server.vs.destination}"
advertize_route = true
}
```
Expand All @@ -215,8 +215,6 @@ resource "bigip_ltm_virtual_address" "vs_va" {

`description` - (Optional) Description of the virtual address

`partition` - (Optional, Default=Common) LTM partition to create the resource in

`advertize_route` - (Optional) Enabled dynamic routing of the address

`conn_limit` - (Optional, Default=0) Max number of connections for virtual address
Expand All @@ -242,12 +240,12 @@ are managed through iControlREST is recommended.

```
resource "bigip_ltm_policy" "policy" {
name = "my_policy"
name = "/Common/my_policy"
strategy = "/Common/first-match"
requires = ["http"]
controls = ["forwarding"]
rule {
name = "rule1"
name = "/Common/rule1"
condition {
httpUri = true
Expand Down Expand Up @@ -292,3 +290,26 @@ resource "bigip_ltm_policy" "policy" {
`action` - Defines a single action. Multiple actions can exist per rule.

`condition` - Defines a single condition. Multiple conditions can exist per rule.


# Building

Create the distributable packages like so:

```
make && make dist
```

# Testing

Running the acceptance test suite requires an F5 to test against. Set `BIGIP_HOST`, `BIGIP_USER`
and `BIGIP_PASSWORD` to a device to run the tests against. By default tests will use the `Common`
partition for creating objects. You can change the partition by setting `BIGIP_TEST_PARTITION`.

```
BIGIP_HOST=f5.mycompany.com BIGIP_USER=foo BIGIP_PASSWORD=secret make testacc
```


Read [here](https://github.com/hashicorp/terraform/blob/master/.github/CONTRIBUTING.md#running-an-acceptance-test) for
more information about acceptance testing in Terraform.
19 changes: 12 additions & 7 deletions bigip/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,44 @@ func Provider() terraform.ResourceProvider {
Type: schema.TypeString,
Required: true,
Description: "Domain name/IP of the BigIP",
DefaultFunc: schema.EnvDefaultFunc("BIGIP_HOST", nil),
},
"username": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "Username with API access to the BigIP",
DefaultFunc: schema.EnvDefaultFunc("BIGIP_USER", nil),
},
"password": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "The user's password",
DefaultFunc: schema.EnvDefaultFunc("BIGIP_PASSWORD", nil),
},
"token_auth": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Enable to use an external authentication source (LDAP, TACACS, etc)",
},
DefaultFunc: schema.EnvDefaultFunc("BIGIP_TOKEN_AUTH", nil),
},
"login_ref": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Default: "tmos",
Description: "Login reference for token authentication (see BIG-IP REST docs for details)",
DefaultFunc: schema.EnvDefaultFunc("BIGIP_LOGIN_REF", nil),
},
},

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(),
"bigip_ltm_policy": resourceBigipLtmPolicy(),
},

ConfigureFunc: providerConfigure,
Expand Down
18 changes: 18 additions & 0 deletions bigip/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import (

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
"os"
)

var TEST_PARTITION = "Common"

var testAccProviders map[string]terraform.ResourceProvider
var testAccProvider *schema.Provider

Expand All @@ -15,10 +18,25 @@ func init() {
testAccProviders = map[string]terraform.ResourceProvider{
"bigip": testAccProvider,
}
if v := os.Getenv("BIGIP_TEST_PARTITION"); v != "" {
TEST_PARTITION = v
}
}

func TestProvider(t *testing.T) {
if err := Provider().(*schema.Provider).InternalValidate(); err != nil {
t.Fatalf("err: %s", err)
}
}

func testAcctPreCheck(t *testing.T) {
if os.Getenv("BIGIP_TOKEN_AUTH") != "" && os.Getenv("BIGIP_LOGIN_REF") != "" {
return
}
for _, s := range [...]string{"BIGIP_HOST", "BIGIP_USER", "BIGIP_PASSWORD"} {
if os.Getenv(s) == "" {
t.Fatal("Either BIGIP_TOKEN_AUTH + BIGIP_LOGIN_REF or BIGIP_USER, BIGIP_PASSWORD and BIGIP_HOST are required for tests.")
return
}
}
}
Loading

0 comments on commit e5918d8

Please sign in to comment.