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

Remove jsondecode function used in mocks examples #35249

Open
dancer1325 opened this issue May 28, 2024 · 1 comment
Open

Remove jsondecode function used in mocks examples #35249

dancer1325 opened this issue May 28, 2024 · 1 comment
Labels
documentation new new issue not yet triaged

Comments

@dancer1325
Copy link

Terraform Version

v1.7.0+

Affected Pages

https://developer.hashicorp.com/terraform/language/tests/mocking#overrides-syntax

What is the docs issue?

In the examples provided to support the explanation, you can find

# ./modules/s3_data/main.tf
variable "data_bucket_name" {
  type = string
}
data "aws_s3_object" "data_bucket" {
  bucket = var.data_bucket_name
  key    = "credentials.json"
}
output "data" {
  value = jsondecode(data.aws_s3_object.data_bucket.body)
}

Once you run terraform test you get an error in some of the previous tests defined something like

data.aws_s3_object.data_bucket.body is ....Call to function "jsondecode" failed: extraneous data after JSON object."

because 'data.aws_s3_object.data_bucket.body' is already a JSON string -> unneeded jsondecode

Proposal

I would suggest to remove jsondecode

variable "data_bucket_name" {
  type = string
}
data "aws_s3_object" "data_bucket" {
  bucket = var.data_bucket_name
  key    = "credentials.json"
}
output "data" {
  value = data.aws_s3_object.data_bucket.body
}

References

No response

@dancer1325 dancer1325 added documentation new new issue not yet triaged labels May 28, 2024
@crw
Copy link
Collaborator

crw commented Jun 3, 2024

Thanks for this report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation new new issue not yet triaged
Projects
None yet
Development

No branches or pull requests

2 participants