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.84k stars 9.19k forks source link

[Bug]: aws_opensearchserverless_security_policy provider inconsistency #39527

Closed crsuarez closed 1 month ago

crsuarez commented 1 month ago

Terraform Core Version

1.7.0

AWS Provider Version

5.69.0

Affected Resource(s)

Expected Behavior

aws_opensearchserverless_security_policy.encryption_policy applied succesfully

Actual Behavior

When running terraform apply ...

image

Relevant Error/Panic Output Snippet

aws_opensearchserverless_security_policy.encryption_policy: Modifying... [id=xxxx-encryption-policy]
╷
│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to
│ aws_opensearchserverless_security_policy.encryption_policy, provider
│ "provider[\"registry.terraform.io/hashicorp/aws\"]" produced an unexpected
│ new value: .policy_version: was cty.StringVal("MTcyNzQ4ODE3NTY4OF8x"), but
│ now cty.StringVal("MTcyNzU0NDY2Nzc4MF8y").
│ 
│ This is a bug in the provider, which should be reported in the provider's
│ own issue tracker.

Terraform Configuration Files

main.tf


# Create the OpenSearch Serverless collection
resource "aws_opensearchserverless_collection" "this" {
  name        = var.oass_collection_name
  description = var.oass_collection_desc
  type        = var.oass_collection_type
  tags        = module.this.tags
  depends_on = [
    aws_opensearchserverless_security_policy.network_policy,
    aws_opensearchserverless_security_policy.encryption_policy
  ]
}

resource "aws_opensearchserverless_security_policy" "network_policy" {
  name        = var.oass_network_security_policy_name
  description = var.oass_collection_desc
  type        = "network"

  policy = jsonencode([
    {
      Rules = [
        {
          ResourceType = "collection",
          Resource     = ["collection/${var.oass_collection_name}"]
        }
      ],
      AllowFromPublic = true
    }
  ])
}

resource "aws_opensearchserverless_security_policy" "encryption_policy" {
  name        = var.oass_encryption_policy_name
  description = "Encryption policy using AWS owned key"
  type        = "encryption"

  policy = jsonencode({
    Rules = [
      {
        ResourceType = "collection",
        Resource     = ["collection/${var.oass_collection_name}"]
      }
    ],
    AWSOwnedKey = true
  })
}

resource "aws_opensearchserverless_access_policy" "data_access_policy" {
  name        = var.oass_data_access_policy_name
  description = var.oass_data_access_policy_desc
  type        = "data"

  policy = jsonencode([
    {
      Version = "2012-10-17"
      Statement = [
        {
          Effect = "Allow",
          Principal = {
            AWS = "${var.kb_role_arn}"
          },
          Action   = "aoss:*",
          Resource = "arn:aws:aoss:${var.region}:${var.id_account}:collection/${aws_opensearchserverless_collection.this.id}/*"
        }
      ]
    }
  ])
}

resource "awscc_bedrock_knowledge_base" "kb_bedrock" {
  provider    = awscc.add
  name        = var.name
  description = var.kb_description
  role_arn    = var.kb_role_arn

  storage_configuration = {
    type = "OPENSEARCH_SERVERLESS"
    opensearch_serverless_configuration = {
      collection_arn    = aws_opensearchserverless_collection.this.arn
      vector_index_name = var.vector_index_name
      field_mapping = {
        metadata_field = var.metadata_field
        text_field     = var.text_field
        vector_field   = var.vector_field
      }
    }
  }
  knowledge_base_configuration = var.knowledge_base_configuration

  tags = module.this.tags
}

Steps to Reproduce

terraform init terraform plan terraform apply

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

github-actions[bot] commented 1 month ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

acwwat commented 1 month ago

The problem can be reproduced by changing something in policy and applying the config to trigger an update. The aws_opensearchserverless_lifecycle_policy resource also has the same issue.

github-actions[bot] commented 1 month ago

[!WARNING] This issue has been closed, meaning that any additional comments are hard for our team to see. Please assume that the maintainers will not see them.

Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed.

github-actions[bot] commented 1 month ago

This functionality has been released in v5.70.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!

github-actions[bot] commented 1 week ago

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.