-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(DataSource): Added new data source
- Added the new data source dns_domain_name to get one domain - Fixed some comment in datasource_instance.go, datasource_instances.go BREAKING CHANGE: No Signed-off-by: Alejandro JNM <alejandrojnm@gmail.com>
- Loading branch information
1 parent
559594a
commit 10629d6
Showing
5 changed files
with
126 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package civo | ||
|
||
import ( | ||
"fmt" | ||
"github.com/civo/civogo" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/validation" | ||
"log" | ||
) | ||
|
||
// Data source to get from the api a specific domain | ||
// using the id or the name of the domain | ||
func dataSourceDnsDomainName() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceDnsDomainNameRead, | ||
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ValidateFunc: validation.NoZeroValues, | ||
ExactlyOneOf: []string{"id", "name"}, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ValidateFunc: validation.NoZeroValues, | ||
ExactlyOneOf: []string{"id", "name"}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceDnsDomainNameRead(d *schema.ResourceData, m interface{}) error { | ||
apiClient := m.(*civogo.Client) | ||
|
||
var foundDomain *civogo.DNSDomain | ||
|
||
if id, ok := d.GetOk("id"); ok { | ||
log.Printf("[INFO] Getting the domain by id") | ||
domain, err := apiClient.FindDNSDomain(id.(string)) | ||
if err != nil { | ||
fmt.Errorf("[ERR] failed to retrive domain: %s", err) | ||
return err | ||
} | ||
|
||
foundDomain = domain | ||
} else if name, ok := d.GetOk("name"); ok { | ||
log.Printf("[INFO] Getting the domain by name") | ||
image, err := apiClient.FindDNSDomain(name.(string)) | ||
if err != nil { | ||
fmt.Errorf("[ERR] failed to retrive domain: %s", err) | ||
return err | ||
} | ||
|
||
foundDomain = image | ||
} | ||
|
||
d.SetId(foundDomain.ID) | ||
d.Set("name", foundDomain.Name) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
--- | ||
layout: "civo" | ||
page_title: "Civo: civo_dns_domain_name" | ||
sidebar_current: "docs-civo-datasource-domain" | ||
description: |- | ||
Get information on a domain. | ||
--- | ||
|
||
# civo_dns_domain_name | ||
|
||
Get information on a domain. This data source provides the name and the id, this is useful if the domain | ||
name in question is not managed by Terraform. | ||
|
||
An error is triggered if the provided domain name is not managed with your | ||
Civo account. | ||
|
||
## Example Usage | ||
|
||
Get the name and the id file for a domain: | ||
|
||
```hcl | ||
data "civo_dns_domain_name" "domain" { | ||
name = "domain.com" | ||
} | ||
output "domain_output" { | ||
value = data.civo_dns_domain_name.domain.name | ||
} | ||
output "domain_id_output" { | ||
value = data.civo_dns_domain_name.domain.id | ||
} | ||
``` | ||
|
||
``` | ||
$ terraform apply | ||
data.civo_dns_domain_name.domain: Refreshing state... | ||
Apply complete! Resources: 0 added, 0 changed, 0 destroyed. | ||
Outputs: | ||
domain_output = domain.com. | ||
domain_id_output = 6ea98024-c6d7-4d0c-bd01-8ee0cab5224e | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `id` - (Optional) The id of the domain. | ||
* `name` - (Optional) The name of the domain. | ||
|
||
## Attributes Reference | ||
|
||
The following attributes are exported: | ||
|
||
* `id` - A unique ID that can be used to identify and reference a domain. | ||
* `name` - The name of the domain. |