Skip to content
New issue

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

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

Already on GitHub? # to your account

added fix for the issue #328 #348

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 13 additions & 4 deletions civo/firewall/resource_firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ func resourceFirewallCreate(ctx context.Context, d *schema.ResourceData, m inter
}

// function to read a firewall
func resourceFirewallRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
func resourceFirewallRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
apiClient := m.(*civogo.Client)

// overwrite the region if it's defined
// Overwrite the region if it's defined
if region, ok := d.GetOk("region"); ok {
apiClient.Region = region.(string)
}

log.Printf("[INFO] retriving the firewall %s", d.Id())
log.Printf("[INFO] retrieving the firewall %s", d.Id())
resp, err := apiClient.FindFirewall(d.Id())
if err != nil {
if resp == nil {
Expand All @@ -201,8 +201,17 @@ func resourceFirewallRead(_ context.Context, d *schema.ResourceData, m interface
d.Set("name", resp.Name)
d.Set("network_id", resp.NetworkID)
d.Set("region", apiClient.Region)
d.Set("create_default_rules", d.Get("create_default_rules").(bool))

// Check if the firewall uses the default rules
createDefaultRules, err := apiClient.IsUsingDefaultRules(d.Id())
if err != nil {
return diag.Errorf("[ERR] error checking default rules: %s", err)
}

// Set the create_default_rules field in the state
d.Set("create_default_rules", createDefaultRules)

// Set the ingress and egress rules
for _, rule := range resp.Rules {
if rule.Direction == "ingress" {
if err := d.Set("ingress_rule", flattenFirewallRules(resp.Rules, rule.Direction)); err != nil {
Expand Down