Skip to content

Commit

Permalink
Allow more empty objects and fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
MajidAbuRmila committed Nov 5, 2024
1 parent 10b809e commit 63c1d6f
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 49 deletions.
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
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
33 changes: 25 additions & 8 deletions internal/provider/resource_identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func resourceIdentity() *schema.Resource {
"agent_link": {
Type: schema.TypeString,
Description: "Full link to referenced Agent.",
Required: true,
Optional: true,
ValidateFunc: LinkValidator,
},
"fqdn": {
Expand All @@ -106,7 +106,7 @@ func resourceIdentity() *schema.Resource {
"ports": {
Type: schema.TypeSet,
Description: "Ports to expose.",
Optional: true,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
Expand Down Expand Up @@ -238,6 +238,11 @@ func resourceIdentity() *schema.Resource {
Type: schema.TypeString,
},
},
"_sentinel": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
},
},
},
Expand Down Expand Up @@ -277,6 +282,11 @@ func resourceIdentity() *schema.Resource {
Type: schema.TypeString,
},
},
"_sentinel": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
},
},
},
Expand Down Expand Up @@ -452,7 +462,10 @@ func importStateIdentity(ctx context.Context, d *schema.ResourceData, meta inter
return nil, fmt.Errorf("unexpected format of ID (%s), expected ID syntax 'gvc:identity'. Example: 'terraform import cpln_identity.RESOURCE_NAME GVC_NAME:IDENTITY_NAME'", d.Id())
}

d.Set("gvc", parts[0])
if err := d.Set("gvc", parts[0]); err != nil {
return nil, err
}

d.SetId(parts[1])

return []*schema.ResourceData{d}, nil
Expand Down Expand Up @@ -1020,9 +1033,9 @@ func flattenAwsIdentity(awsIdentity *client.AwsIdentity) []interface{} {

if awsIdentity != nil {

output := make(map[string]interface{})

output["cloud_account_link"] = *awsIdentity.CloudAccountLink
output := map[string]interface{}{
"cloud_account_link": *awsIdentity.CloudAccountLink,
}

if awsIdentity.PolicyRefs != nil && len(*awsIdentity.PolicyRefs) > 0 {

Expand Down Expand Up @@ -1060,7 +1073,9 @@ func flattenAzureIdentity(azureIdentity *client.AzureIdentity) []interface{} {

for _, r := range *azureIdentity.RoleAssignments {

ra := make(map[string]interface{})
ra := map[string]interface{}{
"_sentinel": true,
}

if r.Scope != nil {
ra["scope"] = *r.Scope
Expand Down Expand Up @@ -1113,7 +1128,9 @@ func flattenGcpIdentity(gcpIdentity *client.GcpIdentity) []interface{} {

for _, b := range *gcpIdentity.Bindings {

bs := make(map[string]interface{})
bs := map[string]interface{}{
"_sentinel": true,
}

if b.Resource != nil {
bs["resource"] = *b.Resource
Expand Down
13 changes: 10 additions & 3 deletions internal/provider/resource_org.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func orgSchema() map[string]*schema.Schema {
"enabled": {
Type: schema.TypeBool,
Description: "Indicates whether threat detection should be forwarded or not.",
Optional: true,
Required: true,
},
"minimum_severity": {
Type: schema.TypeString,
Expand All @@ -190,7 +190,7 @@ func orgSchema() map[string]*schema.Schema {
"host": {
Type: schema.TypeString,
Description: "The hostname to send syslog messages to.",
Optional: true,
Required: true,
},
"port": {
Type: schema.TypeInt,
Expand All @@ -203,6 +203,11 @@ func orgSchema() map[string]*schema.Schema {
},
},
},
"_sentinel": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
},
},
},
Expand Down Expand Up @@ -561,7 +566,9 @@ func flattenOrgSecurity(spec *client.OrgSecurity) []interface{} {
return nil
}

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

if spec.ThreatDetection != nil {
output["threat_detection"] = flattenOrgThreatDetection(spec.ThreatDetection)
Expand Down
9 changes: 8 additions & 1 deletion internal/provider/resource_org_logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ func resourceOrgLogging() *schema.Resource {
},
},
},
"_sentinel": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
},
},
},
Expand Down Expand Up @@ -1030,7 +1035,9 @@ func flattenElasticLogging(logs []client.ElasticLogging) []interface{} {

for l, log := range logs {

result := make(map[string]interface{})
result := map[string]interface{}{
"_sentinel": true,
}

if log.AWS != nil {
result["aws"] = flattenAWSLogging(log.AWS)
Expand Down
Loading

0 comments on commit 63c1d6f

Please sign in to comment.