Skip to content

Commit

Permalink
Support Reserved IP for Instance create operation (#204)
Browse files Browse the repository at this point in the history
Signed-off-by: Uzair Ali <72073401+uzaxirr@users.noreply.github.com>
  • Loading branch information
uzaxirr committed Apr 22, 2024
1 parent 887ffbe commit b1bec2c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
20 changes: 15 additions & 5 deletions civo/instances/resource_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ func ResourceInstance() *schema.Resource {
Computed: true,
Description: "Timestamp when the instance was created",
},
"reserved_ipv4": {
Type: schema.TypeString,
Optional: true,
Description: "Can be either the UUID, name, or the IP address of the reserved IP",
},
},
CreateContext: resourceInstanceCreate,
ReadContext: resourceInstanceRead,
Expand All @@ -174,11 +179,11 @@ func ResourceInstance() *schema.Resource {
}
}

// function to create a instance
// function to create an instance
func resourceInstanceCreate(ctx 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 Expand Up @@ -211,6 +216,10 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, m inter
config.PublicIPRequired = attr.(string)
}

if v, ok := d.GetOk("reserved_ipv4"); ok {
config.ReservedIPv4 = v.(string)
}

if networtID, ok := d.GetOk("network_id"); ok {
config.NetworkID = networtID.(string)
} else {
Expand Down Expand Up @@ -312,7 +321,7 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, m inter
func resourceInstanceRead(_ 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 Expand Up @@ -346,6 +355,7 @@ func resourceInstanceRead(_ context.Context, d *schema.ResourceData, m interface
d.Set("firewall_id", resp.FirewallID)
d.Set("status", resp.Status)
d.Set("script", resp.Script)
d.Set("reserved_ipv4", resp.ReservedIP)
d.Set("created_at", resp.CreatedAt.UTC().String())
d.Set("notes", resp.Notes)

Expand All @@ -360,11 +370,11 @@ func resourceInstanceRead(_ context.Context, d *schema.ResourceData, m interface
return nil
}

// function to update a instance
// function to update an instance
func resourceInstanceUpdate(ctx 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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/civo/terraform-provider-civo

require (
github.com/civo/civogo v0.3.65
github.com/civo/civogo v0.3.68
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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ github.com/civo/civogo v0.3.58 h1:FikCbwAKB5ovD8+NmSi7rzYBSpC4nUpGVpCyngEkTo4=
github.com/civo/civogo v0.3.58/go.mod h1:54lv/FOf7gh6wE9ZwVdw4yBehk8V1CvU9aWa4v6dvW0=
github.com/civo/civogo v0.3.65 h1:FZpkaVoTxcc4lAgRbh5fo65EPDBu/0xmJsoql5xEBHk=
github.com/civo/civogo v0.3.65/go.mod h1:S/iYmGvQOraxdRtcXeq/2mVX01/ia2qfpQUp2SsTLKA=
github.com/civo/civogo v0.3.68 h1:WYqJTtMJDpNVtJE0dMpoQoU5T11A1fpHRqNPiL7hGYM=
github.com/civo/civogo v0.3.68/go.mod h1:S/iYmGvQOraxdRtcXeq/2mVX01/ia2qfpQUp2SsTLKA=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs=
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
Expand Down

0 comments on commit b1bec2c

Please sign in to comment.