Skip to content

Commit

Permalink
Support Private IP for Instance create
Browse files Browse the repository at this point in the history
  • Loading branch information
uzaxirr committed May 6, 2024
1 parent 0cb12ba commit 15ba8d0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 230 deletions.
18 changes: 13 additions & 5 deletions civo/instances/resource_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ package instances

import (
"context"
"log"
"strings"
"time"

"github.com/civo/civogo"
"github.com/civo/terraform-provider-civo/internal/utils"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"log"
"strings"
"time"
)

// ResourceInstance The instance resource represents an object of type instances
Expand Down Expand Up @@ -160,6 +159,11 @@ func ResourceInstance() *schema.Resource {
Computed: true,
Description: "Timestamp when the instance was created",
},
"private_ipv4": {
Type: schema.TypeString,
Optional: true,
Description: "The private IPv4 address for the instance (optional)",
},
"reserved_ipv4": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -216,6 +220,10 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, m inter
config.PublicIPRequired = attr.(string)
}

if privateIPv4, ok := d.GetOk("private_ipv4"); ok {
config.PrivateIPv4 = privateIPv4.(string)
}

if v, ok := d.GetOk("reserved_ipv4"); ok {
config.ReservedIPv4 = v.(string)
}
Expand Down Expand Up @@ -471,7 +479,7 @@ func resourceInstanceUpdate(ctx context.Context, d *schema.ResourceData, m inter
func resourceInstanceDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
apiClient := m.(*civogo.Client)

// overwrite the region if is define in the datasource
// overwrite the region if is defined in the datasource
if region, ok := d.GetOk("region"); ok {
apiClient.Region = region.(string)
}
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module github.com/civo/terraform-provider-civo

require (
github.com/civo/civogo v0.3.68
github.com/civo/civogo v0.3.69
github.com/google/uuid v1.3.1
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-sdk/v2 v2.31.0
github.com/stretchr/testify v1.8.4
golang.org/x/crypto v0.18.0
golang.org/x/crypto v0.21.0
k8s.io/api v0.29.1
)

Expand Down Expand Up @@ -59,8 +59,8 @@ require (
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/zclconf/go-cty v1.14.1 // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 // indirect
Expand Down
Loading

0 comments on commit 15ba8d0

Please sign in to comment.