Skip to content

Commit

Permalink
add import on vs, rs, pool and pool member (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo-ruth authored Feb 15, 2022
1 parent 66bc34e commit 865fb0d
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 45 deletions.
10 changes: 9 additions & 1 deletion docs/resources/loadbalance_pool.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,12 @@ resource "fortiadc_loadbalance_pool" "mypool" {

## Attribute Reference

* `id` - Pool Mkey (internal ID).
* `id` - Pool Mkey (internal ID).

## Import

Pools can be imported using their name:

```
$ terraform import fortiadc_loadbalance_pool.mypool mypool
```
10 changes: 9 additions & 1 deletion docs/resources/loadbalance_pool_member.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,12 @@ resource "fortiadc_loadbalance_pool_member" "mymember" {

## Attribute Reference

* `id` - Member Mkey (internal ID).
* `id` - Member Mkey (internal ID).

## Import

Pool members can be imported using their pool and name joined by a dot:

```
$ terraform import fortiadc_loadbalance_pool_member.mymember mypool.mymember
```
10 changes: 9 additions & 1 deletion docs/resources/loadbalance_real_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@ resource "fortiadc_loadbalance_real_server" "myrealserver" {

## Attribute Reference

* `id` - Real server Mkey (internal ID).
* `id` - Real server Mkey (internal ID).

## Import

Real servers can be imported using their name:

```
$ terraform import fortiadc_loadbalance_real_server.myrealserver myrealserver
```
10 changes: 9 additions & 1 deletion docs/resources/loadbalance_virtual_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,12 @@ resource "fortiadc_loadbalance_virtual_server" "myvirtualserver" {

## Attribute Reference

* `id` - Virtual server Mkey (internal ID).
* `id` - Virtual server Mkey (internal ID).

## Import

Virtual servers can be imported using their name:

```
$ terraform import fortiadc_loadbalance_virtual_server.myvirtualserver myvirtualserver
```
13 changes: 8 additions & 5 deletions fortiadc/resource_fortiadc_loadbalance_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,27 @@ func resourceFortiadcLoadbalancePool() *schema.Resource {
Read: resourceFortiadcLoadbalancePoolRead,
Update: resourceFortiadcLoadbalancePoolUpdate,
Delete: resourceFortiadcLoadbalancePoolDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"pool_type": &schema.Schema{
"pool_type": {
Type: schema.TypeString,
Optional: true,
Default: "ipv4",
},
"healtcheck_enable": &schema.Schema{
"healtcheck_enable": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"healtcheck_relationship": &schema.Schema{
"healtcheck_relationship": {
Type: schema.TypeString,
Optional: true,
Default: "AND",
Expand All @@ -41,7 +44,7 @@ func resourceFortiadcLoadbalancePool() *schema.Resource {
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"real_server_ssl_profile": &schema.Schema{
"real_server_ssl_profile": {
Type: schema.TypeString,
Optional: true,
Default: "NONE",
Expand Down
50 changes: 40 additions & 10 deletions fortiadc/resource_fortiadc_loadbalance_pool_member.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package fortiadc

import (
"context"
"errors"
"fmt"
"strconv"
"strings"

"github.com/Ouest-France/gofortiadc"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand All @@ -15,53 +17,81 @@ func resourceFortiadcLoadbalancePoolMember() *schema.Resource {
Read: resourceFortiadcLoadbalancePoolMemberRead,
Update: resourceFortiadcLoadbalancePoolMemberUpdate,
Delete: resourceFortiadcLoadbalancePoolMemberDelete,
Importer: &schema.ResourceImporter{
StateContext: func(ctx context.Context, d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) {
client := m.(*gofortiadc.Client)

// Split id to pool and member names
idParts := strings.Split(d.Id(), ".")
if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" {
return nil, fmt.Errorf("unexpected format of ID (%q), expected POOL.MEMBER", d.Id())
}
pool := idParts[0]
member := idParts[1]

// Read member ID
mkey, err := client.LoadbalanceGetPoolMemberID(pool, member)
if err != nil {
return nil, err
}

// Set pool and member
err = d.Set("pool", pool)
if err != nil {
return nil, err
}
d.SetId(mkey)

return []*schema.ResourceData{d}, nil
},
},

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"pool": &schema.Schema{
"pool": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"status": &schema.Schema{
"status": {
Type: schema.TypeString,
Optional: true,
Default: "enable",
},
"port": &schema.Schema{
"port": {
Type: schema.TypeInt,
Required: true,
},
"weight": &schema.Schema{
"weight": {
Type: schema.TypeInt,
Optional: true,
Default: 1,
},
"conn_limit": &schema.Schema{
"conn_limit": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
},
"recover": &schema.Schema{
"recover": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
},
"warmup": &schema.Schema{
"warmup": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
},
"warmrate": &schema.Schema{
"warmrate": {
Type: schema.TypeInt,
Optional: true,
Default: 100,
},
"conn_rate_limit": &schema.Schema{
"conn_rate_limit": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
Expand Down
11 changes: 7 additions & 4 deletions fortiadc/resource_fortiadc_loadbalance_real_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,26 @@ func resourceFortiadcLoadbalanceRealServer() *schema.Resource {
Read: resourceFortiadcLoadbalanceRealServerRead,
Update: resourceFortiadcLoadbalanceRealServerUpdate,
Delete: resourceFortiadcLoadbalanceRealServerDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"address": &schema.Schema{
"address": {
Type: schema.TypeString,
Required: true,
},
"address6": &schema.Schema{
"address6": {
Type: schema.TypeString,
Optional: true,
Default: "::",
},
"status": &schema.Schema{
"status": {
Type: schema.TypeString,
Optional: true,
Default: "enable",
Expand Down
47 changes: 25 additions & 22 deletions fortiadc/resource_fortiadc_loadbalance_virtual_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,55 @@ func resourceFortiadcLoadbalanceVirtualServer() *schema.Resource {
Read: resourceFortiadcLoadbalanceVirtualServerRead,
Update: resourceFortiadcLoadbalanceVirtualServerUpdate,
Delete: resourceFortiadcLoadbalanceVirtualServerDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"status": &schema.Schema{
"status": {
Type: schema.TypeString,
Optional: true,
Default: "enable",
},
"type": &schema.Schema{
"type": {
Type: schema.TypeString,
Optional: true,
Default: "l4-load-balance",
},
"address_type": &schema.Schema{
"address_type": {
Type: schema.TypeString,
Optional: true,
Default: "ipv4",
},
"address": &schema.Schema{
"address": {
Type: schema.TypeString,
Required: true,
},
"packet_forward_method": &schema.Schema{
"packet_forward_method": {
Type: schema.TypeString,
Optional: true,
Default: "NAT",
},
"source_pool_list": &schema.Schema{
"source_pool_list": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"port": &schema.Schema{
"port": {
Type: schema.TypeInt,
Required: true,
},
"connection_limit": &schema.Schema{
"connection_limit": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
},
"content_routing_enable": &schema.Schema{
"content_routing_enable": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Expand All @@ -71,7 +74,7 @@ func resourceFortiadcLoadbalanceVirtualServer() *schema.Resource {
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"content_rewriting_enable": &schema.Schema{
"content_rewriting_enable": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Expand All @@ -81,56 +84,56 @@ func resourceFortiadcLoadbalanceVirtualServer() *schema.Resource {
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"connection_rate_limit": &schema.Schema{
"connection_rate_limit": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
},
"error_page": &schema.Schema{
"error_page": {
Type: schema.TypeString,
Optional: true,
Default: "",
},
"error_msg": &schema.Schema{
"error_msg": {
Type: schema.TypeString,
Optional: true,
Default: "Server-unavailable!",
},
"interface": &schema.Schema{
"interface": {
Type: schema.TypeString,
Optional: true,
Default: "port1",
},
"profile": &schema.Schema{
"profile": {
Type: schema.TypeString,
Optional: true,
Default: "LB_PROF_TCP",
},
"method": &schema.Schema{
"method": {
Type: schema.TypeString,
Optional: true,
Default: "LB_METHOD_ROUND_ROBIN",
},
"pool": &schema.Schema{
"pool": {
Type: schema.TypeString,
Required: true,
},
"client_ssl_profile": &schema.Schema{
"client_ssl_profile": {
Type: schema.TypeString,
Optional: true,
Default: "",
},
"http_to_https": &schema.Schema{
"http_to_https": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"persistence": &schema.Schema{
"persistence": {
Type: schema.TypeString,
Optional: true,
Default: "",
},
"traffic_log": &schema.Schema{
"traffic_log": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Expand Down

0 comments on commit 865fb0d

Please sign in to comment.