Skip to content

Commit

Permalink
Fixed error in the doc
Browse files Browse the repository at this point in the history
Added data source instance test
Fixed typo error in doc

Signed-off-by: Alejandro JNM <alejandrojnm@gmail.com>
  • Loading branch information
alejandrojnm committed Jul 3, 2020
1 parent 12c41ce commit 8b75b83
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 6 deletions.
75 changes: 75 additions & 0 deletions civo/datasource_instance_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package civo

import (
"fmt"
"testing"

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

func TestAccDataSourceCivoInstance_basic(t *testing.T) {
datasourceName := "data.civo_instance.foobar"
name := acctest.RandomWithPrefix("instance") + ".com"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceCivoInstanceConfig(name),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(datasourceName, "hostname", name),
resource.TestCheckResourceAttrSet(datasourceName, "private_ip"),
resource.TestCheckResourceAttrSet(datasourceName, "public_ip"),
resource.TestCheckResourceAttrSet(datasourceName, "pseudo_ip"),
),
},
},
})
}

func TestAccDataSourceCivoInstanceByID_basic(t *testing.T) {
datasourceName := "data.civo_instance.foobar"
name := acctest.RandomWithPrefix("instance") + ".com"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceCivoInstanceByIDConfig(name),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(datasourceName, "hostname", name),
resource.TestCheckResourceAttrSet(datasourceName, "private_ip"),
resource.TestCheckResourceAttrSet(datasourceName, "public_ip"),
resource.TestCheckResourceAttrSet(datasourceName, "pseudo_ip"),
),
},
},
})
}

func testAccDataSourceCivoInstanceConfig(name string) string {
return fmt.Sprintf(`
resource "civo_instance" "vm" {
hostname = "%s"
}
data "civo_instance" "foobar" {
hostname = civo_instance.vm.hostname
}
`, name)
}

func testAccDataSourceCivoInstanceByIDConfig(name string) string {
return fmt.Sprintf(`
resource "civo_instance" "vm" {
hostname = "%s"
}
data "civo_instance" "foobar" {
id = civo_instance.vm.id
}
`, name)
}
4 changes: 2 additions & 2 deletions website/docs/d/instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ output "instance_output" {
}
```

Get the Droplet by id:
Get the Instance by id:

```hcl
data "civo_instance" "myhostaname" {
Expand All @@ -48,7 +48,7 @@ One of following the arguments must be provided:

The following attributes are exported:

* `id` - The ID of the Droplet.
* `id` - The ID of the Instance.
* `hostname` - The Instance hostname.
* `reverse_dns` - A fully qualified domain name.
* `size` - The name of the size.
Expand Down
4 changes: 2 additions & 2 deletions website/docs/d/instances.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ data "civo_instances" "small-with-backups" {

`sort` supports the following arguments:

* `key` - (Required) Sort the Droplets by this key. This may be one of `id`, `hostname`, `public_ip`, `private_ip`,
* `key` - (Required) Sort the Instance by this key. This may be one of `id`, `hostname`, `public_ip`, `private_ip`,
`pseudo_ip`, `size`, `template` or `created_at`.

* `direction` - (Required) The sort direction. This may be either `asc` or `desc`.
Expand All @@ -97,7 +97,7 @@ data "civo_instances" "small-with-backups" {

* `instances` - A list of Instances satisfying any `filter` and `sort` criteria. Each instance has the following attributes:

* `id` - The ID of the Droplet.
* `id` - The ID of the Instance.
* `hostname` - The Instance hostname.
* `reverse_dns` - A fully qualified domain name.
* `size` - The name of the size.
Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/snapshot.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ data "civo_snapshot" "mysql-vm" {

The following attributes are exported:

* `id` The ID of the Droplet snapshot.
* `id` The ID of the Instance snapshot.
* `name` - The name of the snapshot.
* `instance_id` - The ID of the Instance from which the snapshot was be taken.
* `safe` - If is `true` the instance will be shut down during the snapshot if id `false` them not.
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/snapshot.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The default is nil meaning the snapshot will be saved as a one-off snapshot.

The following attributes are exported:

* `id` The ID of the Droplet snapshot.
* `id` The ID of the Instance snapshot.
* `name` - The name of the snapshot.
* `instance_id` - The ID of the Instance from which the snapshot was be taken.
* `safe` - If is `true` the instance will be shut down during the snapshot if id `false` them not.
Expand Down

0 comments on commit 8b75b83

Please sign in to comment.