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

[Bug]: Provider Crashes While Importing Cloudsearch Resource #35884

Closed
i-ate-a-vm opened this issue Feb 19, 2024 · 4 comments · Fixed by #35900
Closed

[Bug]: Provider Crashes While Importing Cloudsearch Resource #35884

i-ate-a-vm opened this issue Feb 19, 2024 · 4 comments · Fixed by #35900
Labels
bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. service/cloudsearch Issues and PRs that pertain to the cloudsearch service. service/iam Issues and PRs that pertain to the iam service.
Milestone

Comments

@i-ate-a-vm
Copy link

i-ate-a-vm commented Feb 19, 2024

Terraform Core Version

1.5.5

AWS Provider Version

5.37.0

Affected Resource(s)

aws_cloudsearch_domain

Expected Behavior

The Cloudsearch resource I created through a module with a dynamic block for the index_field should be capable of importing an existing Cloudsearch domain.

Actual Behavior

The AWS provider crashes before the import can complete successfully.

Relevant Error/Panic Output Snippet

╷
│ Error: Request cancelled
│ 
│ The plugin.(*GRPCProvider).ReadResource request was cancelled.
╵


Stack trace from the terraform-provider-aws_v5.37.0_x5 plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x10d00fecc]

goroutine 385 [running]:
github.com/hashicorp/terraform-provider-aws/internal/service/cloudsearch.flattenIndexFieldStatus({0x14003f10f80?, 0x14004197cb0?, {}})
        github.com/hashicorp/terraform-provider-aws/internal/service/cloudsearch/domain.go:1293 +0x232c
github.com/hashicorp/terraform-provider-aws/internal/service/cloudsearch.flattenIndexFieldStatuses({0x14003f74f00?, 0x1c, 0x14003d6b830?})
        github.com/hashicorp/terraform-provider-aws/internal/service/cloudsearch/domain.go:1392 +0xb0
github.com/hashicorp/terraform-provider-aws/internal/service/cloudsearch.resourceDomainRead({0x113600b68, 0x14003d6b830}, 0x14000c23980, {0x1133fe7e0?, 0x14000808000?})
        github.com/hashicorp/terraform-provider-aws/internal/service/cloudsearch/domain.go:332 +0x12c0
github.com/hashicorp/terraform-provider-aws/internal/provider.New.(*wrappedResource).Read.interceptedHandler[...].func9(0x0?, {0x1133fe7e0?, 0x14000808000?})
        github.com/hashicorp/terraform-provider-aws/internal/provider/intercept.go:112 +0x1d4
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0x113600b68?, {0x113600b68?, 0x14003d6aa50?}, 0xd?, {0x1133fe7e0?, 0x14000808000?})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.32.0/helper/schema/resource.go:790 +0x64
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).RefreshWithoutUpgrade(0x1400106a9a0, {0x113600b68, 0x14003d6aa50}, 0x14003d58b60, {0x1133fe7e0, 0x14000808000})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.32.0/helper/schema/resource.go:1089 +0x430
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadResource(0x14003295fc8, {0x113600b68?, 0x14003d6a960?}, 0x14005a79540)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.32.0/helper/schema/grpc_provider.go:666 +0x3e4
github.com/hashicorp/terraform-plugin-mux/tf5muxserver.(*muxServer).ReadResource(0x113600ba0?, {0x113600b68?, 0x14003d6a660?}, 0x14005a79540)
        github.com/hashicorp/terraform-plugin-mux@v0.14.0/tf5muxserver/mux_server_ReadResource.go:35 +0x184
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ReadResource(0x140009719a0, {0x113600b68?, 0x14003d4fc80?}, 0x14003d32900)
        github.com/hashicorp/terraform-plugin-go@v0.21.0/tfprotov5/tf5server/server.go:774 +0x3c4
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadResource_Handler({0x1131c0e20?, 0x140009719a0}, {0x113600b68, 0x14003d4fc80}, 0x14000c23380, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.21.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:482 +0x164
google.golang.org/grpc.(*Server).processUnaryRPC(0x140013aa000, {0x113600b68, 0x14003d4fbf0}, {0x11362e758, 0x14001bdb1e0}, 0x14003d5d200, 0x14001cee060, 0x11aeb5728, 0x0)
        google.golang.org/grpc@v1.61.0/server.go:1385 +0xb8c
google.golang.org/grpc.(*Server).handleStream(0x140013aa000, {0x11362e758, 0x14001bdb1e0}, 0x14003d5d200)
        google.golang.org/grpc@v1.61.0/server.go:1796 +0xc4c
google.golang.org/grpc.(*Server).serveStreams.func2.1()
        google.golang.org/grpc@v1.61.0/server.go:1029 +0x8c
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 28
        google.golang.org/grpc@v1.61.0/server.go:1040 +0x150

Error: The terraform-provider-aws_v5.37.0_x5 plugin crashed!

Terraform Configuration Files

Module main.tf file:

data "aws_iam_policy_document" "cloudsearch_access_policy" {
  statement {
    sid    = "search_only"
    effect = "Allow"

    principals {
      type        = "AWS"
      identifiers = ["*"]
    }

    actions = [
      "cloudsearch:search",
      "cloudsearch:suggest",
    ]
  }
}

resource "aws_cloudsearch_domain_service_access_policy" "access_policy" {
  domain_name   = aws_cloudsearch_domain.domain.id
  access_policy = data.aws_iam_policy_document.cloudsearch_access_policy.json
}

resource "aws_cloudsearch_domain" "domain" {
  name = var.domain_name

  scaling_parameters {
    desired_instance_type = var.instance_type
  }

  endpoint_options {
    enforce_https = var.enforce_https
  }

  dynamic "index_field" {
    for_each = var.indexes
    content {
      name            = index_field.value["name"]
      type            = index_field.value["type"]
      search          = index_field.value["search"]
      return          = index_field.value["return"]
      sort            = index_field.value["sort"]
      highlight       = index_field.value["highlight"]
      analysis_scheme = index_field.value["analysis_scheme"]
    }
  }
}

Module variables.tf file:

variable "domain_name" {
  description = "The CloudSearch domain name"
  type        = string
}

variable "instance_type" {
  description = "Size of the instance to use for the CloudSearch domain"
  type        = string
  default     = "search.large"
}

variable "indexes" {
  description = "Indexes to use on the CloudSearch domain"
  #type        = list(map)
}

variable "enforce_https" {
  description = "Whether to enforce HTTPS on the domain"
  type = bool
  default = false
}

variable "multi_az" {
  description = "Whether the domain should be hosted in multiple AZs"
  type = bool
  default = false
}

File calling the module:

module "prod" {
  source = "../../modules/cloudsearch"

  domain_name = "prod"

  indexes = [
    {
      name            = "choices"
      type            = "text"
      search          = true
      return          = false
      sort            = false
      highlight       = false
      analysis_scheme = "_en_default_"
    },
  ]
}

Steps to Reproduce

Run terraform import module.prod.aws_cloudsearch_domain.domain prod in the folder where the calling file is defined.

Debug Output

No response

Panic Output

No response

Important Factoids

The existing CloudSearch domain has over 30 indexes. I was planning to import the resource first so that I could make sure the existing index was lining up correctly with the values that I fed into the module. Other AWS resources can import successfully like this, so I thought this would work.

I also removed the dynamic block and tried hardcoding an index_field value into the module instead with real values used on the live resource, and experienced the same error. I suspect the error originates from a mismatched number of defined indexes in the code compared to how many indexes are on the live cloudsearch domain, but would have expected the provider to still import the resource and attempt to delete any undefined indexes on the live resource.

UPDATE: Even when I added all the expected indexes and confirmed that the number of indexes defined in Terraform match up with the indexes on the live resource, the provider still crashes.

References

No response

Would you like to implement a fix?

None

@i-ate-a-vm i-ate-a-vm added the bug Addresses a defect in current functionality. label Feb 19, 2024
@github-actions github-actions bot added crash Results from or addresses a Terraform crash or kernel panic. service/cloudsearch Issues and PRs that pertain to the cloudsearch service. service/iam Issues and PRs that pertain to the iam service. labels Feb 19, 2024
Copy link

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • 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.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@terraform-aws-provider terraform-aws-provider bot added the needs-triage Waiting for first response or review from a maintainer. label Feb 19, 2024
@jar-b jar-b removed the needs-triage Waiting for first response or review from a maintainer. label Feb 20, 2024
@jar-b
Copy link
Member

jar-b commented Feb 20, 2024

The switch/case in this flattener is missing a nil check on the options variable:

case types.IndexFieldTypeLiteralArray:
options := field.LiteralArrayOptions
if v := options.DefaultValue; v != nil {
tfMap["default_value"] = aws.ToString(v)
}

Copy link

This functionality has been released in v5.38.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. service/cloudsearch Issues and PRs that pertain to the cloudsearch service. service/iam Issues and PRs that pertain to the iam service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants