hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.74k stars 9.1k forks source link

[Bug]: cannot use cloudformation stack as a source for ressource group #28690

Open plouer opened 1 year ago

plouer commented 1 year ago

Terraform Core Version

1.3.7

AWS Provider Version

4.48.0

Affected Resource(s)

aws_resourcegroups_group

Expected Behavior

it should be possible to create a ressource group including all the ressources from a cloudformation stack like the following command :

aws resource-groups create-group \
    --name group_name \
    --description "description" \
    --resource-query '{"Type":"CLOUDFORMATION_STACK_1_0","Query":"{\"StackIdentifier\":\"stack_identifier\",\"ResourceTypeFilters\":[\"resource_type1\",\"resource_type2\"]}"}'

see : https://docs.aws.amazon.com/ARG/latest/userguide/gettingstarted-query.html#gettingstarted-query-stack-based

Actual Behavior

the current result is :

$ terraform plan
╷
│ Error: expected resource_query.0.type to be one of [TAG_FILTERS_1_0], got CLOUDFORMATION_STACK_1_0
│
│   with aws_resourcegroups_group.test,
│   on main.tf line 18, in resource "aws_resourcegroups_group" "test":
│   18:     type = "CLOUDFORMATION_STACK_1_0"
│

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

can be reproduce with the following code :

provider "aws" {
}

terraform {
}

resource "aws_resourcegroups_group" "test" {
  name = "test"
  description = "test"
  resource_query {
    query = jsonencode(
      {
        ResourceTypeFilters = [ "AWS::AllSupported",]
        StackIdentifier     = "STACK_ARN_GOES_HERE"
      }
    )
    type = "CLOUDFORMATION_STACK_1_0"
  }
}

Steps to Reproduce

to reproduce it you can run this :

provider "aws" {
}

terraform {
}

resource "aws_cloudformation_stack" "name" {
  name = "test-terraform-provisionned-stack"
  template_body = <<STACK
{
    "Resources" : {
      "s31": {
        "Type" : "AWS::S3::Bucket",
        "Properties" : {
          "BucketName" : "test-terraform-provisionned-stack-1",
          "Tags" : [
            {"Key": "Name", "Value": "test_terraform_provisionned_stack_1"}
          ]
        }
    },
      "s32": {
        "Type" : "AWS::S3::Bucket",
        "Properties" : {
          "BucketName" : "test-terraform-provisionned-stack-2",
          "Tags" : [
            {"Key": "Name", "Value": "test_terraform_provisionned_stack_2"}
          ]
        }
      }
    }
  }
STACK
}

resource "aws_resourcegroups_group" "test" {
  name = "test"
  description = "test"
  resource_query {
    query = jsonencode(
      {
        ResourceTypeFilters = [ "AWS::AllSupported",]
        StackIdentifier     = aws_cloudformation_stack.name.id
      }
    )
    type = "CLOUDFORMATION_STACK_1_0"
  }
}

Debug Output

the output I get is : _2023-01-05T14:55:41.600+0100 [DEBUG] Resource instance state not found for node "aws_resourcegroups_group.test", instance aws_resourcegroups_group.test 2023-01-05T14:55:41.600+0100 [DEBUG] ReferenceTransformer: "aws_resourcegroups_group.test" references: [] 2023-01-05T14:55:41.600+0100 [DEBUG] refresh: aws_resourcegroups_group.test: no state, so not refreshing 2023-01-05T14:55:41.601+0100 [ERROR] provider.terraform-provider-aws_v4.48.0_x5: Response contains error diagnostic: diagnostic_summary="expected resource_query.0.type to be one of [TAG_FILTERS_1_0], got CLOUDFORMATION_STACK_1_0" tf_proto_version=5.3 diagnostic_attribute=AttributeName("resource_query").ElementKeyInt(0).AttributeName("type") diagnostic_detail= @caller=github.com/hashicorp/terraform-plugin-go@v0.14.2/tfprotov5/internal/diag/diagnostics.go:55 tf_req_id=a92440e2-6f73-abf9-35c5-49b3e0ad6384 tf_resource_type=aws_resourcegroups_group tf_provider_addr=registry.terraform.io/hashicorp/aws tf_rpc=ValidateResourceTypeConfig @module=sdk.proto diagnostic_severity=ERROR timestamp=2023-01-05T14:55:41.601+0100 2023-01-05T14:55:41.602+0100 [ERROR] vertex "aws_resourcegroups_group.test" error: expected resource_query.0.type to be one of [TAG_FILTERS_1_0], got CLOUDFORMATION_STACK_1_0 2023-01-05T14:55:41.602+0100 [ERROR] vertex "aws_resourcegroups_group.test (expand)" error: expected resource_query.0.type to be one of [TAG_FILTERS_1_0], got CLOUDFORMATION_STACK_1_0 2023-01-05T14:55:41.603+0100 [INFO] backend/local: plan operation completed ╷ │ Error: expected resource_query.0.type to be one of [TAG_FILTERS_1_0], got CLOUDFORMATION_STACK_10 │

Panic Output

No response

Important Factoids

No response

References

the cli reference used :

Would you like to implement a fix?

None

github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

nhooey commented 9 months ago

Is there a workaround for this issue? Terraformer import set a bunch of resource_query variables to CLOUDFORMATION_STACK_1_0...