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

Creating aws_dynamodb_table with replicas attribute does not modify state information for replicas #15409

Closed
asheynkmantyler opened this issue Sep 30, 2020 · 6 comments · Fixed by #29269
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/dynamodb Issues and PRs that pertain to the dynamodb service.
Milestone

Comments

@asheynkmantyler
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction 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

Terraform CLI and Terraform AWS Provider Version

Terraform v0.13.3

  • provider registry.terraform.io/hashicorp/aws v3.8.0

Affected Resource(s)

  • aws_dynamo_db

Terraform Configuration Files

Terraform script:

provider "aws" {
    region = "us-east-1"
    shared_credentials_file=####
    profile = ###
    alias = "us-east-1"
}
resource "aws_dynamodb_table" "foo" {
  provider = aws.us-east-1
  name             = "test-foo"
  hash_key         = "TestTableHashKey"
  billing_mode     = "PAY_PER_REQUEST"
  stream_enabled   = true
  stream_view_type = "NEW_AND_OLD_IMAGES"

  attribute {
    name = "TestTableHashKey"
    type = "S"
  }

  replica {
    region_name = "us-east-2"
  }
}

Terraform state file:

{
  "version": 4,
  "terraform_version": "0.13.3",
  "serial": 50,
  "lineage": "9fe88cbb-1769-e3b6-7cd8-377f5fc5ca13",
  "outputs": {},
  "resources": [
    {
      "mode": "managed",
      "type": "aws_dynamodb_table",
      "name": "foo2",
      "provider": "provider[\"registry.terraform.io/hashicorp/aws\"].us-east-1",
      "instances": [
        {
          "schema_version": 1,
          "attributes": {
            "arn": "arn:aws:dynamodb:us-east-1:#####:table/test-foo",
            "attribute": [
              {
                "name": "TestTableHashKey",
                "type": "S"
              }
            ],
            "billing_mode": "PAY_PER_REQUEST",
            "global_secondary_index": [],
            "hash_key": "TestTableHashKey",
            "id": "test-foo",
            "local_secondary_index": [],
            "name": "test-foo",
            "point_in_time_recovery": [
              {
                "enabled": false
              }
            ],
            "range_key": null,
            "read_capacity": 0,
            "replica": [
              {
                "region_name": "us-east-2"
              }
            ],
            "server_side_encryption": [],
            "stream_arn": "arn:aws:dynamodb:us-east-1:####:table/test-foo/stream/2020-09-30T19:17:44.238",
            "stream_enabled": true,
            "stream_label": "2020-09-30T19:17:44.238",
            "stream_view_type": "NEW_AND_OLD_IMAGES",
            "tags": null,
            "timeouts": null,
            "ttl": [
              {
                "attribute_name": "",
                "enabled": false
              }
            ],
            "write_capacity": 0
          },
          "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwLCJ1cGRhdGUiOjM2MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjEifQ=="
        }
      ]
    }
  ]
}

Expected Behavior

Since AWS actually creates a table in the region specified in "replicas" I expected state file to contain information block about dynamodb table in replicated region. Otherwise that part of resource cannot be managed via terraform without importing it manually.

Actual Behavior

Terraform state does not contain information about replica dynamo db.

Steps to Reproduce

  1. terraform apply

Important Factoids

It works appropriately with DynamoDB tables version 2017, using example provided in aws_dynamodb_global_table documentation. It doesn't with aws_dynamodb global tables version 2019.

@ghost ghost added the service/dynamodb Issues and PRs that pertain to the dynamodb service. label Sep 30, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Sep 30, 2020
@pbzdyl
Copy link

pbzdyl commented Oct 9, 2020

Hi @asheynkmantyler,

I'm curious - how would you like to use the replica information in the state? I'm asking as I have an issue where I would like to obtain ARNs of the replica tables (e.g. so I can setup IAM policies for them) and/or replica tables streams ARNs and currently I have to manually assemble ARNs for replica tables, e.g.:

# default region is eu-west-1
resource "aws_dynamodb_table" "my-table" {
  name             = "my-table"
  replica {
    region_name = "eu-central-1"
  }
  }
}

locals {
  replicas-arns = [for replica_region in aws_dynamodb_table.my-table.replica[*].region_name : replace(aws_dynamodb_table.my-table.arn, data.aws_region.current.name, replica_region)]
}

If your issue is not about accessing attributes of the replica tables (like in my example above) then I guess I need to open separate ticket for use case.

@asheynkmantyler
Copy link
Author

My issue arose when we tried to use same terraform plan for production and dr. When we ran the plan for the DR, it returned ResourceAlreadyExists error, because it was trying to create DynamoDB table in "dr" region, but from AWS' perspective table was already there because of the replica configuration.

@breathingdust breathingdust added enhancement Requests to existing resources that expand the functionality or scope. and removed needs-triage Waiting for first response or review from a maintainer. labels Sep 16, 2021
@vicky275
Copy link

@asheynkmantyler How did you resolve this, I am facing same issue not able to get the replicated tables state in statefile.

@habouche
Copy link

habouche commented Dec 7, 2022

@asheynkmantyler have you succeeded resolving this issue , I'm facing the same problem where I need to retrieve the stream_arn for the replica tables

@github-actions
Copy link

github-actions bot commented Feb 9, 2023

This functionality has been released in v4.54.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
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 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/dynamodb Issues and PRs that pertain to the dynamodb service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants