mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-09 07:33:58 -06:00
8ae31740e3
* Replace DNSimple API client with the official Go client * Upgrade DNSimple provider to use the new API v2 Acceptance tests pass: ``` === RUN TestProvider --- PASS: TestProvider (0.00s) === RUN TestProvider_impl --- PASS: TestProvider_impl (0.00s) === RUN TestAccDNSimpleRecord_Basic --- PASS: TestAccDNSimpleRecord_Basic (2.67s) === RUN TestAccDNSimpleRecord_Updated --- PASS: TestAccDNSimpleRecord_Updated (1.88s) PASS ok github.com/hashicorp/terraform/builtin/providers/dnsimple ``` Note that the code still has to be updated to pass the account ID dynamically in place of "TODO-ACCOUNT". * Refactor DNSimple provider to expose both client and config The config is required as the new API wants to know the identifier of the account you are operating to. The account is not stored in the client (as the client can talk with different accounts), hence I need to pass it as part of the config. * Identify Terraform requests to DNSimple via UserAgent * Upgrade to the latest dnsimple-go version * Update docs Provide upgrade instructions and update the docs for API v2. * Remove rendundant type declaration
64 lines
1.8 KiB
Go
64 lines
1.8 KiB
Go
package dnsimple
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
// Provider returns a terraform.ResourceProvider.
|
|
func Provider() terraform.ResourceProvider {
|
|
return &schema.Provider{
|
|
Schema: map[string]*schema.Schema{
|
|
"email": &schema.Schema{
|
|
Type: schema.TypeString,
|
|
Optional: true,
|
|
DefaultFunc: schema.EnvDefaultFunc("DNSIMPLE_EMAIL", nil),
|
|
Description: "The DNSimple account email address.",
|
|
},
|
|
|
|
"token": &schema.Schema{
|
|
Type: schema.TypeString,
|
|
Required: true,
|
|
DefaultFunc: schema.EnvDefaultFunc("DNSIMPLE_TOKEN", nil),
|
|
Description: "The API v2 token for API operations.",
|
|
},
|
|
|
|
"account": &schema.Schema{
|
|
Type: schema.TypeString,
|
|
Required: true,
|
|
DefaultFunc: schema.EnvDefaultFunc("DNSIMPLE_ACCOUNT", nil),
|
|
Description: "The account for API operations.",
|
|
},
|
|
},
|
|
|
|
ResourcesMap: map[string]*schema.Resource{
|
|
"dnsimple_record": resourceDNSimpleRecord(),
|
|
},
|
|
|
|
ConfigureFunc: providerConfigure,
|
|
}
|
|
}
|
|
|
|
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
|
// DNSimple API v1 requires email+token to authenticate.
|
|
// DNSimple API v2 requires only an OAuth token and in this particular case
|
|
// the reference of the account for API operations (to avoid fetching it in real time).
|
|
//
|
|
// v2 is not backward compatible with v1, therefore return an error in case email is set,
|
|
// to inform the user to upgrade to v2. Also, v1 token is not the same of v2.
|
|
if email := d.Get("email").(string); email != "" {
|
|
return nil, errors.New(
|
|
"DNSimple API v2 requires an account identifier and the new OAuth token. " +
|
|
"Please upgrade your configuration.")
|
|
}
|
|
|
|
config := Config{
|
|
Token: d.Get("token").(string),
|
|
Account: d.Get("account").(string),
|
|
}
|
|
|
|
return config.Client()
|
|
}
|