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

Commit 098330a

Browse files
intiluha0ndi
authored andcommitted
GCLOUD2-3228 health monitor expected_codes support
1 parent 3abff57 commit 098330a

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

gcore/data_source_gcore_lbpool.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ func dataSourceLBPool() *schema.Resource {
109109
Type: schema.TypeString,
110110
Computed: true,
111111
},
112+
"expected_codes": &schema.Schema{
113+
Type: schema.TypeString,
114+
Computed: true,
115+
},
112116
},
113117
},
114118
},
@@ -203,6 +207,7 @@ func dataSourceLBPoolRead(ctx context.Context, d *schema.ResourceData, m interfa
203207
"max_retries": lb.HealthMonitor.MaxRetries,
204208
"max_retries_down": lb.HealthMonitor.MaxRetriesDown,
205209
"url_path": lb.HealthMonitor.URLPath,
210+
"expected_codes": lb.HealthMonitor.ExpectedCodes,
206211
}
207212
if lb.HealthMonitor.HTTPMethod != nil {
208213
healthMonitor["http_method"] = lb.HealthMonitor.HTTPMethod.String()

gcore/data_source_gcore_lbpool_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func TestAccLBPoolDataSource(t *testing.T) {
7272
MaxRetriesDown: 10,
7373
HTTPMethod: types.HTTPMethodPointer(types.HTTPMethodGET),
7474
URLPath: "/",
75+
ExpectedCodes: "123,321",
7576
},
7677
}
7778
res, err := lbpools.Create(clientPools, optsPool).Extract()

gcore/provider_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,14 @@ func testAccPreCheckInstance(t *testing.T) {
143143
func checkNameAndID(resourceType string, t *testing.T) {
144144
// resourceType is a word in capital letters
145145
keyID := fmt.Sprintf("TEST_%s_ID", resourceType)
146-
keyNane := fmt.Sprintf("TEST_%s_NAME", resourceType)
146+
keyName := fmt.Sprintf("TEST_%s_NAME", resourceType)
147147
_, haveID := os.LookupEnv(keyID)
148-
_, haveName := os.LookupEnv(keyNane)
148+
_, haveName := os.LookupEnv(keyName)
149149
if !haveID && !haveName {
150-
t.Fatalf("%s or %s must be set for acceptance tests", keyID, keyNane)
150+
t.Fatalf("%s or %s must be set for acceptance tests", keyID, keyName)
151151
}
152152
if haveID && haveName {
153-
t.Fatalf("Use only one from environment variables: %s or %s", keyID, keyNane)
153+
t.Fatalf("Use only one from environment variables: %s or %s", keyID, keyName)
154154
}
155155
}
156156

@@ -165,11 +165,11 @@ func projectInfo() string {
165165
func objectInfo(resourceType string) string {
166166
// resourceType is a word in capital letters
167167
keyID := fmt.Sprintf("TEST_%s_ID", resourceType)
168-
keyNane := fmt.Sprintf("TEST_%s_NAME", resourceType)
168+
keyName := fmt.Sprintf("TEST_%s_NAME", resourceType)
169169
if regionID, exists := os.LookupEnv(keyID); exists {
170170
return fmt.Sprintf(`%s_id = %s`, strings.ToLower(resourceType), regionID)
171171
}
172-
return fmt.Sprintf(`%s_name = "%s"`, strings.ToLower(resourceType), os.Getenv(keyNane))
172+
return fmt.Sprintf(`%s_name = "%s"`, strings.ToLower(resourceType), os.Getenv(keyName))
173173
}
174174

175175
func CreateTestClient(provider *gcorecloud.ProviderClient, endpoint, version string) (*gcorecloud.ServiceClient, error) {

gcore/resource_gcore_lbpool.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ func resourceLBPool() *schema.Resource {
159159
Optional: true,
160160
Computed: true,
161161
},
162+
"expected_codes": &schema.Schema{
163+
Type: schema.TypeString,
164+
Optional: true,
165+
Computed: true,
166+
},
162167
},
163168
},
164169
},
@@ -288,6 +293,7 @@ func resourceLBPoolRead(ctx context.Context, d *schema.ResourceData, m interface
288293
"max_retries": lb.HealthMonitor.MaxRetries,
289294
"max_retries_down": lb.HealthMonitor.MaxRetriesDown,
290295
"url_path": lb.HealthMonitor.URLPath,
296+
"expected_codes": lb.HealthMonitor.ExpectedCodes,
291297
}
292298
if lb.HealthMonitor.HTTPMethod != nil {
293299
healthMonitor["http_method"] = lb.HealthMonitor.HTTPMethod.String()

gcore/utils.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,14 @@ func extractHealthMonitorMap(d *schema.ResourceData) *lbpools.CreateHealthMonito
463463
healthOpts.URLPath = urlPath
464464
}
465465

466-
if hm["id"].(string) != "" {
467-
healthOpts.ID = hm["id"].(string)
466+
expectedCodes := hm["expected_codes"].(string)
467+
if expectedCodes != "" {
468+
healthOpts.ExpectedCodes = expectedCodes
469+
}
470+
471+
id := hm["id"].(string)
472+
if id != "" {
473+
healthOpts.ID = id
468474
}
469475
}
470476
return healthOpts

0 commit comments

Comments
 (0)