Skip to content
This repository was archived by the owner on Mar 1, 2023. It is now read-only.

Commit 461cf06

Browse files
committed
loadbalancer, lblistener, lbpool and lb memeber resources added
1 parent cdd5916 commit 461cf06

20 files changed

+1907
-12
lines changed

examples/lblistener/main.tf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
provider gcore {
2+
user_name = "[email protected]"
3+
password = "testtest"
4+
gcore_platform = "http://api.stg-45.staging.gcdn.co"
5+
gcore_api = "http://10.100.179.92:33081"
6+
}
7+
8+
resource "gcore_loadbalancer" "lb" {
9+
project_id = 1
10+
region_id = 1
11+
name = "test"
12+
flavor = "lb1-1-2"
13+
listeners {
14+
name = "test"
15+
protocol = "HTTP"
16+
protocol_port = 80
17+
}
18+
}
19+
20+
resource "gcore_lblistener" "listener" {
21+
project_id = 1
22+
region_id = 1
23+
name = "test"
24+
protocol = "TCP"
25+
protocol_port = 36621
26+
loadbalancer_id = gcore_loadbalancer.lb.id
27+
}

examples/lbmember/main.tf

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
provider gcore {
2+
user_name = "[email protected]"
3+
password = "testtest"
4+
gcore_platform = "http://api.stg-45.staging.gcdn.co"
5+
gcore_api = "http://10.100.179.92:33081"
6+
}
7+
8+
resource "gcore_loadbalancer" "lb" {
9+
project_id = 1
10+
region_id = 1
11+
name = "test1"
12+
flavor = "lb1-1-2"
13+
listeners {
14+
name = "test"
15+
protocol = "HTTP"
16+
protocol_port = 80
17+
}
18+
}
19+
20+
resource "gcore_lbpool" "pl" {
21+
project_id = 1
22+
region_id = 1
23+
name = "test_pool1"
24+
protocol = "HTTP"
25+
lb_algorithm = "LEAST_CONNECTIONS"
26+
loadbalancer_id = gcore_loadbalancer.lb.id
27+
listener_id = gcore_loadbalancer.lb.listeners.0.id
28+
health_monitor {
29+
type = "PING"
30+
delay = 60
31+
max_retries = 5
32+
timeout = 10
33+
}
34+
session_persistence {
35+
type = "APP_COOKIE"
36+
cookie_name = "test_new_cookie"
37+
}
38+
}
39+
40+
resource "gcore_lbmember" "lbm" {
41+
project_id = 1
42+
region_id = 1
43+
pool_id = gcore_lbpool.pl.id
44+
address = "10.10.2.15"
45+
protocol_port = 8081
46+
weight = 5
47+
}
48+
49+

examples/loadbalancer/main.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
provider gcore {
2+
user_name = "[email protected]"
3+
password = "testtest"
4+
gcore_platform = "http://api.stg-45.staging.gcdn.co"
5+
gcore_api = "http://10.100.179.92:33081"
6+
}
7+
8+
resource "gcore_loadbalancer" "lb" {
9+
project_id = 1
10+
region_id = 1
11+
name = "test"
12+
flavor = "lb1-1-2"
13+
listeners {
14+
name = "test"
15+
protocol = "HTTP"
16+
protocol_port = 80
17+
}
18+
}

examples/lpool/main.tf

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
provider gcore {
2+
user_name = "[email protected]"
3+
password = "testtest"
4+
gcore_platform = "http://api.stg-45.staging.gcdn.co"
5+
gcore_api = "http://10.100.179.92:33081"
6+
}
7+
8+
resource "gcore_loadbalancer" "lb" {
9+
project_id = 1
10+
region_id = 1
11+
name = "test1"
12+
flavor = "lb1-1-2"
13+
listeners {
14+
name = "test"
15+
protocol = "HTTP"
16+
protocol_port = 80
17+
}
18+
}
19+
20+
resource "gcore_lbpool" "pl" {
21+
project_id = 1
22+
region_id = 1
23+
name = "test_pool1"
24+
protocol = "HTTP"
25+
lb_algorithm = "LEAST_CONNECTIONS"
26+
loadbalancer_id = gcore_loadbalancer.lb.id
27+
listener_id = gcore_loadbalancer.lb.listeners.0.id
28+
health_monitor {
29+
type = "PING"
30+
delay = 60
31+
max_retries = 5
32+
timeout = 10
33+
}
34+
session_persistence {
35+
type = "APP_COOKIE"
36+
cookie_name = "test_new_cookie"
37+
}
38+
}

examples/versions/version.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ terraform {
33
required_providers {
44
gcore = {
55
source = "local.gcorelabs.com/repo/gcore"
6-
version = "~>0.0.8"
6+
version = "~>0.0.9"
77
}
88
}
99
}

gcore/provider.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ func Provider() *schema.Provider {
4444
"gcore_keypair": resourceKeypair(),
4545
"gcore_reservedfixedip": resourceReservedFixedIP(),
4646
"gcore_floatingip": resourceFloatingIP(),
47+
"gcore_loadbalancer": resourceLoadBalancer(),
48+
"gcore_lblistener": resourceLbListener(),
49+
"gcore_lbpool": resourceLBPool(),
50+
"gcore_lbmember": resourceLBMember(),
4751
},
4852
ConfigureContextFunc: providerConfigure,
4953
}

gcore/provider_test.go

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ import (
1515
)
1616

1717
var (
18-
GCORE_USERNAME = os.Getenv("GCORE_USERNAME")
19-
GCORE_PASSWORD = os.Getenv("GCORE_PASSWORD")
20-
GCORE_IMAGE = os.Getenv("GCORE_IMAGE")
21-
GCORE_SECGROUP = os.Getenv("GCORE_SECGROUP")
22-
GCORE_EXT_NET = os.Getenv("GCORE_EXT_NET")
23-
GCORE_PRIV_NET = os.Getenv("GCORE_PRIV_NET")
24-
GCORE_PRIV_SUBNET = os.Getenv("GCORE_PRIV_SUBNET")
18+
GCORE_USERNAME = os.Getenv("GCORE_USERNAME")
19+
GCORE_PASSWORD = os.Getenv("GCORE_PASSWORD")
20+
GCORE_IMAGE = os.Getenv("GCORE_IMAGE")
21+
GCORE_SECGROUP = os.Getenv("GCORE_SECGROUP")
22+
GCORE_EXT_NET = os.Getenv("GCORE_EXT_NET")
23+
GCORE_PRIV_NET = os.Getenv("GCORE_PRIV_NET")
24+
GCORE_PRIV_SUBNET = os.Getenv("GCORE_PRIV_SUBNET")
25+
GCORE_LB_ID = os.Getenv("GCORE_LB_ID")
26+
GCORE_LBLISTENER_ID = os.Getenv("GCORE_LBLISTENER_ID")
27+
GCORE_LBPOOL_ID = os.Getenv("GCORE_LBPOOL_ID")
2528
)
2629

2730
var testAccProvider *schema.Provider
@@ -56,6 +59,46 @@ func testAccPreCheck(t *testing.T) {
5659
checkNameAndID("REGION", t)
5760
}
5861

62+
func testAccPreCheckLBListener(t *testing.T) {
63+
Vars := map[string]interface{}{
64+
"GCORE_USERNAME": GCORE_USERNAME,
65+
"GCORE_PASSWORD": GCORE_PASSWORD,
66+
"GCORE_LB_ID": GCORE_LB_ID,
67+
}
68+
for k, v := range Vars {
69+
if v == "" {
70+
t.Fatalf("'%s' must be set for acceptance test", k)
71+
}
72+
}
73+
}
74+
75+
func testAccPreCheckLBPool(t *testing.T) {
76+
Vars := map[string]interface{}{
77+
"GCORE_USERNAME": GCORE_USERNAME,
78+
"GCORE_PASSWORD": GCORE_PASSWORD,
79+
"GCORE_LB_ID": GCORE_LB_ID,
80+
"GCORE_LBLISTENER_ID": GCORE_LBLISTENER_ID,
81+
}
82+
for k, v := range Vars {
83+
if v == "" {
84+
t.Fatalf("'%s' must be set for acceptance test", k)
85+
}
86+
}
87+
}
88+
89+
func testAccPreCheckLBMember(t *testing.T) {
90+
Vars := map[string]interface{}{
91+
"GCORE_USERNAME": GCORE_USERNAME,
92+
"GCORE_PASSWORD": GCORE_PASSWORD,
93+
"GCORE_LBPOOL_ID": GCORE_LBPOOL_ID,
94+
}
95+
for k, v := range Vars {
96+
if v == "" {
97+
t.Fatalf("'%s' must be set for acceptance test", k)
98+
}
99+
}
100+
}
101+
59102
func testAccPreCheckRouter(t *testing.T) {
60103
Vars := map[string]interface{}{
61104
"GCORE_EXT_NET": GCORE_EXT_NET,

gcore/resource_gcore_floatingip.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func resourceFloatingIPUpdate(ctx context.Context, d *schema.ResourceData, m int
198198
return diag.FromErr(err)
199199
}
200200

201-
if d.HasChange("fixed_ip_address") || d.HasChange("port_id") {
201+
if d.HasChanges("fixed_ip_address", "port_id") {
202202
oldFixedIP, newFixedIP := d.GetChange("fixed_ip_address")
203203
oldPortID, newPortID := d.GetChange("port_id")
204204
if oldPortID.(string) != "" || oldFixedIP.(string) != "" {

0 commit comments

Comments
 (0)