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

Wrong account_id using cloudflare_accounts Data Source #1956

Closed
2 tasks done
ivanfavi opened this issue Oct 10, 2022 · 4 comments
Closed
2 tasks done

Wrong account_id using cloudflare_accounts Data Source #1956

ivanfavi opened this issue Oct 10, 2022 · 4 comments
Labels
kind/support Categorizes issue or PR as related to user support.

Comments

@ivanfavi
Copy link

ivanfavi commented Oct 10, 2022

Confirmation

  • My issue isn't already found on the issue tracker.
  • I have replicated my issue using the latest version of the provider and it is still present.

Terraform and Cloudflare provider version

Terraform v1.3.2
on linux_amd64
+ provider registry.terraform.io/cloudflare/cloudflare v3.25.0

Affected resource(s)

cloudflare_accounts (Data Source)

I've used a local variable to set the CloudFlare account id. Now trying to use this data source https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/data-sources/accounts
I'm getting an unexpected value.

I'm able to resolve and get the properly account ID through this API call

curl -sX GET "https://api.cloudflare.com/client/v4/accounts" \
     -H "X-Auth-Email: XXXX" \
     -H "X-Auth-Key: YYY" \
     -H "Content-Type: application/json" | jq .

I'm using a account name like this "Company - Testing" Maybe some character is not correctly parsed from the provider?

Terraform configuration files

terraform {
  required_version = "1.3.2"
  required_providers {
    cloudflare = {
      source  = "cloudflare/cloudflare"
      version = "3.25.0"
    }
  }
}

provider "cloudflare" {
  api_key = var.api_key
  email   = var.email
}

data "cloudflare_accounts" "cf_account_testing" {
  name = "Company - Testing"
}

locals {
  account_id = "eafd3cacb876352a4a064b203364b11b"
}

output "account_id" {
  # value       = local.account_id
  value       = data.cloudflare_accounts.cf_account_testing.id
  description = "Company Testing account id"
}

Link to debug output

nothing relevant to add here

Panic output

No response

Expected output

Plan: 0 to add, 0 to change, 0 to destroy.

Actual output

Plan: 0 to add, 1 to change, 0 to destroy.

Changes to Outputs:
  ~ account_id = "eafd3cacb876352a4a064b203364b11b" -> "9231aee13b429376bc5ffaa8ff242cdc"

Steps to reproduce

  1. Remove locals/variable where I set manually the account_id value
  2. Execute terraform plan to get the account_id value from the data source

Additional factoids

No response

References

#1902
https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/data-sources/accounts

@ivanfavi ivanfavi added kind/bug Categorizes issue or PR as related to a bug. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Oct 10, 2022
@jacobbednarz
Copy link
Member

Thank you for reporting this issue! For maintainers to dig into issues it is required that all issues include the entirety of TF_LOG=DEBUG output to be provided. The only parts that should be redacted are your user credentials in the X-Auth-Key, X-Auth-Email and Authorization HTTP headers. Details such as zone or account identifiers are not considered sensitive but can be redacted if you are very cautious. This log file provides additional context from Terraform, the provider and the Cloudflare API that helps in debugging issues. Without it, maintainers are very limited in what they can do and may hamper diagnosis efforts.

This issue has been marked with triage/needs-information and is unlikely to receive maintainer attention until the log file is provided making this a complete bug report.

@jacobbednarz jacobbednarz added triage/needs-information Indicates an issue needs more information in order to work on it. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Oct 10, 2022
@ivanfavi
Copy link
Author

ivanfavi commented Oct 11, 2022

here there is the output requested

2022-10-11T10:01:08.260+0200 [INFO]  Terraform version: 1.3.2
2022-10-11T10:01:08.260+0200 [DEBUG] using github.com/hashicorp/go-tfe v1.9.0
2022-10-11T10:01:08.260+0200 [DEBUG] using github.com/hashicorp/hcl/v2 v2.14.1
2022-10-11T10:01:08.260+0200 [DEBUG] using github.com/hashicorp/terraform-config-inspect v0.0.0-20210209133302-4fd17a0faac2
2022-10-11T10:01:08.260+0200 [DEBUG] using github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734
2022-10-11T10:01:08.260+0200 [DEBUG] using github.com/zclconf/go-cty v1.11.0
2022-10-11T10:01:08.260+0200 [INFO]  Go runtime version: go1.19.1
2022-10-11T10:01:08.260+0200 [INFO]  CLI args: []string{"/home/ivan/.tfenv/versions/1.3.2/terraform", "plan"}
2022-10-11T10:01:08.260+0200 [DEBUG] Attempting to open CLI config file: /home/ivan/.terraformrc
2022-10-11T10:01:08.260+0200 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2022-10-11T10:01:08.260+0200 [DEBUG] ignoring non-existing provider search directory terraform.d/plugins
2022-10-11T10:01:08.260+0200 [DEBUG] ignoring non-existing provider search directory /home/ivan/.terraform.d/plugins
2022-10-11T10:01:08.260+0200 [DEBUG] ignoring non-existing provider search directory /home/ivan/.local/share/terraform/plugins
2022-10-11T10:01:08.260+0200 [DEBUG] ignoring non-existing provider search directory /usr/share/ubuntu/terraform/plugins
2022-10-11T10:01:08.260+0200 [DEBUG] ignoring non-existing provider search directory /usr/share/gnome/terraform/plugins
2022-10-11T10:01:08.260+0200 [DEBUG] ignoring non-existing provider search directory /usr/local/share/terraform/plugins
2022-10-11T10:01:08.260+0200 [DEBUG] ignoring non-existing provider search directory /usr/share/terraform/plugins
2022-10-11T10:01:08.260+0200 [DEBUG] ignoring non-existing provider search directory /var/lib/snapd/desktop/terraform/plugins
2022-10-11T10:01:08.260+0200 [INFO]  CLI command args: []string{"plan"}
2022-10-11T10:01:08.261+0200 [DEBUG] New state was assigned lineage "66661d12-b95c-afc5-cabd-f8482b4d18bd"
2022-10-11T10:01:08.300+0200 [DEBUG] checking for provisioner in "."
2022-10-11T10:01:08.300+0200 [DEBUG] checking for provisioner in "/home/ivan/.tfenv/versions/1.3.2"
2022-10-11T10:01:08.301+0200 [INFO]  backend/local: starting Plan operation
2022-10-11T10:01:08.302+0200 [DEBUG] created provider logger: level=debug
2022-10-11T10:01:08.302+0200 [INFO]  provider: configuring client automatic mTLS
2022-10-11T10:01:08.317+0200 [DEBUG] provider: starting plugin: path=.terraform/providers/registry.terraform.io/cloudflare/cloudflare/3.25.0/linux_amd64/terraform-provider-cloudflare_v3.25.0 args=[.terraform/providers/registry.terraform.io/cloudflare/cloudflare/3.25.0/linux_amd64/terraform-provider-cloudflare_v3.25.0]
2022-10-11T10:01:08.317+0200 [DEBUG] provider: plugin started: path=.terraform/providers/registry.terraform.io/cloudflare/cloudflare/3.25.0/linux_amd64/terraform-provider-cloudflare_v3.25.0 pid=128426
2022-10-11T10:01:08.317+0200 [DEBUG] provider: waiting for RPC address: path=.terraform/providers/registry.terraform.io/cloudflare/cloudflare/3.25.0/linux_amd64/terraform-provider-cloudflare_v3.25.0
2022-10-11T10:01:08.324+0200 [INFO]  provider.terraform-provider-cloudflare_v3.25.0: configuring server automatic mTLS: timestamp=2022-10-11T10:01:08.324+0200
2022-10-11T10:01:08.341+0200 [DEBUG] provider: using plugin: version=5
2022-10-11T10:01:08.341+0200 [DEBUG] provider.terraform-provider-cloudflare_v3.25.0: plugin address: address=/tmp/plugin4207044575 network=unix timestamp=2022-10-11T10:01:08.341+0200
2022-10-11T10:01:08.361+0200 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2022-10-11T10:01:08.362+0200 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/cloudflare/cloudflare/3.25.0/linux_amd64/terraform-provider-cloudflare_v3.25.0 pid=128426
2022-10-11T10:01:08.362+0200 [DEBUG] provider: plugin exited
2022-10-11T10:01:08.362+0200 [DEBUG] Building and walking validate graph
2022-10-11T10:01:08.369+0200 [DEBUG] ProviderTransformer: "data.cloudflare_accounts.cf_account_testing" (*terraform.NodeValidatableResource) needs provider["registry.terraform.io/cloudflare/cloudflare"]
2022-10-11T10:01:08.369+0200 [DEBUG] ReferenceTransformer: "output.account_id (expand)" references: [data.cloudflare_accounts.cf_account_testing]
2022-10-11T10:01:08.370+0200 [DEBUG] ReferenceTransformer: "provider[\"registry.terraform.io/cloudflare/cloudflare\"]" references: []
2022-10-11T10:01:08.370+0200 [DEBUG] ReferenceTransformer: "data.cloudflare_accounts.cf_account_testing" references: []
2022-10-11T10:01:08.370+0200 [DEBUG] ReferenceTransformer: "local.account_id (expand)" references: []
2022-10-11T10:01:08.370+0200 [DEBUG] Starting graph walk: walkValidate
2022-10-11T10:01:08.370+0200 [DEBUG] created provider logger: level=debug
2022-10-11T10:01:08.370+0200 [INFO]  provider: configuring client automatic mTLS
2022-10-11T10:01:08.376+0200 [DEBUG] provider: starting plugin: path=.terraform/providers/registry.terraform.io/cloudflare/cloudflare/3.25.0/linux_amd64/terraform-provider-cloudflare_v3.25.0 args=[.terraform/providers/registry.terraform.io/cloudflare/cloudflare/3.25.0/linux_amd64/terraform-provider-cloudflare_v3.25.0]
2022-10-11T10:01:08.376+0200 [DEBUG] provider: plugin started: path=.terraform/providers/registry.terraform.io/cloudflare/cloudflare/3.25.0/linux_amd64/terraform-provider-cloudflare_v3.25.0 pid=128442
2022-10-11T10:01:08.376+0200 [DEBUG] provider: waiting for RPC address: path=.terraform/providers/registry.terraform.io/cloudflare/cloudflare/3.25.0/linux_amd64/terraform-provider-cloudflare_v3.25.0
2022-10-11T10:01:08.380+0200 [INFO]  provider.terraform-provider-cloudflare_v3.25.0: configuring server automatic mTLS: timestamp=2022-10-11T10:01:08.379+0200
2022-10-11T10:01:08.396+0200 [DEBUG] provider: using plugin: version=5
2022-10-11T10:01:08.396+0200 [DEBUG] provider.terraform-provider-cloudflare_v3.25.0: plugin address: network=unix address=/tmp/plugin1217547021 timestamp=2022-10-11T10:01:08.396+0200
2022-10-11T10:01:08.420+0200 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2022-10-11T10:01:08.421+0200 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/cloudflare/cloudflare/3.25.0/linux_amd64/terraform-provider-cloudflare_v3.25.0 pid=128442
2022-10-11T10:01:08.421+0200 [DEBUG] provider: plugin exited
2022-10-11T10:01:08.421+0200 [INFO]  backend/local: plan calling Plan
2022-10-11T10:01:08.421+0200 [DEBUG] Building and walking plan graph for NormalMode
2022-10-11T10:01:08.422+0200 [DEBUG] ProviderTransformer: "data.cloudflare_accounts.cf_account_testing (expand)" (*terraform.nodeExpandPlannableResource) needs provider["registry.terraform.io/cloudflare/cloudflare"]
2022-10-11T10:01:08.422+0200 [DEBUG] ReferenceTransformer: "local.account_id (expand)" references: []
2022-10-11T10:01:08.422+0200 [DEBUG] ReferenceTransformer: "output.account_id (expand)" references: [data.cloudflare_accounts.cf_account_testing (expand)]
2022-10-11T10:01:08.422+0200 [DEBUG] ReferenceTransformer: "provider[\"registry.terraform.io/cloudflare/cloudflare\"]" references: []
2022-10-11T10:01:08.422+0200 [DEBUG] ReferenceTransformer: "data.cloudflare_accounts.cf_account_testing (expand)" references: []
2022-10-11T10:01:08.422+0200 [DEBUG] Starting graph walk: walkPlan
2022-10-11T10:01:08.422+0200 [DEBUG] created provider logger: level=debug
2022-10-11T10:01:08.422+0200 [INFO]  provider: configuring client automatic mTLS
2022-10-11T10:01:08.428+0200 [DEBUG] provider: starting plugin: path=.terraform/providers/registry.terraform.io/cloudflare/cloudflare/3.25.0/linux_amd64/terraform-provider-cloudflare_v3.25.0 args=[.terraform/providers/registry.terraform.io/cloudflare/cloudflare/3.25.0/linux_amd64/terraform-provider-cloudflare_v3.25.0]
2022-10-11T10:01:08.428+0200 [DEBUG] provider: plugin started: path=.terraform/providers/registry.terraform.io/cloudflare/cloudflare/3.25.0/linux_amd64/terraform-provider-cloudflare_v3.25.0 pid=128462
2022-10-11T10:01:08.428+0200 [DEBUG] provider: waiting for RPC address: path=.terraform/providers/registry.terraform.io/cloudflare/cloudflare/3.25.0/linux_amd64/terraform-provider-cloudflare_v3.25.0
2022-10-11T10:01:08.432+0200 [INFO]  provider.terraform-provider-cloudflare_v3.25.0: configuring server automatic mTLS: timestamp=2022-10-11T10:01:08.432+0200
2022-10-11T10:01:08.448+0200 [DEBUG] provider: using plugin: version=5
2022-10-11T10:01:08.448+0200 [DEBUG] provider.terraform-provider-cloudflare_v3.25.0: plugin address: address=/tmp/plugin1071327281 network=unix timestamp=2022-10-11T10:01:08.448+0200
2022-10-11T10:01:08.470+0200 [WARN]  ValidateProviderConfig from "provider[\"registry.terraform.io/cloudflare/cloudflare\"]" changed the config value, but that value is unused
2022-10-11T10:01:08.471+0200 [DEBUG] Resource instance state not found for node "data.cloudflare_accounts.cf_account_testing", instance data.cloudflare_accounts.cf_account_testing
2022-10-11T10:01:08.471+0200 [DEBUG] ReferenceTransformer: "data.cloudflare_accounts.cf_account_testing" references: []
data.cloudflare_accounts.cf_account_testing: Reading...
2022-10-11T10:01:08.472+0200 [DEBUG] provider.terraform-provider-cloudflare_v3.25.0: reading accounts: @module=cloudflare tf_provider_addr=registry.terraform.io/cloudflare/cloudflare @caller=github.com/cloudflare/terraform-provider-cloudflare/internal/provider/data_source_accounts.go:62 tf_data_source_type=cloudflare_accounts tf_req_id=f677af81-b783-f33f-9c28-1b6b7114aada tf_rpc=ReadDataSource timestamp=2022-10-11T10:01:08.472+0200
2022-10-11T10:01:08.473+0200 [DEBUG] provider.terraform-provider-cloudflare_v3.25.0: Cloudflare API Request Details:
---[ REQUEST ]---------------------------------------
GET /client/v4/accounts?name=Company+-+Testing HTTP/1.1
Host: api.cloudflare.com
User-Agent: terraform/1.3.2 terraform-plugin-sdk/2.10.1 terraform-provider-cloudflare/3.25.0
Content-Type: application/json
X-Auth-Email: [redacted]
X-Auth-Key: [redacted]
Accept-Encoding: gzip




-----------------------------------------------------: timestamp=2022-10-11T10:01:08.472+0200
2022-10-11T10:01:09.612+0200 [DEBUG] provider.terraform-provider-cloudflare_v3.25.0: Cloudflare API Response Details:
---[ RESPONSE ]--------------------------------------
HTTP/2.0 200 OK
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Cf-Cache-Status: DYNAMIC
Cf-Ray: 758610ed5ed96977-FRA
Content-Type: application/json
Date: Tue, 11 Oct 2022 08:01:09 GMT
Expires: Sun, 25 Jan 1981 05:00:00 GMT
Pragma: no-cache
Server: cloudflare
Set-Cookie: __cfruid=01e3d905c5f797c5ba6ec89c271878df7b763c93-1665475269; path=/; domain=.api.cloudflare.com; HttpOnly; Secure; SameSite=None
Strict-Transport-Security: max-age=31536000
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN


{
 "result": [],
 "result_info": {
  "page": 1,
  "per_page": 20,
  "total_pages": 0,
  "count": 0,
  "total_count": 0
 },
 "success": true,
 "errors": [],
 "messages": []
}
-----------------------------------------------------: timestamp=2022-10-11T10:01:09.612+0200
data.cloudflare_accounts.cf_account_testing: Read complete after 2s [id=d41d8cd98f00b204e9800998ecf8427e]
2022-10-11T10:01:09.615+0200 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2022-10-11T10:01:09.618+0200 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/cloudflare/cloudflare/3.25.0/linux_amd64/terraform-provider-cloudflare_v3.25.0 pid=128462
2022-10-11T10:01:09.618+0200 [DEBUG] provider: plugin exited
2022-10-11T10:01:09.618+0200 [DEBUG] building apply graph to check for errors
2022-10-11T10:01:09.619+0200 [DEBUG] ProviderTransformer: "data.cloudflare_accounts.cf_account_testing (expand)" (*terraform.nodeExpandApplyableResource) needs provider["registry.terraform.io/cloudflare/cloudflare"]
2022-10-11T10:01:09.619+0200 [DEBUG] ReferenceTransformer: "output.account_id (expand)" references: [data.cloudflare_accounts.cf_account_testing (expand)]
2022-10-11T10:01:09.619+0200 [DEBUG] ReferenceTransformer: "provider[\"registry.terraform.io/cloudflare/cloudflare\"]" references: []
2022-10-11T10:01:09.619+0200 [DEBUG] ReferenceTransformer: "data.cloudflare_accounts.cf_account_testing (expand)" references: []
2022-10-11T10:01:09.619+0200 [DEBUG] ReferenceTransformer: "local.account_id (expand)" references: []
2022-10-11T10:01:09.619+0200 [DEBUG] pruneUnusedNodes: data.cloudflare_accounts.cf_account_testing (expand) is no longer needed, removing
2022-10-11T10:01:09.619+0200 [DEBUG] pruneUnusedNodes: local.account_id (expand) is no longer needed, removing
2022-10-11T10:01:09.619+0200 [DEBUG] pruneUnusedNodes: provider["registry.terraform.io/cloudflare/cloudflare"] is no longer needed, removing
2022-10-11T10:01:09.619+0200 [INFO]  backend/local: plan operation completed


Changes to Outputs:
  + account_id = "d41d8cd98f00b204e9800998ecf8427e"


You can apply this plan to save these new output values to the Terraform state, without changing any real infrastructure.


─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

The value got for account_id is wrong.

I've seen this GET /client/v4/accounts?name=Company+-+Testing HTTP/1.1
There are whitespaces before and after the character -

Shall I escape them somehow?

I had to use --data-encode to get the right account_id from de CF API using curl

 curl -sG "https://api.cloudflare.com/client/v4/accounts" --data-urlencode "name=Company - Testing" \
     -H "X-Auth-Email: email" \
     -H "X-Auth-Key:key" \
     -H "Content-Type: application/json" | jq .

Through curl I'm doing a request to same endpoint but using HTTP/2

> GET /client/v4/accounts?name=Company+-+Testing HTTP/2
> Host: api.cloudflare.com
> user-agent: curl/7.81.0
> accept: */*
> x-auth-email: email
> x-auth-key: key
> content-type: application/json

I also tried the data source with this but I'm still getting wrong account_id

data "cloudflare_accounts" "cf_account_testing" {
  name = urlencode("Company - Testing")
}

@jacobbednarz
Copy link
Member

the functionality here is working correctly for me. i think the issue is that you're referencing the resource ID, not the account ID (data.cloudflare_accounts.cf_account_testing.id). to get the account ID, you'll need data.cloudflare_accounts.cf_account_testing.accounts[0].id since the resource returns potentially multiple accounts.

the difference is mentioned on the docs page for the two fields and their intentions.

@jacobbednarz jacobbednarz closed this as not planned Won't fix, can't repro, duplicate, stale Oct 12, 2022
@jacobbednarz jacobbednarz added kind/support Categorizes issue or PR as related to user support. and removed kind/bug Categorizes issue or PR as related to a bug. triage/needs-information Indicates an issue needs more information in order to work on it. labels Oct 12, 2022
@ivanfavi
Copy link
Author

You're right! Thank you for your support on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/support Categorizes issue or PR as related to user support.
Projects
None yet
Development

No branches or pull requests

2 participants