{
  "AWSTemplateFormatVersion" : "2010-09-09",
  "Description" : "Reference Identity Token Vending Machine 1.3",
  "Parameters" : {
    "AppName" : {
      "Type" : "String",
      "Description" : "App Name i.e. MyMobileAppName",
      "Default" : "MyMobileAppName",
      "AllowedPattern" : ".+",
      "ConstraintDescription" : "Input a valid App Name"
    }
  },
  "Resources" : {
    "IdentityTVMUser" : {
      "Type" : "AWS::IAM::User",
      "Properties" : {
        "Path" : "/",
        "Policies" : [ {
          "PolicyName" : "IdentityTVMPolicy",
          "PolicyDocument" : {
            "Statement" : [ {
              "Effect" : "Allow",
              "Action" : "sts:GetFederationToken",
              "Resource" : "*"
            }, {
              "Effect" : "Allow",
              "Action" : "iam:GetUser",
              "Resource" : "*"
            }, {
              "Effect" : "Allow",
              "Action" : "sdb:*",
              "Resource" : "*"
            }, {
              "Effect" : "Allow",
              "Action" : "dynamodb:*",
              "Resource" : "*"
            }, {
              "Effect" : "Allow",
              "Action" : "sqs:*",
              "Resource" : "*"
            }, {
              "Effect" : "Allow",
              "Action" : "s3:*",
              "Resource" : "*"
            }, {
              "Action" : "sns:*",
              "Effect" : "Allow",
              "Resource" : "*"
            } ]
          }
        } ]
      }
    },
    "IdentityTVMAccessKey" : {
      "Type" : "AWS::IAM::AccessKey",
      "Properties" : {
        "UserName" : {
          "Ref" : "IdentityTVMUser"
        }
      }
    },
    "IdentityTVMApplication" : {
      "Type" : "AWS::ElasticBeanstalk::Application",
      "Properties" : {
        "Description" : "Identity TVM",
        "ApplicationVersions" : [ {
          "VersionLabel" : "Version 1.3",
          "Description" : "https://github.com/amazonwebservices/aws-tvm-identity",
          "SourceBundle" : {
            "S3Bucket" : "tvm-identity",
            "S3Key" : "latest/IdentityTVM.war"
          }
        } ],
        "ConfigurationTemplates" : [ {
          "TemplateName" : "DefaultConfiguration",
          "Description" : "64bit Amazon Linux running Tomcat 7",
          "SolutionStackName" : "64bit Amazon Linux running Tomcat 7",
          "OptionSettings" : [ {
            "Namespace" : "aws:elasticbeanstalk:environment",
            "OptionName" : "EnvironmentType",
            "Value" : "SingleInstance"
          }, {
            "Namespace" : "aws:autoscaling:launchconfiguration",
            "OptionName" : "InstanceType",
            "Value" : "t1.micro"
          }, {
            "Namespace" : "aws:autoscaling:asg",
            "OptionName" : "MaxSize",
            "Value" : "1"
          }, {
            "Namespace" : " aws:elasticbeanstalk:application:environment",
            "OptionName" : "AWS_ACCESS_KEY_ID",
            "Value" : {
              "Ref" : "IdentityTVMAccessKey"
            }
          }, {
            "Namespace" : " aws:elasticbeanstalk:application:environment",
            "OptionName" : "AWS_SECRET_KEY",
            "Value" : {
              "Fn::GetAtt" : [ "IdentityTVMAccessKey", "SecretAccessKey" ]
            }
          }, {
            "Namespace" : " aws:elasticbeanstalk:application:environment",
            "OptionName" : "PARAM1",
            "Value" : {
              "Ref" : "AppName"
            }
          } ]
        } ]
      }
    },
    "IdentityTVMEnvironment" : {
      "Type" : "AWS::ElasticBeanstalk::Environment",
      "Properties" : {
        "ApplicationName" : {
          "Ref" : "IdentityTVMApplication"
        },
        "Description" : "Identity TVM Environment",
        "TemplateName" : "DefaultConfiguration",
        "VersionLabel" : "Version 1.3"
      }
    }
  },
  "Outputs" : {
    "URL" : {
      "Value" : {
        "Fn::Join" : [ "", [ "http://", {
          "Fn::GetAtt" : [ "IdentityTVMEnvironment", "EndpointURL" ]
        } ] ]
      },
      "Description" : "URL for the Identity Token Vending Machine"
    }
  }
}