Created
July 25, 2018 07:32
-
-
Save omerxx/935381f636250b1866189a418afe4aea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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": "c4.large", | |
"AllowedValues": [ | |
"t2.micro", | |
"t2.small", | |
"t2.medium", | |
"m3.medium", | |
"m3.large", | |
"m3.xlarge", | |
"m3.2xlarge", | |
"c4.large" | |
], | |
"ConstraintDescription": "must be a valid EC2 instance type." | |
}, | |
"SubnetId": { | |
"Type": "AWS::EC2::Subnet::Id", | |
"Description": "The ID of a public subnet in your VPC", | |
"Default": "subnet-6dec7446" | |
}, | |
"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": "" | |
}, | |
"VpcId": { | |
"Description": "The ID of a VPC hosting a NAT instance", | |
"Type": "AWS::EC2::VPC::Id", | |
"Default": "vpc-55f2f030" | |
} | |
}, | |
"Mappings": { | |
"RegionMap": { | |
"us-east-1": { | |
"AMI": "ami-38a3292f" | |
}, | |
"us-west-1": { | |
"AMI": "ami-cfa64a8b" | |
}, | |
"us-west-2": { | |
"AMI": "ami-01291e31" | |
}, | |
"eu-central-1": { | |
"AMI": "ami-be6659a3" | |
}, | |
"eu-west-1": { | |
"AMI": "ami-811874f6" | |
}, | |
"sa-east-1": { | |
"AMI": "ami-5d941040" | |
}, | |
"ap-southeast-1": { | |
"AMI": "ami-ce370b9c" | |
}, | |
"ap-southeast-2": { | |
"AMI": "ami-a509759f" | |
}, | |
"ap-northeast-1": { | |
"AMI": "ami-d2cb0bd2" | |
} | |
} | |
}, | |
"Resources": { | |
"SecurityGroup": { | |
"Type": "AWS::EC2::SecurityGroup", | |
"Properties": { | |
"VpcId": { | |
"Ref": "VpcId" | |
}, | |
"GroupDescription": "Security group for OpenVPN Server", | |
"SecurityGroupIngress": [ | |
{ | |
"IpProtocol": "tcp", | |
"FromPort": "22", | |
"ToPort": "22", | |
"CidrIp": "0.0.0.0/0" | |
}, | |
{ | |
"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" | |
}, | |
"Tags": [ | |
{ "Key": "Name", "Value": "openvpn"} | |
], | |
"UserData": { | |
"Fn::Base64": { | |
"Fn::Join": [ | |
"", | |
[ | |
"public_hostname=", | |
{ | |
"Ref": "IPAddress" | |
}, | |
"\n", | |
"admin_user=", | |
{ | |
"Ref": "AdminUser" | |
}, | |
"\n", | |
"admin_pw=", | |
{ | |
"Ref": "AdminPassword" | |
} | |
] | |
] | |
} | |
} | |
}, | |
"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