Skip to content

Commit

Permalink
Merge pull request #77 from grokify/enhance/cloudwaf_instance/add_res…
Browse files Browse the repository at this point in the history
…ponse_properties

Add Cloud WAF Instance response computed properties
  • Loading branch information
jhanrahan-sigsci authored Sep 12, 2022
2 parents dd38840 + 5668945 commit 2893f87
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
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

0 comments on commit 2893f87

Please sign in to comment.