Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add domain datasource #34

Merged
merged 9 commits into from
Dec 23, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions exoscale/datasource_exoscale_domain.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package exoscale

import (
"context"
"strconv"

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

func datasourceDomain() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Description: "Name of the Domain",
Required: true,
},
},
Read: datasourceDomainRead,
}
}

func datasourceDomainRead(d *schema.ResourceData, meta interface{}) error {
ctx, cancel := context.WithTimeout(context.Background(), d.Timeout(schema.TimeoutCreate))
defer cancel()

client := GetDNSClient(meta)

domainName := d.Get("name")

domain, err := client.GetDomain(ctx, domainName.(string))
if err != nil {
return err
}

d.SetId(strconv.FormatInt(domain.ID, 10))

return d.Set("name", domain.Name)
}
47 changes: 47 additions & 0 deletions exoscale/datasource_exoscale_domain_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package exoscale

import (
"errors"
"fmt"
"testing"

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

var testAccDatasourceDomainName = testPrefix + "-" + testRandomString() + ".com"

func TestAccDatasourceDomain(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(`
%s
data "exoscale_domain" "domain" {
name = "${exoscale_domain.exo.name}"
}`, testAccResourceDomainRecordConfigCreate),
Check: resource.ComposeTestCheckFunc(
testAccDatasourceDomainAttributes(testAttrs{
"name": ValidateString(testAccDatasourceDomainName),
}),
),
},
},
})
}

func testAccDatasourceDomainAttributes(expected testAttrs) resource.TestCheckFunc {
return func(s *terraform.State) error {
for _, rs := range s.RootModule().Resources {
if rs.Type != "exoscale_domain" {
continue
}

return checkResourceAttributes(expected, rs.Primary.Attributes)
}

return errors.New("exoscale_domain datasource not found in the state")
}
}
1 change: 1 addition & 0 deletions exoscale/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func Provider() terraform.ResourceProvider {

DataSourcesMap: map[string]*schema.Resource{
"exoscale_compute_template": datasourceComputeTemplate(),
"exoscale_domain": datasourceDomain(),
},

ResourcesMap: map[string]*schema.Resource{
Expand Down
32 changes: 32 additions & 0 deletions website/docs/d/domain.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
layout: "exoscale"
page_title: "Exoscale: exoscale_domain"
sidebar_current: "docs-exoscale-domain"
description: |-
Provides information about a Domain.
---

# exoscale\_domain

Provides information on a domain name hosted on [Exoscale DNS][exodns].

[exodns]: https://www.exoscale.com/dns/

## Example Usage

```hcl
data "exoscale_domain" "my-company-com" {
name = "my-company.com"
}
```

## Argument Reference

* `name` - (Required) The name of the domain.

## Attributes Reference

The following attributes are exported:

* `name` - Name of the Domain
* `id` - ID of the Domain