dtan4/terraforming

View on GitHub
lib/terraforming/template/tf/dynamo_db.erb

Summary

Maintainability
Test Coverage
<%- tables.each do |table| -%>
resource "aws_dynamodb_table" "<%= table.table_name -%>" {
    name = "<%= table.table_name -%>"
    read_capacity = <%= table.provisioned_throughput.read_capacity_units %>
    write_capacity = <%= table.provisioned_throughput.write_capacity_units %>
<%- table.key_schema.each do |key| -%>
    <%= key.key_type.downcase -%>_key = <%= key.attribute_name.inspect %>
<%- end %>
<%- table.attribute_definitions.each do |attribute| -%>
    attribute {
        name = "<%= attribute.attribute_name -%>"
        type = "<%= attribute.attribute_type -%>"
    }
<%- end -%>
<%- ttl_values(table).each do |attr| -%>
    ttl {
        attribute_name = <%= attr.inspect %>
        enabled = true
    }
<%- end -%>
<%- Array(table.global_secondary_indexes).each do |index| -%>
    global_secondary_index {
        name = "<%= index.index_name -%>"
        <%- index.key_schema.each do |key| -%>
        <%= key.key_type.downcase -%>_key = "<%= key.attribute_name -%>"
        <%- end -%>
        read_capacity = <%= index.provisioned_throughput.read_capacity_units %>
        write_capacity = <%= index.provisioned_throughput.write_capacity_units %>
        projection_type = "<%= index.projection.projection_type %>"
        <%- keys = index.projection.non_key_attributes -%>
        <%- if Array(keys).size > 0 -%>
        non_key_attributes = <%= keys.inspect -%>
        <%- end %>
    }
<%- end -%>
<%- Array(table.local_secondary_indexes).each do |index| -%>
    local_secondary_index {
        name = "<%= index.index_name -%>"
    <%- index.key_schema.each do |key| -%>
        <%- if key.key_type.downcase == "range" -%>
        <%= key.key_type.downcase -%>_key = "<%= key.attribute_name -%>"
        <%- end -%>
    <%- end -%>
        projection_type = "<%= index.projection.projection_type -%>"
        <%- keys = index.projection.non_key_attributes -%>
        <%- if Array(keys).size > 0 -%>
        non_key_attributes = <%= keys.inspect -%>
        <%- end %>
    }
<%- end -%>
<%- tags(table).each do |tag| -%>
    tags {
        <%= tag.key %> = "<%= tag.value -%>"
    }
<%- end -%>
<%- if table.stream_specification -%>
    stream_enabled = <%= table.stream_specification.stream_enabled %>
    stream_view_type = <%= table.stream_specification.stream_view_type.inspect %>
<%- end -%>
<%- if table.sse_description -%>
    server_side_encryption {
        enabled = true
    }
<%- end -%>
}
<%- end -%>