-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add digitalocean_records data source (#502)
* add digitalocean_records data source * add docs * id attribute * fmt * switch to single set of functions
- Loading branch information
Showing
19 changed files
with
349 additions
and
40 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
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,23 @@ | ||
package digitalocean | ||
|
||
import ( | ||
"github.com/digitalocean/terraform-provider-digitalocean/internal/datalist" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceDigitalOceanRecords() *schema.Resource { | ||
dataListConfig := &datalist.ResourceConfig{ | ||
RecordSchema: recordsSchema(), | ||
ResultAttributeName: "records", | ||
ExtraQuerySchema: map[string]*schema.Schema{ | ||
"domain": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
}, | ||
FlattenRecord: flattenDigitalOceanRecord, | ||
GetRecords: getDigitalOceanRecords, | ||
} | ||
|
||
return datalist.NewResource(dataListConfig) | ||
} |
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,70 @@ | ||
package digitalocean | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"testing" | ||
) | ||
|
||
func TestAccDataSourceDigitalOceanRecords_Basic(t *testing.T) { | ||
name1 := fmt.Sprintf("foobar-test-terraform-%s.com", acctest.RandString(10)) | ||
|
||
resourcesConfig := fmt.Sprintf(` | ||
resource "digitalocean_domain" "foo" { | ||
name = "%s" | ||
} | ||
resource "digitalocean_record" "mail" { | ||
name = "mail" | ||
domain = digitalocean_domain.foo.name | ||
type = "MX" | ||
priority = 10 | ||
value = "mail.example.com." | ||
} | ||
resource "digitalocean_record" "www" { | ||
name = "www" | ||
domain = digitalocean_domain.foo.name | ||
type = "A" | ||
value = "192.168.1.1" | ||
} | ||
`, name1) | ||
|
||
datasourceConfig := fmt.Sprintf(` | ||
data "digitalocean_records" "result" { | ||
domain = "%s" | ||
filter { | ||
key = "type" | ||
values = ["A"] | ||
} | ||
} | ||
`, name1) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProviderFactories: testAccProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: resourcesConfig, | ||
}, | ||
{ | ||
Config: resourcesConfig + datasourceConfig, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.digitalocean_records.result", "records.#", "1"), | ||
resource.TestCheckResourceAttr("data.digitalocean_records.result", "records.0.domain", name1), | ||
resource.TestCheckResourceAttrPair("data.digitalocean_records.result", "records.0.id", "digitalocean_record.www", "id"), | ||
resource.TestCheckResourceAttrPair("data.digitalocean_records.result", "records.0.name", "digitalocean_record.www", "name"), | ||
resource.TestCheckResourceAttrPair("data.digitalocean_records.result", "records.0.type", "digitalocean_record.www", "type"), | ||
resource.TestCheckResourceAttrPair("data.digitalocean_records.result", "records.0.value", "digitalocean_record.www", "value"), | ||
resource.TestCheckResourceAttrPair("data.digitalocean_records.result", "records.0.priority", "digitalocean_record.www", "priority"), | ||
resource.TestCheckResourceAttrPair("data.digitalocean_records.result", "records.0.port", "digitalocean_record.www", "port"), | ||
resource.TestCheckResourceAttrPair("data.digitalocean_records.result", "records.0.ttl", "digitalocean_record.www", "ttl"), | ||
resource.TestCheckResourceAttrPair("data.digitalocean_records.result", "records.0.weight", "digitalocean_record.www", "weight"), | ||
resource.TestCheckResourceAttrPair("data.digitalocean_records.result", "records.0.flags", "digitalocean_record.www", "flags"), | ||
resource.TestCheckResourceAttrPair("data.digitalocean_records.result", "records.0.tag", "digitalocean_record.www", "tag"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} |
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
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
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
Oops, something went wrong.