Skip to content

Commit

Permalink
Create Default firewall for network when not specified. (#230)
Browse files Browse the repository at this point in the history
* Create Default firewall for network when not specified.
  • Loading branch information
uzaxirr committed Jun 24, 2024
1 parent 8a47734 commit 55973e3
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions civo/network/resource_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package network

import (
"context"
"fmt"
"log"
"time"

Expand Down Expand Up @@ -137,6 +138,14 @@ func resourceNetworkCreate(ctx context.Context, d *schema.ResourceData, m interf
return err
}
d.SetId(network.ID)

// Create a default firewall for the network
log.Printf("[INFO] Creating default firewall for the network %s", d.Get("label").(string))
err = createDefaultFirewall(apiClient, network.ID, network.Label)
if err != nil {
return err
}

return nil
}, 10*time.Second, 2*time.Minute)

Expand Down Expand Up @@ -259,3 +268,21 @@ func expandStringList(input interface{}) []string {
}
return result
}

// createDefaultFirewall function to create a default firewall
func createDefaultFirewall(apiClient *civogo.Client, networkID string, networkName string) error {

firewallConfig := civogo.FirewallConfig{
Name: fmt.Sprintf("%s-default", networkName),
NetworkID: networkID,
Region: apiClient.Region,
}

// Create the default firewall
_, err := apiClient.NewFirewall(&firewallConfig)
if err != nil {
return err
}

return nil
}

0 comments on commit 55973e3

Please sign in to comment.