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

Terraform seems not to support multiple attributes in a DynamoDB key schema #556

Closed
hashibot opened this issue Jun 13, 2017 · 11 comments
Closed
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/dynamodb Issues and PRs that pertain to the dynamodb service.

Comments

@hashibot
Copy link

hashibot commented Jun 13, 2017

This issue was originally opened by @jgryszko as hashicorp/terraform#12229. It was migrated here as part of the provider split. The original body of the issue is below.


Hi,

It looks like multiple attributes are not supported for dynamodb key schema so far.

Looking at the source, only hash_key is included in the key schema.

resource_aws_dynamodb_table.go:

hash_key_name := d.Get("hash_key").(string)
	keyschema := []*dynamodb.KeySchemaElement{
		{
			AttributeName: aws.String(hash_key_name),
			KeyType:       aws.String("HASH"),
		},
	}

Are there plans to change this in near future?
Best,
Janusz

@hashibot hashibot added the bug Addresses a defect in current functionality. label Jun 13, 2017
@thiagonache
Copy link

Why should we declare schema in terraform? Dynamodb is schemaless, it doesn't matter.

@jgryszko
Copy link

@thiagonache, It's not about general schema. The key schema defines, which attributes are part of the primary key.

A primary key can either be a single-attribute partition key or a composite partition-sort key. A single attribute partition primary key could be, for example, “UserID”. This would allow you to quickly read and write data for an item associated with a given user ID.
See https://aws.amazon.com/dynamodb/faqs/

@thiagonache
Copy link

gotcha... combination of range key + hash key. I haven't notice that....

@thiagonache
Copy link

thiagonache commented Jul 30, 2017

resource "aws_dynamodb_table" "mytable" {
  name           = "mytable"
  read_capacity  = 5
  write_capacity = 5
  hash_key       = "Id"
  range_key      = "Timestamp"

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

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

  tags {
    Name        = "mytable"
    Environment = "dev"
    Terraform   = "yes"
  }
}

does it not work for you?

@grubernaut grubernaut added the waiting-response Maintainers are waiting on response from community or contributor. label Jul 31, 2017
@Ninir
Copy link
Contributor

Ninir commented Aug 28, 2017

Hi @jgryszko

Were you able to replicate @thiagonache 's configuration and confirm whether it works?
Would like to close this one since it seems like a non-bug to me.

Thanks! :)

@visit1985
Copy link
Contributor

visit1985 commented Nov 18, 2017

@Ninir I think you can have multiple range keys in a schema, but range_key is for a single value.

@paddycarver paddycarver removed the waiting-response Maintainers are waiting on response from community or contributor. label Nov 21, 2017
@radeksimko radeksimko added question A question about existing functionality; most questions are re-routed to discuss.hashicorp.com. service/dynamodb Issues and PRs that pertain to the dynamodb service. and removed bug Addresses a defect in current functionality. labels Jan 22, 2018
@radeksimko radeksimko added enhancement Requests to existing resources that expand the functionality or scope. and removed question A question about existing functionality; most questions are re-routed to discuss.hashicorp.com. labels Jan 29, 2018
@MichaelDeCorte
Copy link

while correct, it isn't required to define the scheme, the option should exist and the documentation suggests that it is possible

@Mohitg06
Copy link

I still see this issue while using Terraform v0.11.8

@MarkVLK
Copy link

MarkVLK commented Oct 6, 2018

Likewise, with the following configuration

resource "aws_dynamodb_table" "dynamodb_table" {
  name           = "Asset_DB_TF"
  hash_key       = "Product"
  read_capacity  = 1
  write_capacity = 1

  server_side_encryption {
    enabled = true
  }

  attribute = [{
    name = "Product"
    type = "S"
  }, {
    name = "Contact"
    type = "S"
  }, {
    name = "Deployed"
    type = "S"
  }, {
    name = "Resource ID"
    type = "S"
  }, {
    name = "Version"
    type = "S"
  }]
}

I'm getting

aws_dynamodb_table.dynamodb_table: All attributes must be indexed. Unused attributes: ["Contact" "Resource ID" "Deployed" "Version"]

@Ninir
Copy link
Contributor

Ninir commented Jun 6, 2019

Hey folks,

Circling back to that one, let me offer a few answers:

I think you can have multiple range keys in a schema, but range_key is for a single value.
@visit1985 the primary key is either a hash key or a hash key + sort key. It is the only thing for the default index.
However, if you add another index, you can add another primary key.

@MarkVLK regarding your issue, this is expected: the fields that are not included in the primary key can't be set as non-key schema fields. Look at the example from the Terraform documentation: there are 3 attributes defined, 2 are for the main primary key, the last one is for the global index.

@jgryszko the code I see as of today is including both the hash and range keys.

I will now close this issue. Please comment if you think there still is an issue.

@Ninir Ninir closed this as completed Jun 6, 2019
@ghost
Copy link

ghost commented Nov 3, 2019

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Nov 3, 2019
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

No branches or pull requests