Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow more empty objects and fix bugs #134

Merged
merged 5 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions docs/resources/gvc.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,10 @@ Optional:

### `load_balancer`

Required:

- **dedicated** (Boolean) Creates a dedicated load balancer in each location and enables additional Domain features: custom ports, protocols and wildcard hostnames. Charges apply for each location.

Optional:

- **dedicated** (Boolean) Creates a dedicated load balancer in each location and enables additional Domain features: custom ports, protocols and wildcard hostnames. Charges apply for each location.
- **trusted_proxies** (Int) Controls the address used for request logging and for setting the X-Envoy-External-Address header. If set to 1, then the last address in an existing X-Forwarded-For header will be used in place of the source client IP address. If set to 2, then the second to last address in an existing X-Forwarded-For header will be used in place of the source client IP address. If the XFF header does not have at least two addresses or does not exist then the source client IP address will be used instead.

- **redirect** (Block List, Max: 1) ([see below](#nestedblock--load_balancer--redirect)).

<a id="nestedblock--load_balancer--redirect"></a>
Expand Down
13 changes: 2 additions & 11 deletions internal/provider/client/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,8 @@ func (c *Client) UpdateDomainRoute(domainName string, domainPort int, route *Dom
(*(*domain.Spec.Ports)[pIndex].Routes)[rIndex].Port = route.Port
}

if route.HostPrefix == nil || *route.HostPrefix == "" {
(*(*domain.Spec.Ports)[pIndex].Routes)[rIndex].HostPrefix = nil
} else {
(*(*domain.Spec.Ports)[pIndex].Routes)[rIndex].HostPrefix = route.HostPrefix
}

if route.Headers == nil || route.Headers.Request == nil || route.Headers.Request.Set == nil {
(*(*domain.Spec.Ports)[pIndex].Routes)[rIndex].Headers = nil
} else {
(*(*domain.Spec.Ports)[pIndex].Routes)[rIndex].Headers = route.Headers
}
(*(*domain.Spec.Ports)[pIndex].Routes)[rIndex].HostPrefix = route.HostPrefix
(*(*domain.Spec.Ports)[pIndex].Routes)[rIndex].Headers = route.Headers

// Update resource
domain.SpecReplace = DeepCopy(domain.Spec).(*DomainSpec)
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resource_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func resourceDomain() *schema.Resource {
},
"spec": {
Type: schema.TypeList,
Description: "Domain specificiation.",
Description: "Domain specification.",
Required: true,
MaxItems: 1,
Elem: &schema.Resource{
Expand Down
39 changes: 32 additions & 7 deletions internal/provider/resource_domain_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,19 @@ func resourceDomainRoute() *schema.Resource {
Optional: true,
Elem: StringSchema(),
},
"_sentinel": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
},
},
},
"_sentinel": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
},
},
},
Expand Down Expand Up @@ -176,19 +186,30 @@ func importStateDomainRoute(ctx context.Context, d *schema.ResourceData, m inter
}

// Set values and Id
d.Set("domain_link", domainLink)
d.Set("domain_port", domainPort)
if err := d.Set("domain_link", domainLink); err != nil {
return nil, err
}

if err := d.Set("domain_port", domainPort); err != nil {
return nil, err
}

var routeIdentifier string

if prefix != nil {
routeIdentifier = *prefix
d.Set("prefix", *prefix)

if err := d.Set("prefix", *prefix); err != nil {
return nil, err
}
}

if regex != nil {
routeIdentifier = *regex
d.Set("regex", *regex)

if err := d.Set("regex", *regex); err != nil {
return nil, err
}
}

d.SetId(fmt.Sprintf("%s_%d_%s", domainLink, domainPort, routeIdentifier))
Expand Down Expand Up @@ -285,7 +306,7 @@ func resourceDomainRouteUpdate(ctx context.Context, d *schema.ResourceData, m in
ReplacePrefix: GetString(d.Get("replace_prefix")),
WorkloadLink: GetString(d.Get("workload_link")),
Port: GetInt(d.Get("port")),
HostPrefix: GetString(d.Get(("host_prefix"))),
HostPrefix: GetString(d.Get("host_prefix")),
}

if d.Get("prefix") != nil {
Expand Down Expand Up @@ -449,7 +470,9 @@ func flattenDomainRouteHeaders(headers *client.DomainRouteHeaders) []interface{}
return nil
}

spec := map[string]interface{}{}
spec := map[string]interface{}{
"_sentinel": true,
}

if headers.Request != nil {
spec["request"] = flattenDomainHeaderOperation(headers.Request)
Expand All @@ -466,7 +489,9 @@ func flattenDomainHeaderOperation(request *client.DomainHeaderOperation) []inter
return nil
}

spec := map[string]interface{}{}
spec := map[string]interface{}{
"_sentinel": true,
}

if request.Set != nil {
spec["set"] = *request.Set
Expand Down
8 changes: 5 additions & 3 deletions internal/provider/resource_domain_route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ func TestControlPlane_FlattenDomainRouteHeaders(t *testing.T) {
flattenedHeaders := flattenDomainRouteHeaders(expectedHeaders)

if diff := deep.Equal(expectedFlatten, flattenedHeaders); diff != nil {
t.Errorf("Mk8s Firewall was not flattened correctly. Diff: %s", diff)
t.Errorf("Domain Route Headers were not flattened correctly. Diff: %s", diff)
}
}

Expand Down Expand Up @@ -584,7 +584,8 @@ func generateTestDomainHeaderOperation() (*client.DomainHeaderOperation, *client
func generateFlatTestDomainRouteHeaders(request []interface{}) []interface{} {

spec := map[string]interface{}{
"request": request,
"request": request,
"_sentinel": true,
}

return []interface{}{
Expand All @@ -595,7 +596,8 @@ func generateFlatTestDomainRouteHeaders(request []interface{}) []interface{} {
func generateFlatTestDomainHeaderOperation(set map[string]interface{}) []interface{} {

spec := map[string]interface{}{
"set": set,
"set": set,
"_sentinel": true,
}

return []interface{}{
Expand Down
32 changes: 25 additions & 7 deletions internal/provider/resource_gvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func GvcSchema() map[string]*schema.Schema {
"dedicated": {
Type: schema.TypeBool,
Description: "Creates a dedicated load balancer in each location and enables additional Domain features: custom ports, protocols and wildcard hostnames. Charges apply for each location.",
Required: true,
Optional: true,
},
"trusted_proxies": {
Type: schema.TypeInt,
Expand All @@ -156,9 +156,19 @@ func GvcSchema() map[string]*schema.Schema {
Description: "Specify the redirect url for any 500 level status code.",
Optional: true,
},
"_sentinel": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
},
},
},
"_sentinel": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
},
},
},
Expand Down Expand Up @@ -453,8 +463,10 @@ func buildLoadBalancer(specs []interface{}) *client.LoadBalancer {
}

spec := specs[0].(map[string]interface{})
output := client.LoadBalancer{
Dedicated: GetBool(spec["dedicated"].(bool)),
output := client.LoadBalancer{}

if spec["dedicated"] != nil {
output.Dedicated = GetBool(spec["dedicated"].(bool))
}

if spec["trusted_proxies"] != nil {
Expand Down Expand Up @@ -570,8 +582,10 @@ func flattenLoadBalancer(gvcSpec *client.LoadBalancer) []interface{} {
return nil
}

loadBalancer := map[string]interface{}{
"dedicated": *gvcSpec.Dedicated,
loadBalancer := map[string]interface{}{}

if gvcSpec.Dedicated != nil {
loadBalancer["dedicated"] = *gvcSpec.Dedicated
}

if gvcSpec.TrustedProxies != nil {
Expand All @@ -593,7 +607,9 @@ func flattenRedirect(spec *client.Redirect) []interface{} {
return nil
}

redirect := map[string]interface{}{}
redirect := map[string]interface{}{
"_sentinel": true,
}

if spec.Class != nil {
redirect["class"] = flattenRedirectClass(spec.Class)
Expand All @@ -610,7 +626,9 @@ func flattenRedirectClass(spec *client.RedirectClass) []interface{} {
return nil
}

class := map[string]interface{}{}
class := map[string]interface{}{
"_sentinel": true,
}

if spec.Status5XX != nil {
class["status_5xx"] = *spec.Status5XX
Expand Down
Loading