# Path: stacker_blueprints/policies.py
# def dynamodb_autoscaling_policy(tables):
#     """Policy to allow AutoScaling a list of DynamoDB tables."""
#     return Policy(
#         Statement=[
#             Statement(
#                 Effect=Allow,
#                 Resource=dynamodb_arns(tables),
#                 Action=[
#                     dynamodb.DescribeTable,
#                     dynamodb.UpdateTable,
#                 ]
#             ),
#             Statement(
#                 Effect=Allow,
#                 Resource=['*'],
#                 Action=[
#                     cloudwatch.PutMetricAlarm,
#                     cloudwatch.DescribeAlarms,
#                     cloudwatch.GetMetricStatistics,
#                     cloudwatch.SetAlarmState,
#                     cloudwatch.DeleteAlarms,
#                 ]
#             ),
#         ]
#     )


from stacker.blueprints.base import Blueprint
from stacker.blueprints.variables.types import TroposphereType
from troposphere import (
    iam,
    applicationautoscaling as aas,
    dynamodb,
    Ref,
    GetAtt,
    Output,
    Sub,
)
from .policies import (
    dynamodb_autoscaling_policy,
)
from awacs.helpers.trust import make_simple_assume_policy
                target: 80.0

            - table: test-group-table
              read:
                min: 10
                max: 50
                scale-in-cooldown: 180
                scale-out-cooldown: 180
              write:
                max: 25
    """
    VARIABLES = {
        "AutoScalingConfigs": {
            "type": list,
            "description": "A list of dicts, each of which represent "
                           "a DynamoDB AutoScaling Configuration.",
        }
    }

    # reference: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html#cfn-dynamodb-table-examples-application-autoscaling # noqa
    def create_scaling_iam_role(self):
        assumerole_policy = get_application_autoscaling_assumerole_policy()
        return self.template.add_resource(
            iam.Role(
                "Role",
                Policies=[
                    iam.Policy(
                        PolicyName=Sub(
                            "${AWS::StackName}-dynamodb-autoscaling"
                        ),

# Path: stacker_blueprints/policies.py
# def dynamodb_autoscaling_policy(tables):
#     """Policy to allow AutoScaling a list of DynamoDB tables."""
#     return Policy(
#         Statement=[
#             Statement(
#                 Effect=Allow,
#                 Resource=dynamodb_arns(tables),
#                 Action=[
#                     dynamodb.DescribeTable,
#                     dynamodb.UpdateTable,
#                 ]
#             ),
#             Statement(
#                 Effect=Allow,
#                 Resource=['*'],
#                 Action=[
#                     cloudwatch.PutMetricAlarm,
#                     cloudwatch.DescribeAlarms,
#                     cloudwatch.GetMetricStatistics,
#                     cloudwatch.SetAlarmState,
#                     cloudwatch.DeleteAlarms,
#                 ]
#             ),
#         ]
#     )


# Path: stacker_blueprints/dynamodb.py
from stacker.blueprints.base import Blueprint
from stacker.blueprints.variables.types import TroposphereType
from troposphere import (
    iam,
    applicationautoscaling as aas,
    dynamodb,
    Ref,
    GetAtt,
    Output,
    Sub,
)
from .policies import (
    dynamodb_autoscaling_policy,
)
from awacs.helpers.trust import make_simple_assume_policy

                target: 80.0

            - table: test-group-table
              read:
                min: 10
                max: 50
                scale-in-cooldown: 180
                scale-out-cooldown: 180
              write:
                max: 25
    """
    VARIABLES = {
        "AutoScalingConfigs": {
            "type": list,
            "description": "A list of dicts, each of which represent "
                           "a DynamoDB AutoScaling Configuration.",
        }
    }

    # reference: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html#cfn-dynamodb-table-examples-application-autoscaling # noqa
    def create_scaling_iam_role(self):
        assumerole_policy = get_application_autoscaling_assumerole_policy()
        return self.template.add_resource(
            iam.Role(
                "Role",
                Policies=[
                    iam.Policy(
                        PolicyName=Sub(
                            "${AWS::StackName}-dynamodb-autoscaling"
                        ),

                        PolicyDocument=dynamodb_autoscaling_policy(self.tables)