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

Add Cloud WAF Instance response computed properties #77

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
76 changes: 76 additions & 0 deletions provider/resource_corp_cloudwaf_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,54 @@ func resourceCorpCloudWAFInstance() *schema.Resource {
},
},
},
"deployment": {
Type: schema.TypeList, // use TypeList to workaround SDK TypeMap limitation with only string value support: https://github.com/hashicorp/terraform-plugin-sdk/issues/62
Description: "The sites primary Agent key",
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"status": {
Type: schema.TypeString,
Description: "Current status of the deployment.",
Computed: true,
},
"message": {
Type: schema.TypeString,
Description: "CloudWAF instance message.",
Computed: true,
},
"dns_entry": {
Type: schema.TypeString,
Description: "CloudWAF instance's DNS Entry.",
Computed: true,
},
"egress_ips": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ip": {
Type: schema.TypeString,
Description: "Egress IP address CloudWAF will be directing traffic to origin from.",
Computed: true,
},
"status": {
Type: schema.TypeString,
Description: "EgressIP Status.",
Computed: true,
},
"updated_at": {
Type: schema.TypeString,
Description: "When EgressIP was last updated on.",
Computed: true,
},
},
},
},
},
},
},
},
}
}
Expand Down Expand Up @@ -168,6 +216,7 @@ func resourceCorpCloudWAFInstanceCreate(d *schema.ResourceData, m interface{}) e
}

d.SetId(cwaf.ID)

return resourceCorpCloudWAFInstanceRead(d, m)
}

Expand Down Expand Up @@ -228,6 +277,11 @@ func resourceCorpCloudWAFInstanceRead(d *schema.ResourceData, m interface{}) err
if err != nil {
return err
}
err = d.Set("deployment", flattenCloudWAFInstanceDeployment(cwaf.Deployment))
if err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -344,3 +398,25 @@ func flattenCloudWAFInstanceRoutes(routes []sigsci.CloudWAFInstanceWorkspaceRout
}
return routesMap
}

func flattenCloudWAFInstanceDeployment(deployment sigsci.CloudWAFInstanceDeployment) []interface{} {
return []interface{}{
map[string]interface{}{
"status": deployment.Status,
"message": deployment.Message,
"dns_entry": deployment.DNSEntry,
"egress_ips": flattenCloudWAFInstanceEgressIPs(deployment.EgressIPs),
},
}
}

func flattenCloudWAFInstanceEgressIPs(egressIPs []sigsci.CloudWAFInstanceEgressIP) []interface{} {
var egressIPsSet = make([]interface{}, len(egressIPs))
for i, egressIP := range egressIPs {
egressIPsSet[i] = map[string]interface{}{
"ip": egressIP.IP,
"status": egressIP.Status,
"updated_at": egressIP.UpdatedAt}
}
return egressIPsSet
}
2 changes: 2 additions & 0 deletions provider/resource_corp_cloudwaf_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ func TestAccResourceCorpCloudWAFInstanceCRUD(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "workspace_configs.368698502.routes.3172309932.origin", "https://example.com"),
resource.TestCheckResourceAttr(resourceName, "workspace_configs.368698502.routes.3172309932.pass_host_header", "false"),
resource.TestCheckResourceAttr(resourceName, "workspace_configs.368698502.routes.3172309932.trust_proxy_headers", "true"),
resource.TestCheckResourceAttr(resourceName, "deployment.0.status", "done"),
resource.TestCheckResourceAttrSet(resourceName, "deployment.0.dns_entry"),
),
},
{
Expand Down