Skip to content

Commit

Permalink
Merge pull request #1 from yanndegat/ec_http_pr_review
Browse files Browse the repository at this point in the history
Ec http pr review
  • Loading branch information
eliecharra authored Jun 14, 2018
2 parents 845a891 + af137a6 commit 74df441
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 273 deletions.
22 changes: 22 additions & 0 deletions ovh/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ func testAccPreCheck(t *testing.T) {
t.Fatal("OVH_ZONE must be set for acceptance tests")
}

v = os.Getenv("OVH_IPLB_SERVICE")
if v == "" {
t.Fatal("OVH_IPLB_SERVICE must be set for acceptance tests")
}

if testAccOVHClient == nil {
config := Config{
Endpoint: os.Getenv("OVH_ENDPOINT"),
Expand Down Expand Up @@ -122,3 +127,20 @@ func testAccCheckPublicCloudExists(t *testing.T) {
t.Logf("Read Cloud Project %s -> status: '%s', desc: '%s'", endpoint, r.Status, r.Description)

}

func testAccCheckIpLoadbalancingExists(t *testing.T) {
type iplbResponse struct {
ServiceName string `json:"serviceName"`
State string `json:"state"`
}

r := iplbResponse{}

endpoint := fmt.Sprintf("/ipLoadbalancing/%s", os.Getenv("OVH_IPLB_SERVICE"))

err := testAccOVHClient.Get(endpoint, &r)
if err != nil {
t.Fatalf("Error: %q\n", err)
}
t.Logf("Read IPLB service %s -> state: '%s', serviceName: '%s'", endpoint, r.State, r.ServiceName)
}
38 changes: 19 additions & 19 deletions ovh/resource_ovh_iploadbalancing_http_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,6 @@ import (
"github.com/hashicorp/terraform/helper/schema"
)

// IPLoadbalancingRouteHTTPAction Action triggered when all rules match
type IPLoadbalancingRouteHTTPAction struct {
Target string `json:"target,omitempty"` // Farm ID for "farm" action type or URL template for "redirect" action. You may use ${uri}, ${protocol}, ${host}, ${port} and ${path} variables in redirect target
Status int `json:"status,omitempty"` // HTTP status code for "redirect" and "reject" actions
Type string `json:"type,omitempty"` // Action to trigger if all the rules of this route matches
}

//IPLoadbalancingRouteHTTP HTTP Route
type IPLoadbalancingRouteHTTP struct {
Status string `json:"status,omitempty"` //Route status. Routes in "ok" state are ready to operate
Weight int `json:"weight,omitempty"` //Route priority ([0..255]). 0 if null. Highest priority routes are evaluated first. Only the first matching route will trigger an action
Action *IPLoadbalancingRouteHTTPAction `json:"action,omitempty"` //Action triggered when all rules match
RouteID int `json:"routeId,omitempty"` //Id of your route
DisplayName string `json:"displayName,omitempty"` //Human readable name for your route, this field is for you
FrontendID int `json:"frontendId,omitempty"` //Route traffic for this frontend
}

func resourceIPLoadbalancingRouteHTTP() *schema.Resource {
return &schema.Resource{
Create: resourceIPLoadbalancingRouteHTTPCreate,
Expand Down Expand Up @@ -74,6 +57,23 @@ func resourceIPLoadbalancingRouteHTTP() *schema.Resource {
}
}

// IPLoadbalancingRouteHTTPAction Action triggered when all rules match
type IPLoadbalancingRouteHTTPAction struct {
Target string `json:"target,omitempty"` // Farm ID for "farm" action type or URL template for "redirect" action. You may use ${uri}, ${protocol}, ${host}, ${port} and ${path} variables in redirect target
Status int `json:"status,omitempty"` // HTTP status code for "redirect" and "reject" actions
Type string `json:"type,omitempty"` // Action to trigger if all the rules of this route matches
}

//IPLoadbalancingRouteHTTP HTTP Route
type IPLoadbalancingRouteHTTP struct {
Status string `json:"status,omitempty"` //Route status. Routes in "ok" state are ready to operate
Weight int `json:"weight,omitempty"` //Route priority ([0..255]). 0 if null. Highest priority routes are evaluated first. Only the first matching route will trigger an action
Action *IPLoadbalancingRouteHTTPAction `json:"action,omitempty"` //Action triggered when all rules match
RouteID int `json:"routeId,omitempty"` //Id of your route
DisplayName string `json:"displayName,omitempty"` //Human readable name for your route, this field is for you
FrontendID int `json:"frontendId,omitempty"` //Route traffic for this frontend
}

func resourceIPLoadbalancingRouteHTTPCreate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

Expand Down Expand Up @@ -102,7 +102,7 @@ func resourceIPLoadbalancingRouteHTTPCreate(d *schema.ResourceData, meta interfa

d.SetId(fmt.Sprintf("%d", resp.RouteID))

return nil
return resourceIPLoadbalancingRouteHTTPRead(d, meta)
}

func resourceIPLoadbalancingRouteHTTPRead(d *schema.ResourceData, meta interface{}) error {
Expand Down Expand Up @@ -148,7 +148,7 @@ func resourceIPLoadbalancingRouteHTTPUpdate(d *schema.ResourceData, meta interfa
return fmt.Errorf("calling %s:\n\t %s", endpoint, err.Error())
}

return nil
return resourceIPLoadbalancingRouteHTTPRead(d, meta)
}

func resourceIPLoadbalancingRouteHTTPDelete(d *schema.ResourceData, meta interface{}) error {
Expand Down
28 changes: 14 additions & 14 deletions ovh/resource_ovh_iploadbalancing_http_route_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@ import (
"github.com/hashicorp/terraform/helper/schema"
)

//IPLoadbalancingRouteHTTPRule HTTP Route Rule
type IPLoadbalancingRouteHTTPRule struct {
RuleID int `json:"ruleId,omitempty"` //Id of your rule
RouteID int `json:"routeId,omitempty"` //Id of your route
DisplayName string `json:"displayName,omitempty"` //Human readable name for your rule
Field string `json:"field,omitempty"` //Name of the field to match like "protocol" or "host". See "/ipLoadbalancing/{serviceName}/availableRouteRules" for a list of available rules
Match string `json:"match,omitempty"` //Matching operator. Not all operators are available for all fields. See "/ipLoadbalancing/{serviceName}/availableRouteRules"
Negate bool `json:"negate,omitempty"` //Invert the matching operator effect
Pattern string `json:"pattern,omitempty"` //Value to match against this match. Interpretation if this field depends on the match and field
SubField string `json:"subField,omitempty"` //Name of sub-field, if applicable. This may be a Cookie or Header name for instance
}

func resourceIPLoadbalancingRouteHTTPRule() *schema.Resource {
return &schema.Resource{
Create: resourceIPLoadbalancingRouteHTTPRuleCreate,
Expand Down Expand Up @@ -71,6 +59,18 @@ func resourceIPLoadbalancingRouteHTTPRule() *schema.Resource {
}
}

//IPLoadbalancingRouteHTTPRule HTTP Route Rule
type IPLoadbalancingRouteHTTPRule struct {
RuleID int `json:"ruleId,omitempty"` //Id of your rule
RouteID int `json:"routeId,omitempty"` //Id of your route
DisplayName string `json:"displayName,omitempty"` //Human readable name for your rule
Field string `json:"field,omitempty"` //Name of the field to match like "protocol" or "host". See "/ipLoadbalancing/{serviceName}/availableRouteRules" for a list of available rules
Match string `json:"match,omitempty"` //Matching operator. Not all operators are available for all fields. See "/ipLoadbalancing/{serviceName}/availableRouteRules"
Negate bool `json:"negate,omitempty"` //Invert the matching operator effect
Pattern string `json:"pattern,omitempty"` //Value to match against this match. Interpretation if this field depends on the match and field
SubField string `json:"subField,omitempty"` //Name of sub-field, if applicable. This may be a Cookie or Header name for instance
}

func resourceIPLoadbalancingRouteHTTPRuleCreate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

Expand All @@ -95,7 +95,7 @@ func resourceIPLoadbalancingRouteHTTPRuleCreate(d *schema.ResourceData, meta int

d.SetId(fmt.Sprintf("%d", resp.RuleID))

return nil
return resourceIPLoadbalancingRouteHTTPRuleRead(d, meta)
}

func resourceIPLoadbalancingRouteHTTPRuleRead(d *schema.ResourceData, meta interface{}) error {
Expand Down Expand Up @@ -134,7 +134,7 @@ func resourceIPLoadbalancingRouteHTTPRuleUpdate(d *schema.ResourceData, meta int
return fmt.Errorf("calling %s:\n\t %s", endpoint, err.Error())
}

return nil
return resourceIPLoadbalancingRouteHTTPRuleRead(d, meta)
}

func resourceIPLoadbalancingRouteHTTPRuleDelete(d *schema.ResourceData, meta interface{}) error {
Expand Down
Loading

0 comments on commit 74df441

Please sign in to comment.