|
1 | 1 | { |
2 | 2 | "AWSTemplateFormatVersion": "2010-09-09", |
| 3 | + "Mappings": { |
| 4 | + "OS": { |
| 5 | + "Ubuntu1604": { |
| 6 | + "HelperInstallationCommands": "export DEBIAN_FRONTEND=noninteractive\napt-get -yq update\napt-get -yq install python3-pip\npython3 -m pip install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz\n", |
| 7 | + "InstallationLinks": "https://git.io/vpnsetup" |
| 8 | + }, |
| 9 | + "Ubuntu1804": { |
| 10 | + "HelperInstallationCommands": "export DEBIAN_FRONTEND=noninteractive\napt-get -yq update\napt-get -yq install python3-pip\npython3 -m pip install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz\n", |
| 11 | + "InstallationLinks": "https://git.io/vpnsetup" |
| 12 | + }, |
| 13 | + "Ubuntu2004": { |
| 14 | + "HelperInstallationCommands": "export DEBIAN_FRONTEND=noninteractive\napt-get -yq update\napt-get -yq install python3-pip\npython3 -m pip install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz\n", |
| 15 | + "InstallationLinks": "https://git.io/vpnsetup" |
| 16 | + }, |
| 17 | + "Debian9": { |
| 18 | + "HelperInstallationCommands": "export DEBIAN_FRONTEND=noninteractive\napt-get -yq update\napt-get -yq install python3-pip\npython3 -m pip install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz\n", |
| 19 | + "InstallationLinks": "https://git.io/vpnsetup" |
| 20 | + }, |
| 21 | + "CentOS7": { |
| 22 | + "HelperInstallationCommands": "yum -y check-update\nyum -y install python3 wget\npython3 -m pip install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz\n", |
| 23 | + "InstallationLinks": "https://git.io/vpnsetup-centos" |
| 24 | + }, |
| 25 | + "CentOS8": { |
| 26 | + "HelperInstallationCommands": "yum -y check-update\nyum -y install python3 wget\npython3 -m pip install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz\n", |
| 27 | + "InstallationLinks": "https://git.io/vpnsetup-centos" |
| 28 | + }, |
| 29 | + "AmazonLinux2": { |
| 30 | + "HelperInstallationCommands": "export PATH=\"$PATH:/opt/aws/bin\"\n", |
| 31 | + "InstallationLinks": "https://git.io/vpnsetup-amzn" |
| 32 | + } |
| 33 | + } |
| 34 | + }, |
3 | 35 | "Metadata": { |
4 | 36 | "AWS::CloudFormation::Designer": { |
5 | 37 | "0a162613-8f2e-4864-be99-75d946934a4a": { |
|
110 | 142 | "parent": "5198eb6d-da4f-43e2-8a4b-b9bff02b26a2", |
111 | 143 | "embeds": [], |
112 | 144 | "iscontainedinside": [ |
113 | | - "5198eb6d-da4f-43e2-8a4b-b9bff02b26a2", |
114 | | - "5198eb6d-da4f-43e2-8a4b-b9bff02b26a2", |
115 | | - "5198eb6d-da4f-43e2-8a4b-b9bff02b26a2", |
116 | | - "5198eb6d-da4f-43e2-8a4b-b9bff02b26a2", |
117 | | - "5198eb6d-da4f-43e2-8a4b-b9bff02b26a2", |
118 | | - "5198eb6d-da4f-43e2-8a4b-b9bff02b26a2", |
119 | | - "5198eb6d-da4f-43e2-8a4b-b9bff02b26a2", |
120 | | - "5198eb6d-da4f-43e2-8a4b-b9bff02b26a2", |
121 | 145 | "5198eb6d-da4f-43e2-8a4b-b9bff02b26a2" |
122 | 146 | ], |
123 | 147 | "dependson": [ |
|
344 | 368 | }, |
345 | 369 | "' ERR\n", |
346 | 370 | "sleep 60\n", |
347 | | - "export DEBIAN_FRONTEND=noninteractive\n", |
348 | | - "apt-get -yq update\n", |
349 | | - "apt-get -yq install python3-pip\n", |
350 | | - "pip3 install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz\n", |
| 371 | + { |
| 372 | + "Fn::FindInMap": [ |
| 373 | + "OS", |
| 374 | + { |
| 375 | + "Ref": "OS" |
| 376 | + }, |
| 377 | + "HelperInstallationCommands" |
| 378 | + ] |
| 379 | + }, |
351 | 380 | "export VPN_IPSEC_PSK='", |
352 | 381 | { |
353 | 382 | "Ref": "VpnIpsecPsk" |
|
363 | 392 | "Ref": "VpnPassword" |
364 | 393 | }, |
365 | 394 | "'\n", |
366 | | - "wget -t 3 -T 30 -nv -O vpnsetup.sh https://git.io/vpnsetup\n", |
| 395 | + "wget -t 3 -T 30 -nv -O vpnsetup.sh ", |
| 396 | + { |
| 397 | + "Fn::FindInMap": [ |
| 398 | + "OS", |
| 399 | + { |
| 400 | + "Ref": "OS" |
| 401 | + }, |
| 402 | + "InstallationLinks" |
| 403 | + ] |
| 404 | + }, |
| 405 | + "\n", |
367 | 406 | "sh vpnsetup.sh\n", |
368 | 407 | "cfn-signal -e 0 ", |
369 | 408 | " --stack ", |
|
600 | 639 | [ |
601 | 640 | "import boto3", |
602 | 641 | "import cfnresponse", |
| 642 | + "'''", |
| 643 | + "This python script should be embeded into its designated cloudformation template.", |
| 644 | + "Its function is to sort out the correct AMI image to use for each of the distribution options available.", |
| 645 | + "'''", |
603 | 646 | "def creation_date(e):", |
604 | 647 | " return e['CreationDate']", |
605 | 648 | "", |
|
608 | 651 | " regionName = event['ResourceProperties']['Region']", |
609 | 652 | " distribution = event['ResourceProperties']['Distribution']", |
610 | 653 | " ec2 = boto3.client('ec2',regionName)", |
611 | | - " IAMName = ''", |
612 | | - " if distribution == 'Ubuntu16.04':", |
613 | | - " IAMName = 'ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*'", |
614 | | - " elif distribution == 'Ubuntu18.04':", |
615 | | - " IAMName = 'ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*'", |
616 | | - " elif distribution == 'Ubuntu20.04':", |
617 | | - " IAMName = 'ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*'", |
| 654 | + " AMIName = ''", |
| 655 | + " if distribution == 'Ubuntu1604':", |
| 656 | + " AMIName = 'ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*'", |
| 657 | + " elif distribution == 'Ubuntu1804':", |
| 658 | + " AMIName = 'ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*'", |
| 659 | + " elif distribution == 'Ubuntu2004':", |
| 660 | + " AMIName = 'ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*'", |
618 | 661 | " elif distribution == 'Debian9':", |
619 | | - " IAMName = 'debian-stretch-hvm-x86_64-gp2-*'", |
620 | | - " response = ec2.describe_images(Filters=[{'Name':'name', 'Values':[IAMName]}], Owners=['099720109477', '379101102735'])", |
| 662 | + " AMIName = 'debian-stretch-hvm-x86_64-gp2-*'", |
| 663 | + " elif distribution == 'CentOS7':", |
| 664 | + " AMIName = 'CentOS 7.9.2009 x86_64'", |
| 665 | + " elif distribution == 'CentOS8':", |
| 666 | + " AMIName = 'CentOS 8.3.2011 x86_64'", |
| 667 | + " elif distribution == 'AmazonLinux2':", |
| 668 | + " AMIName = 'amzn2-ami-hvm-*.*-x86_64-gp2'", |
| 669 | + " response = ec2.describe_images(Filters=[{'Name':'name', 'Values':[AMIName]}], Owners=['099720109477', '379101102735', '125523088429', 'amazon'])", |
621 | 670 | " images = response['Images']", |
622 | 671 | " images.sort(key=creation_date,reverse=True)", |
623 | 672 | " AMIId = images[0]['ImageId']", |
|
762 | 811 | "OS": { |
763 | 812 | "Type": "String", |
764 | 813 | "Description": "The OS of your VPN server. Default: Ubuntu 20.04", |
765 | | - "Default": "Ubuntu20.04", |
| 814 | + "Default": "Ubuntu2004", |
766 | 815 | "AllowedValues": [ |
767 | | - "Ubuntu20.04", |
768 | | - "Ubuntu18.04", |
769 | | - "Ubuntu16.04", |
770 | | - "Debian9" |
| 816 | + "Ubuntu2004", |
| 817 | + "Ubuntu1804", |
| 818 | + "Ubuntu1604", |
| 819 | + "Debian9", |
| 820 | + "CentOS7", |
| 821 | + "CentOS8", |
| 822 | + "AmazonLinux2" |
771 | 823 | ] |
772 | 824 | }, |
773 | 825 | "InstanceType": { |
|
832 | 884 | "Value": "https://github.com/hwdsl2/setup-ipsec-vpn#next-steps" |
833 | 885 | } |
834 | 886 | } |
| 887 | + |
835 | 888 | } |
0 commit comments