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

Data sources that return lists throw an error when target resources do not exist #2225

Open
YutaHig opened this issue Feb 28, 2025 · 0 comments

Comments

@YutaHig
Copy link

YutaHig commented Feb 28, 2025

Community Note

  • Please vote on this issue by adding a 👍 [reaction](https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
  • The resources and data sources in this provider are generated from the CloudFormation schema, so they can only support the actions that the underlying schema supports. For this reason submitted bugs should be limited to defects in the generation and runtime code of the provider. Customizing behavior of the resource, or noting a gap in behavior are not valid bugs and should be submitted as enhancements to AWS via the CloudFormation Open Coverage Roadmap.

Terraform CLI and Terraform AWS Cloud Control Provider Version

Terraform v1.11.0
on darwin_arm64

Affected Resource(s)

  • data.awscc_xxxxxs

All data sources which return list.

Terraform Configuration Files

terraform {
  required_providers {
    awscc = {
      source  = "hashicorp/awscc"
      version = "~> 1.30.0"
    }
  }
}

provider "awscc" {
  region = "ap-northeast-1"
}

# Any data sources that retrieves resources not exist in the target AWS account.
data "awscc_amplify_apps" "all" {}

Debug Output

Panic Output

Expected Behavior

A data source that returns multiple resources will return an empty list if the target resource does not exist.

For example, in the case of the aws provider, it behaves as follows:

# Any data sources that retrieves resources not exist in the target AWS account.
data "aws_db_instances" "all" {}

output "aws_db_instances" {
  value = data.aws_db_instances.all
}
❯ terraform apply --auto-approve
data.aws_db_instances.all: Reading...
data.aws_db_instances.all: Read complete after 0s [id=ap-northeast-1]

Changes to Outputs:
  + aws_db_instances = {
      + filter               = null
      + id                   = "ap-northeast-1"
      + instance_arns        = []
      + instance_identifiers = []
      + tags                 = null
    }

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

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

aws_instances = {
  "filter" = toset(null) /* of object */
  "id" = "ap-northeast-1"
  "instance_arns" = tolist([])
  "instance_identifiers" = tolist([])
  "tags" = tomap(null) /* of string */
}

Actual Behavior

If the data source's target does not exist in the target AWS account, it will result in an error.
So it is not possible to use the data resource's results for conditional branching.

❯ terraform apply
data.awscc_amplify_apps.all: Reading...
╷
│ Error: AWS SDK Go Service Operation Unsuccessful
│ 
│   with data.awscc_amplify_apps.all,
│   on terraform.tf line 5, in data "awscc_amplify_apps" "all":
│   5: data "awscc_amplify_apps" "all" {}
│ 
│ Calling CloudControl service ListResources operation returned: Empty result

Steps to Reproduce

  1. terraform plan

Important Factoids

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant