Skip to content

Instantly share code, notes, and snippets.

@rgarcia
Last active February 5, 2016 01:29
Show Gist options
  • Save rgarcia/4c85473fa2aeb61f79fa to your computer and use it in GitHub Desktop.
Save rgarcia/4c85473fa2aeb61f79fa to your computer and use it in GitHub Desktop.
OpenVPN
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "Launch OpenVPN Server in an existing Virtual Private Cloud (VPC).",
"Parameters" : {
"InstanceType" : {
"Description" : "Instance type for OpenVPN Server",
"Type" : "String",
"Default" : "t2.micro",
"AllowedValues" : [ "t2.micro","t2.small","t2.medium","m3.medium","m3.large","m3.xlarge","m3.2xlarge"],
"ConstraintDescription" : "must be a valid EC2 instance type."
},
"SubnetId" : {
"Type" : "String",
"Description" : "The ID of a public subnet in your VPC",
"Type" : "AWS::EC2::Subnet::Id"
},
"AdminUser" : {
"Type" : "String",
"Description" : "OpenVPN admin account name",
"Default" : "openvpn"
},
"AdminPassword" : {
"Type" : "String",
"Description" : "OpenVPN admin account initial password",
"NoEcho" : "true",
"MinLength": "8",
"MaxLength": "32",
"ConstraintDescription" : "must contain at least 8 characters."
},
"AdminCidrIp" : {
"Type" : "String",
"Description" : "Source cidr block where the admin will be administrating the OpenVPN Server",
"Default" : "0.0.0.0/0"
},
"KeyName" : {
"Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances",
"Type" : "AWS::EC2::KeyPair::KeyName",
"Default" : "schen"
},
"VpcId": {
"Description": "The ID of a VPC hosting a NAT instance",
"Type": "AWS::EC2::VPC::Id"
}
},
"Mappings" : {
"RegionMap" : {
"us-west-2" : { "AMI" : "ami-76f4ef17" }
}
},
"Resources" : {
"SecurityGroup" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"VpcId" : { "Ref" : "VpcId" },
"GroupDescription" : "Security group for OpenVPN Server",
"SecurityGroupIngress" : [
{"IpProtocol" : "tcp", "FromPort" : "443", "ToPort" : "443", "CidrIp" : "0.0.0.0/0"},
{"IpProtocol" : "udp", "FromPort" : "1192", "ToPort" : "1192", "CidrIp" : "0.0.0.0/0" },
{"IpProtocol" : "tcp", "FromPort" : "943", "ToPort" : "943", "CidrIp" : { "Ref" : "AdminCidrIp"} }
]
}
},
"IPAddress" : {
"Type" : "AWS::EC2::EIP",
"Properties" : {
"Domain" : "vpc"
}
},
"Instance" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"ImageId" : { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "AMI" ]},
"InstanceType" : { "Ref" : "InstanceType" },
"SecurityGroupIds" : [{ "Ref" : "SecurityGroup" }],
"SubnetId" : { "Ref" : "SubnetId" },
"KeyName" : { "Ref" : "KeyName" },
"UserData": {
"Fn::Base64": {
"Fn::Join": [ "", [
"public_hostname=", { "Ref" : "IPAddress" }, "\n",
"admin_user=", { "Ref" : "AdminUser" }, "\n",
"admin_pw=", { "Ref" : "AdminPassword" }
] ]
}
},
"Tags" : [
{"Key" : "Application", "Value" : { "Ref" : "AWS::StackId"} },
{"Key" : "Name", "Value" : "OpenVPN Server"}
]
},
"DependsOn" : "IPAddress"
},
"IPAssoc" : {
"Type": "AWS::EC2::EIPAssociation",
"Properties": {
"AllocationId": { "Fn::GetAtt" : [ "IPAddress", "AllocationId" ] },
"InstanceId": { "Ref" : "Instance" }
},
"DependsOn" : "Instance"
}
},
"Outputs" : {
"OpenVPNServerAdminURL" : {
"Value" : { "Fn::Join" : ["", ["https://", { "Ref" : "IPAddress" }, ":943/admin" ]] },
"Description" : "OpenVPN Server Admin URL"
},
"OpenVPNServerURL" : {
"Value" : { "Fn::Join" : ["", ["https://", { "Ref" : "IPAddress" } ]] },
"Description" : "OpenVPN Server URL"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment