Skip to content

Commit

Permalink
change label to name
Browse files Browse the repository at this point in the history
  • Loading branch information
uzaxirr committed Jun 19, 2024
1 parent b13b827 commit b24e713
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions civo/network/resource_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func ResourceNetwork() *schema.Resource {
return &schema.Resource{
Description: "Provides a Civo network resource. This can be used to create, modify, and delete networks.",
Schema: map[string]*schema.Schema{
"label": {
"name": {
Type: schema.TypeString,
Required: true,
Description: "Name for the network",
Expand All @@ -43,12 +43,6 @@ func ResourceNetwork() *schema.Resource {
},
Description: "List of nameservers for the network",
},
// Computed resource
"name": {
Type: schema.TypeString,
Computed: true,
Description: "The name of the network",
},
"default": {
Type: schema.TypeBool,
Computed: true,
Expand Down Expand Up @@ -105,7 +99,7 @@ func resourceNetworkCreate(ctx context.Context, d *schema.ResourceData, m interf
apiClient.Region = region.(string)
}

log.Printf("[INFO] creating the new network %s", d.Get("label").(string))
log.Printf("[INFO] creating the new network %s", d.Get("name").(string))
vlanConfig := civogo.VLANConnectConfig{
VlanID: d.Get("vlan_id").(int),
PhysicalInterface: d.Get("vlan_physical_interface").(string),
Expand All @@ -116,7 +110,7 @@ func resourceNetworkCreate(ctx context.Context, d *schema.ResourceData, m interf
}

configs := civogo.NetworkConfig{
Label: d.Get("label").(string),
Label: d.Get("name").(string),
CIDRv4: d.Get("cidr_v4").(string),
Region: apiClient.Region,
NameserversV4: expandStringList(d.Get("nameservers_v4")),
Expand All @@ -128,7 +122,7 @@ func resourceNetworkCreate(ctx context.Context, d *schema.ResourceData, m interf

// Retry the network creation using the utility function
err := utils.RetryUntilSuccessOrTimeout(func() error {
log.Printf("[INFO] Attempting to create the network %s", d.Get("label").(string))
log.Printf("[INFO] Attempting to create the network %s", d.Get("name").(string))
network, err := apiClient.CreateNetwork(configs)
if err != nil {
return err
Expand Down Expand Up @@ -172,9 +166,8 @@ func resourceNetworkRead(_ context.Context, d *schema.ResourceData, m interface{
}
}

d.Set("name", CurrentNetwork.Name)
d.Set("region", apiClient.Region)
d.Set("label", CurrentNetwork.Label)
d.Set("name", CurrentNetwork.Label)
d.Set("default", CurrentNetwork.Default)
d.Set("cidr_v4", CurrentNetwork.CIDR)
d.Set("nameservers_v4", CurrentNetwork.NameserversV4)
Expand All @@ -191,9 +184,9 @@ func resourceNetworkUpdate(ctx context.Context, d *schema.ResourceData, m interf
apiClient.Region = region.(string)
}

if d.HasChange("label") {
if d.HasChange("name") {
log.Printf("[INFO] updating the network %s", d.Id())
_, err := apiClient.RenameNetwork(d.Get("label").(string), d.Id())
_, err := apiClient.RenameNetwork(d.Get("name").(string), d.Id())
if err != nil {
return diag.Errorf("[ERR] An error occurred while rename the network %s", d.Id())
}
Expand Down

0 comments on commit b24e713

Please sign in to comment.