Skip to content

Commit

Permalink
release v0.1.18
Browse files Browse the repository at this point in the history
  • Loading branch information
contabo committed Aug 10, 2023
1 parent 4e72de4 commit ae27490
Show file tree
Hide file tree
Showing 26 changed files with 127 additions and 141 deletions.
8 changes: 4 additions & 4 deletions contabo/resource_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,10 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, m inter
createInstanceRequest.DisplayName = &displayName
}
if imageId != "" {
createInstanceRequest.ImageId = imageId
createInstanceRequest.ImageId = &imageId
}
if region != "" {
createInstanceRequest.Region = region
createInstanceRequest.Region = &region
}
if productId != "" {
createInstanceRequest.ProductId = productId
Expand Down Expand Up @@ -498,7 +498,7 @@ func AddInstanceToData(
if err := d.Set("product_id", instance.ProductId); err != nil {
return diag.FromErr(err)
}
ipConfig := buildIpConfig(instance.IpConfig)
ipConfig := buildIpConfig(&instance.IpConfig)
if err := d.Set("ip_config", ipConfig); err != nil && len(ipConfig) > 0 {
return diag.FromErr(err)
}
Expand Down Expand Up @@ -552,7 +552,7 @@ func AddInstanceToData(
return diags
}

func buildIpConfig(ipConfigResponse *openapi.IpConfig2) []interface{} {
func buildIpConfig(ipConfigResponse *openapi.IpConfig) []interface{} {
if ipConfigResponse != nil {
ipConfig := make(map[string]interface{})

Expand Down
85 changes: 43 additions & 42 deletions contabo/resource_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,54 @@ package contabo

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

// func TestAccContaboInstanceBasic(t *testing.T) {
// resource.Test(t, resource.TestCase{
// PreCheck: func() { testAccPreCheck(t) },
// Providers: testAccProviders,
// CheckDestroy: testAccCheckInstanceDestroy,
// Steps: []resource.TestStep{
// {
// Config: updateAndReinstallVPSCreation(),
// Check: resource.ComposeTestCheckFunc(
// testCheckContaboInstanceExists("contabo_instance.update_reinstall_test"),
// resource.TestCheckResourceAttr("contabo_instance.update_reinstall_test", "display_name", "created_display_name"),
// ),
// PreventPostDestroyRefresh: true,
// },
// {
// Config: updateAndReinstallInstallFedora(),
// Check: resource.ComposeTestCheckFunc(
// testCheckContaboInstanceExists("contabo_instance.update_reinstall_test"),
// resource.TestCheckResourceAttr("contabo_instance.update_reinstall_test", "image_id", "1e1802ac-843c-42ed-9533-add37aaff46b"),
// ),
// PreventPostDestroyRefresh: true,
// },
// {
// Config: updateAndReinstallDisplayNameUpdate(),
// Check: resource.ComposeTestCheckFunc(
// testCheckContaboInstanceExists("contabo_instance.update_reinstall_test"),
// resource.TestCheckResourceAttr("contabo_instance.update_reinstall_test", "display_name", "first_updated_display_name"),
// ),
// PreventPostDestroyRefresh: true,
// },
// {
// Config: updateAndReinstallUpdateDisplayNameAndInstallArch(),
// Check: resource.ComposeTestCheckFunc(
// testCheckContaboInstanceExists("contabo_instance.update_reinstall_test"),
// resource.TestCheckResourceAttr("contabo_instance.update_reinstall_test", "display_name", "secound_updated_display_name"),
// resource.TestCheckResourceAttr("contabo_instance.update_reinstall_test", "image_id", "69b52ee3-2fda-4f44-b8de-69e480d87c7d"),
// ),
// PreventPostDestroyRefresh: true,
// },
// },
// })
// }
func TestAccContaboInstanceBasic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckInstanceDestroy,
Steps: []resource.TestStep{
{
Config: updateAndReinstallVPSCreation(),
Check: resource.ComposeTestCheckFunc(
testCheckContaboInstanceExists("contabo_instance.update_reinstall_test"),
resource.TestCheckResourceAttr("contabo_instance.update_reinstall_test", "display_name", "created_display_name"),
),
PreventPostDestroyRefresh: true,
},
{
Config: updateAndReinstallInstallFedora(),
Check: resource.ComposeTestCheckFunc(
testCheckContaboInstanceExists("contabo_instance.update_reinstall_test"),
resource.TestCheckResourceAttr("contabo_instance.update_reinstall_test", "image_id", "1e1802ac-843c-42ed-9533-add37aaff46b"),
),
PreventPostDestroyRefresh: true,
},
{
Config: updateAndReinstallDisplayNameUpdate(),
Check: resource.ComposeTestCheckFunc(
testCheckContaboInstanceExists("contabo_instance.update_reinstall_test"),
resource.TestCheckResourceAttr("contabo_instance.update_reinstall_test", "display_name", "first_updated_display_name"),
),
PreventPostDestroyRefresh: true,
},
{
Config: updateAndReinstallUpdateDisplayNameAndInstallArch(),
Check: resource.ComposeTestCheckFunc(
testCheckContaboInstanceExists("contabo_instance.update_reinstall_test"),
resource.TestCheckResourceAttr("contabo_instance.update_reinstall_test", "display_name", "secound_updated_display_name"),
resource.TestCheckResourceAttr("contabo_instance.update_reinstall_test", "image_id", "69b52ee3-2fda-4f44-b8de-69e480d87c7d"),
),
PreventPostDestroyRefresh: true,
},
},
})
}

func updateAndReinstallVPSCreation() string {
return `
Expand Down
34 changes: 20 additions & 14 deletions contabo/resource_private_networking.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func resourcePrivateNetworkCreate(
createPrivateNetworkRequest := openapi.NewCreatePrivateNetworkRequestWithDefaults()
createPrivateNetworkRequest.Name = privateNetworkName
createPrivateNetworkRequest.Description = &privateNetworkDescription
createPrivateNetworkRequest.Region = privateNetworkRegion
createPrivateNetworkRequest.Region = &privateNetworkRegion

res, httpResp, err := client.PrivateNetworksApi.
CreatePrivateNetwork(context.Background()).
Expand Down Expand Up @@ -351,32 +351,38 @@ func handleInstanceChanges(diags diag.Diagnostics,
//Remove instances which are not more in this private network
old, new := d.GetChange("instance_ids")
oldInstanceIds := old.(*schema.Set).List()
newInstanceIds := new.(*schema.Set).List()
for _, instanceId := range oldInstanceIds {
instanceIdInt := instanceId.(int)
instanceId := int64(instanceIdInt)
instanceId64Int := int64(instanceIdInt)

httpResp, err := unassignInstanceToPrivateNetwork(diags, client, privateNetworkId, instanceId)
if err != nil {
return HandleResponseErrors(diags, httpResp)
if !new.(*schema.Set).Contains(instanceId) {
httpResp, err := unassignInstanceToPrivateNetwork(diags, client, privateNetworkId, instanceId64Int)
if err != nil {
return HandleResponseErrors(diags, httpResp)
}
}

}

//Add new instances which are now in this private network
newInstanceIds := new.(*schema.Set).List()
for _, instanceId := range newInstanceIds {
instanceIdInt := instanceId.(int)
instanceId := int64(instanceIdInt)
instanceId64Int := int64(instanceIdInt)

httpResp, err := retryAddPrivateNetworkAddOnToInstance(diags, client, instanceId, 0)
if !old.(*schema.Set).Contains(instanceId) {
httpResp, err := retryAddPrivateNetworkAddOnToInstance(diags, client, instanceId64Int, 0)

if err != nil && !strings.Contains(err.Error(), httpConflict) {
return HandleResponseErrors(diags, httpResp)
}
if err != nil && !strings.Contains(err.Error(), httpConflict) {
return HandleResponseErrors(diags, httpResp)
}

httpResp, err = assignInstanceToPrivateNetwork(diags, client, privateNetworkId, instanceId)
if err != nil {
return HandleResponseErrors(diags, httpResp)
httpResp, err = assignInstanceToPrivateNetwork(diags, client, privateNetworkId, instanceId64Int)
if err != nil {
return HandleResponseErrors(diags, httpResp)
}
}

}
return nil
}
Expand Down
63 changes: 32 additions & 31 deletions contabo/resource_private_networking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,45 @@ import (
"context"
"fmt"
"strconv"
"testing"

"contabo.com/openapi"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
uuid "github.com/satori/go.uuid"
)

// func TestAccContaboPrivateNetworkBasic(t *testing.T) {
// resource.Test(t, resource.TestCase{
// PreCheck: func() {
// testAccPreCheck(t)
// },
// Providers: testAccProviders,
// CheckDestroy: testAccCheckPrivateNetworkDestroy,
// Steps: []resource.TestStep{
// {
// Config: testAddInstance(),
// },
// {
// Config: testCheckContaboPrivateNetworkConfigBasic(),
// Check: resource.ComposeTestCheckFunc(
// testCheckContaboPrivateNetworkExists("contabo_private_network.new"),
// resource.TestCheckResourceAttr("contabo_private_network.new", "instances.#", "0"),
// ),
// },
// {
// Config: testContaboPrivateNetworkConfigWithInstance(),
// Check: resource.ComposeTestCheckFunc(
// testCheckContaboPrivateNetworkExists("contabo_private_network.with_instance"),
// resource.TestCheckResourceAttr("contabo_private_network.with_instance", "instances.#", "1"),
// resource.TestCheckResourceAttr(
// "contabo_private_network.with_instance", "instances.0.private_ip_config.0.v4.0.ip", "10.0.0.1"),
// resource.TestCheckResourceAttr("contabo_instance.new", "additional_ips.#", "0"),
// ),
// },
// },
// })
// }
func TestAccContaboPrivateNetworkBasic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testAccCheckPrivateNetworkDestroy,
Steps: []resource.TestStep{
{
Config: testAddInstance(),
},
{
Config: testCheckContaboPrivateNetworkConfigBasic(),
Check: resource.ComposeTestCheckFunc(
testCheckContaboPrivateNetworkExists("contabo_private_network.new"),
resource.TestCheckResourceAttr("contabo_private_network.new", "instances.#", "0"),
),
},
{
Config: testContaboPrivateNetworkConfigWithInstance(),
Check: resource.ComposeTestCheckFunc(
testCheckContaboPrivateNetworkExists("contabo_private_network.with_instance"),
resource.TestCheckResourceAttr("contabo_private_network.with_instance", "instances.#", "1"),
resource.TestCheckResourceAttr(
"contabo_private_network.with_instance", "instances.0.private_ip_config.0.v4.0.ip", "10.0.0.1"),
resource.TestCheckResourceAttr("contabo_instance.new", "additional_ips.#", "0"),
),
},
},
})
}

func testAccCheckPrivateNetworkDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*openapi.APIClient)
Expand Down
36 changes: 21 additions & 15 deletions contabo/resource_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package contabo
import (
"context"
"fmt"
"os"
"strconv"
"testing"

"contabo.com/openapi"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand All @@ -13,21 +15,25 @@ import (

var instanceId int64 = 10001001

// func TestAccContaboSnapshotBasic(t *testing.T) {
// resource.Test(t, resource.TestCase{
// PreCheck: func() { testAccPreCheck(t) },
// Providers: testAccProviders,
// CheckDestroy: testAccCheckInstanceSnapshotDestroy,
// Steps: []resource.TestStep{
// {
// Config: testCheckContaboInstanceSnapshotConfigBasic(),
// Check: resource.ComposeTestCheckFunc(
// testCheckContaboInstanceSnapshotExists("contabo_instance_snapshot.new"),
// ),
// },
// },
// })
// }
func TestAccContaboSnapshotBasic(t *testing.T) {
// We have to skip the test on prod, because our test vhost (v_host_id = 14174) is suspended on prod, if it will not be suspended it is possible that customer will be provisioned on it... :)
if os.Getenv("SKIP_PROD") != "" {
t.Skip("Skipping not finished test")
}
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckInstanceSnapshotDestroy,
Steps: []resource.TestStep{
{
Config: testCheckContaboInstanceSnapshotConfigBasic(),
Check: resource.ComposeTestCheckFunc(
testCheckContaboInstanceSnapshotExists("contabo_instance_snapshot.new"),
),
},
},
})
}

func testAccCheckInstanceSnapshotDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*openapi.APIClient)
Expand Down
2 changes: 0 additions & 2 deletions docs/data-sources/contabo_image.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,3 @@ In order to provide a custom image, please specify an URL from which the image c
- `status` (String) Downloading status of the image (`downloading`, `downloaded` or `error`).
- `uploaded_size_mb` (Number) The size of the uploaded image in megabyte.
- `version` (String) Version number to distinguish the contents of an image e.g. the version of the operating system.


2 changes: 0 additions & 2 deletions docs/data-sources/contabo_instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,3 @@ Read-Only:
- `gateway` (String)
- `ip` (String)
- `netmask_cidr` (Number)


2 changes: 0 additions & 2 deletions docs/data-sources/contabo_instance_snapshot.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,3 @@ description: |-
- `created_date` (String) The creation date of this instance snapshot.
- `image_id` (String) Id of the Image the snapshot was taken from.
- `image_name` (String) Name of the Image the snapshot was taken from.


2 changes: 0 additions & 2 deletions docs/data-sources/contabo_object_storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,3 @@ Optional:
- `error_message` (String) If the autoscaling is in an error state (see status property), the error message can be seen in this field.
- `size_limit_tb` (Number) Autoscaling size limit for the current object storage.
- `state` (String) Status of this object storage. It can be set to `enabled`, `disabled` or `error`.


2 changes: 0 additions & 2 deletions docs/data-sources/contabo_object_storage_bucket.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,3 @@ Manage buckets on your contabo Object Storage. With this resource you are able t
- `creation_date` (String) The creation date of the bucket.
- `id` (String) The ID of this resource.
- `public_sharing_link` (String) If your bucket is publicly shared, you can access it with this link.


2 changes: 0 additions & 2 deletions docs/data-sources/contabo_private_network.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,3 @@ Read-Only:
- `gateway` (String)
- `ip` (String)
- `netmask_cidr` (Number)


2 changes: 0 additions & 2 deletions docs/data-sources/contabo_secret.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,3 @@ The Secret Management API allows you to store and manage your passwords and ssh-
### Read-Only

- `id` (String) The identifier of the secret. Use it to manage it!


2 changes: 1 addition & 1 deletion docs/guides/custom_instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ terraform {
required_providers {
contabo = {
source = "contabo/contabo"
version = ">= 0.1.17"
version = ">= 0.1.18"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/use_environment_variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ terraform {
required_providers {
contabo = {
source = "contabo/contabo"
version = ">= 0.1.17"
version = ">= 0.1.18"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ terraform {
required_providers {
contabo = {
source = "contabo/contabo"
version = ">= 0.1.17"
version = ">= 0.1.18"
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions docs/resources/contabo_image.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,3 @@ resource "contabo_image" "custom_image_alpine" {
- `standard_image` (Boolean) Flag indicating that the image is either a standard (true) or a custom image (false).
- `status` (String) Downloading status of the image (`downloading`, `downloaded` or `error`).
- `uploaded_size_mb` (Number) The size of the uploaded image in megabyte.


2 changes: 0 additions & 2 deletions docs/resources/contabo_instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,3 @@ Read-Only:
- `gateway` (String)
- `ip` (String)
- `netmask_cidr` (Number)


0 comments on commit ae27490

Please sign in to comment.