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

Convert: Keep sort order of attributes in input HCL #2688

Open
ansgarm opened this issue Mar 3, 2023 · 0 comments
Open

Convert: Keep sort order of attributes in input HCL #2688

ansgarm opened this issue Mar 3, 2023 · 0 comments
Labels
enhancement New feature or request feature/convert priority/awaiting-more-evidence Lowest priority. Unlikely to be worked on unless/until it gets a lot more upvotes.

Comments

@ansgarm
Copy link
Member

ansgarm commented Mar 3, 2023

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

Description

When using cdktf convert to translate HCL to CDKTF languages, the order of the properties is sorted alphabetically.
However, this order might have a reason, especially in the case of documentation examples. In the example given below the name of the table is moved below the attributes whereas the more natural place to put it, would be at the top of the resource.

This is only stylistic and does not change the behavior, but from my experience most Terraform config tends to put "global" properties such as "name" in this example at the top.

Example

Given the following HCL example
resource "aws_dynamodb_table" "basic-dynamodb-table" {
  name           = "GameScores"
  billing_mode   = "PROVISIONED"
  read_capacity  = 20
  write_capacity = 20
  hash_key       = "UserId"
  range_key      = "GameTitle"

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

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

  attribute {
    name = "TopScore"
    type = "N"
  }

  ttl {
    attribute_name = "TimeToExist"
    enabled        = false
  }

  global_secondary_index {
    name               = "GameTitleIndex"
    hash_key           = "GameTitle"
    range_key          = "TopScore"
    write_capacity     = 10
    read_capacity      = 10
    projection_type    = "INCLUDE"
    non_key_attributes = ["UserId"]
  }

  tags = {
    Name        = "dynamodb-table-1"
    Environment = "production"
  }
}

cdktf convert --language typescript --provider 'hashicorp/aws@~>4.53.0' returns:

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.dynamodbTable.DynamodbTable(this, "basic-dynamodb-table", {
  attribute: [
    {
      name: "UserId",
      type: "S",
    },
    {
      name: "GameTitle",
      type: "S",
    },
    {
      name: "TopScore",
      type: "N",
    },
  ],
  billingMode: "PROVISIONED",
  globalSecondaryIndex: [
    {
      hashKey: "GameTitle",
      name: "GameTitleIndex",
      nonKeyAttributes: ["UserId"],
      projectionType: "INCLUDE",
      rangeKey: "TopScore",
      readCapacity: 10,
      writeCapacity: 10,
    },
  ],
  hashKey: "UserId",
  name: "GameScores",
  rangeKey: "GameTitle",
  readCapacity: 20,
  tags: {
    Environment: "production",
    Name: "dynamodb-table-1",
  },
  ttl: {
    attributeName: "TimeToExist",
    enabled: false,
  },
  writeCapacity: 20,
});

References

@ansgarm ansgarm added enhancement New feature or request feature/convert labels Mar 3, 2023
@xiehan xiehan added the priority/important-longterm Medium priority, to be worked on within the following 1-2 business quarters. label Mar 9, 2023
@rhatri rhatri added priority/awaiting-more-evidence Lowest priority. Unlikely to be worked on unless/until it gets a lot more upvotes. and removed priority/important-longterm Medium priority, to be worked on within the following 1-2 business quarters. labels Jul 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature/convert priority/awaiting-more-evidence Lowest priority. Unlikely to be worked on unless/until it gets a lot more upvotes.
Projects
None yet
Development

No branches or pull requests

3 participants