Skip to content

Commit

Permalink
provider: remove account_id global configuration option
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobbednarz committed Jan 12, 2023
1 parent 67c25a3 commit 04c40fa
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 25 deletions.
3 changes: 3 additions & 0 deletions .changelog/2139.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:breaking-change
provider: `account_id` is no longer available as a global configuration option. Instead, use the resource specific attributes.
```
1 change: 0 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ resource "cloudflare_page_rule" "www" {

### Optional

- `account_id` (String, Deprecated) Configure API client to always use a specific account. Alternatively, can be configured using the `CLOUDFLARE_ACCOUNT_ID` environment variable.
- `api_base_path` (String) Configure the base path used by the API client. Alternatively, can be configured using the `CLOUDFLARE_API_BASE_PATH` environment variable.
- `api_client_logging` (Boolean) Whether to print logs from the API client (using the default log library logger). Alternatively, can be configured using the `CLOUDFLARE_API_CLIENT_LOGGING` environment variable.
- `api_hostname` (String) Configure the hostname used by the API client. Alternatively, can be configured using the `CLOUDFLARE_API_HOSTNAME` environment variable.
Expand Down
3 changes: 1 addition & 2 deletions internal/provider/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ type Config struct {
}

// Client returns a new client for accessing cloudflare.
func (c *Config) Client() (*cloudflare.API, error) {
func (c *Config) Client(ctx context.Context) (*cloudflare.API, error) {
var err error
var client *cloudflare.API
ctx := context.Background()

if c.APIUserServiceKey != "" {
client, err = cloudflare.NewWithUserServiceKey(c.APIUserServiceKey, c.Options...)
Expand Down
23 changes: 1 addition & 22 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strings"

cloudflare "github.com/cloudflare/cloudflare-go"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -149,14 +148,6 @@ func New(version string) func() *schema.Provider {
Description: "Whether to print logs from the API client (using the default log library logger). Alternatively, can be configured using the `CLOUDFLARE_API_CLIENT_LOGGING` environment variable.",
},

"account_id": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("CLOUDFLARE_ACCOUNT_ID", nil),
Description: "Configure API client to always use a specific account. Alternatively, can be configured using the `CLOUDFLARE_ACCOUNT_ID` environment variable.",
Deprecated: "Use resource specific `account_id` attributes instead.",
},

"api_hostname": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -333,21 +324,9 @@ func configure(version string, p *schema.Provider) func(context.Context, *schema
config.APIUserServiceKey = v.(string)
}

client, err := config.Client()
if err != nil {
return nil, diag.FromErr(err)
}

if accountID, ok := d.GetOk("account_id"); ok {
tflog.Info(ctx, fmt.Sprintf("using specified account id %s in Cloudflare provider", accountID.(string)))
options = append(options, cloudflare.UsingAccount(accountID.(string)))
} else {
return client, diag.FromErr(err)
}

config.Options = options

client, err = config.Client()
client, err := config.Client(ctx)
if err != nil {
return nil, diag.FromErr(err)
}
Expand Down

0 comments on commit 04c40fa

Please sign in to comment.