diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/ADConnector/README.md b/human_reference_dataset/aws-cloudformation-templates/Solutions/ADConnector/README.md new file mode 100644 index 0000000000000000000000000000000000000000..0e3bab287f3a36b31aa6199e0b32630627b41d79 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/ADConnector/README.md @@ -0,0 +1,50 @@ +# AD Connector + +## Description + +This solution creates an AD Connector to connect to an on-premises directory. + +- (Optional) Create AWS resources (IAM role & instance profile) to support + seamlessly joining Windows EC2 instances to your AD Connector directory. +- (Optional) Create AWS resources (IAM role, instance profile, and secret) to + support seamlessly joining Linux EC2 instances to your AD Connector directory. +- (Optional) Creates a Domain Members Security Group with **EXAMPLE** rules + allowing all Private IP communications inbound. + +## Notes + +- AD Connector is not an AWS CloudFormation supported resource, therefore using + an AWS CloudFormation custom resource. +- CloudWatch Logs Log Group uses Amazon managed server-side encryption. + Optionally, a KMS CMK can be used. +- Secrets Manager Secrets using Amazon managed server-side encryption. + Optionally, a KMS CMK can be used. +- **NOTE** Security Group rules are configured to allow all inbound + communications from [RFC1918](https://tools.ietf.org/html/rfc1918#section-3) + Private Address Space, which includes: + `10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16`, this is used as an **EXAMPLE**, + however, all security group rules can be locked down based on the + requirements. + +## Resources + +- [Active Directory Connector](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/directory_ad_connector.html) +- [AD Connector Prerequisites](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/prereq_connector.html) +- [Join an EC2 instance to your AD Connector directory](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/ad_connector_join_instance.html) + +## Attributions + +Using the +[aws-cloudformation/custom-resource-heper](https://github.com/aws-cloudformation/custom-resource-helper) +to handle the AWS CloudFormation Custom Resource responses for the given +resources. + +## Instructions + +1. Run [src/package.sh](src/package.sh) to package the code and dependencies. +1. Upload the + [src/adconnector\_custom\_resource.zip](src/adconnector_custom_resource.zip) to + an S3 bucket, note the bucket name. +1. Launch the AWS CloudFormation stack using the + [ADCONNECTOR.cfn.yaml](templates/ADCONNECTOR.cfn.yaml) template file as the + source. diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/ADConnector/src/.gitignore b/human_reference_dataset/aws-cloudformation-templates/Solutions/ADConnector/src/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..f90b0add27ee16b966595fac405f0e956059fcd4 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/ADConnector/src/.gitignore @@ -0,0 +1,3 @@ +.package +adconnector_custom_resource.zip + diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/ADConnector/src/adconnector_custom_resource.py b/human_reference_dataset/aws-cloudformation-templates/Solutions/ADConnector/src/adconnector_custom_resource.py new file mode 100644 index 0000000000000000000000000000000000000000..f4b47ba852aeea5bc6881c49d7d8703f9eb875ca --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/ADConnector/src/adconnector_custom_resource.py @@ -0,0 +1,124 @@ +"""Create and configure an ADConnector Directory. + +Copyright 2021 Amazon Web Services, Inc. or its affiliates. All Rights Reserved. +This AWS Content is provided subject to the terms of the AWS Customer Agreement available at +http://aws.amazon.com/agreement or other written agreement between Customer and either +Amazon Web Services, Inc. or Amazon Web Services EMEA SARL or both. +""" + +import json +import logging +import os + +import boto3 +from crhelper import CfnResource + +# Setup Default Logger +logger = logging.getLogger(__name__) +logger.setLevel(logging.INFO) +logger.setLevel(os.environ.get("LOG_LEVEL", logging.ERROR)) + +# Initialize the helper +helper = CfnResource(json_logging=False, log_level="DEBUG", boto_level="CRITICAL") + +try: + ds_client = boto3.client("ds") + secretsmanager_client = boto3.client("secretsmanager") +except Exception as error: + helper.init_failure(error) + + +def get_adconnector_parameters(params: dict) -> dict: + """Creates a parameters dictionary for the ds:connect_directory API call to create AD Connector. + + Args: + params: event resource properties + + Returns: + ADConnector Parameters + """ + # Get AD Domain Join Credentials from Secrets Manager + response = secretsmanager_client.get_secret_value( + SecretId=params["DOMAIN_JOIN_SECRET_ID"] + ) + secret = json.loads(response["SecretString"]) + # Create DNS Servers List + + return { + "Name": params["DOMAIN_DNS_NAME"], + "ShortName": params["DOMAIN_NETBIOS_NAME"], + "Password": secret.get("password"), + "Description": params["ADCONNECTOR_DESCRIPTION"], + "Size": params["ADCONNECTOR_SIZE"], + "ConnectSettings": { + "VpcId": params["ADCONNECTOR_VPCID"], + "SubnetIds": [ + params["ADCONNECTOR_SUBNET_ID1"], + params["ADCONNECTOR_SUBNET_ID2"], + ], + "CustomerDnsIps": params["DOMAIN_DNS_SERVERS"].split(", "), + "CustomerUserName": secret.get("username"), + }, + } + + +@helper.create +def create(event, _) -> str: + """Create Event from AWS CloudFormation. + + Args: + event: event data + context: runtime information + + Returns: + ADConnectorDirectoryResourceID + """ + logger.info("Create Event") + logger.info(f"REQUEST RECEIVED: {json.dumps(event, default=str)}") + adconnector_params = get_adconnector_parameters(event["ResourceProperties"]) + response = ds_client.connect_directory(**adconnector_params) + logger.info(f"connect_directory_response = {json.dumps(response, default=str)}") + helper.PhysicalResourceId = response["DirectoryId"] + return helper.PhysicalResourceId + + +@helper.update +def update(event, _): + """Update Event from AWS CloudFormation. + + Args: + event: event data + context: runtime information + + """ + logger.info("Update Event") + logger.info(f"REQUEST RECEIVED: {json.dumps(event, default=str)}") + + +@helper.delete +def delete(event, _): + """Delete Event from AWS CloudFormation. Deletes the ADConnector Directory. + + Args: + event: event data + context: runtime information + + """ + logger.info("Delete Event") + logger.info(f"REQUEST RECEIVED: {json.dumps(event, default=str)}") + helper.PhysicalResourceId = event.get("PhysicalResourceId") + directory_id = helper.PhysicalResourceId + logger.info(f"directory_id = {directory_id}") + response = ds_client.delete_directory(DirectoryId=directory_id) + logger.info(f"delete_directory_response = {json.dumps(response, default=str)}") + + +def lambda_handler(event, context): + """Lambda Handler. + + Args: + event: event data + context: runtime information + """ + logger.info("....Lambda Handler Started....") + helper(event, context) diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/ADConnector/src/package.sh b/human_reference_dataset/aws-cloudformation-templates/Solutions/ADConnector/src/package.sh new file mode 100644 index 0000000000000000000000000000000000000000..babac7db72478a1cb3fac21b6320514859421e9b --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/ADConnector/src/package.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +set -e + +# Builds a lambda package from a single Python 3 module with pip dependencies. +# This is a modified version of the AWS packaging instructions: +# https://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html#python-package-dependencies + +# Set name of python script, excluding .py extension +SCRIPT_NAME="adconnector_custom_resource" +SCRIPT_DIRECTORY=$(pwd) + +# Clean-Up +rm -rf .package .DS_Store "$SCRIPT_NAME".zip + +create_package() { + # Create .package directory + mkdir -p .package + # Add dependencies to .package, per the requirements.txt + pip3 install --target .package --requirement requirements.txt + # Add the python script to .package + cp ./"${SCRIPT_NAME}".py .package +} + +# Includes Python Script & Dependencies (if any) +make_zip() { + cd .package + zip -r ../"${SCRIPT_NAME}".zip ./* + echo -e "\n### SCRIPT DIRECTORY: ${SCRIPT_DIRECTORY}" + echo -e "\n### LAMBDA ZIP FILE: ${SCRIPT_NAME}.zip" + cd .. +} + +create_package +make_zip + +echo -e "### LAMBDA PACKAGE SIZE: $(du -sh .package)" diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/ADConnector/src/requirements.txt b/human_reference_dataset/aws-cloudformation-templates/Solutions/ADConnector/src/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..f824a487e7eada5d84cc8192c9495987afe906ae --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/ADConnector/src/requirements.txt @@ -0,0 +1,2 @@ +# DEPENDENCIES +crhelper diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/ADConnector/templates/ADCONNECTOR.cfn.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/ADConnector/templates/ADCONNECTOR.cfn.json new file mode 100644 index 0000000000000000000000000000000000000000..8a49a122cf3cc221bb34a3ad1fce3d0879ce9ec2 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/ADConnector/templates/ADCONNECTOR.cfn.json @@ -0,0 +1,1226 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "This template creates an AD Connector to connect to an on-premises directory. Tasks accomplished, (1) create AD Connector (2) option to create seamless domain join resources for Windows & Linux EC2 instances (3) option to create a domain members security group that allows all PrivateIP communications inbound (4) option to create DHCPOptionSet pointing to Domain DNS servers", + "Metadata": { + "cfn-lint": { + "config": { + "ignore_checks": [ + "W1001" + ] + } + }, + "AWS::CloudFormation::Interface": { + "ParameterGroups": [ + { + "Label": "Network Configuration", + "Parameters": [ + "VPCID", + "PrivateSubnet1ID", + "PrivateSubnet2ID", + "CreateADConnectorDomainMembersSG", + "CreateDHCPOptionSet" + ] + }, + { + "Label": { + "default": "Active Directory Configuration (Onprem)" + }, + "Parameters": [ + "DomainDNSName", + "DomainNetBiosName", + "DomainJoinUser", + "DomainJoinUserPassword", + "DomainDNSServers", + "SecretsManagerDomainCredentialsSecretsKMSKey" + ] + }, + { + "Label": { + "default": "AD Connector Configuration" + }, + "Parameters": [ + "ADConnectorSize", + "ADConnectorDescription", + "CreateWindowsEC2DomainJoinResources", + "CreateLinuxEC2DomainJoinResources", + "SSMLogsBucketName" + ] + }, + { + "Label": { + "default": "Lambda Function Configuration (AD Connector Custom Resource)" + }, + "Parameters": [ + "LambdaFunctionName", + "LambdaS3BucketName", + "LambdaZipFileName", + "LambdaLogsLogGroupRetention", + "LambdaLogsCloudWatchKMSKey", + "LambdaLogLevel" + ] + } + ], + "ParameterLabels": { + "ADConnectorDescription": { + "default": "AD Connector Description" + }, + "ADConnectorSize": { + "default": "AD Connector Size" + }, + "CreateDHCPOptionSet": { + "default": "Create DHCP Option Set" + }, + "CreateADConnectorDomainMembersSG": { + "default": "Create Domain Members Security Group" + }, + "CreateLinuxEC2DomainJoinResources": { + "default": "Create AWS resources to support seamless domain join Linux EC2 instances" + }, + "CreateWindowsEC2DomainJoinResources": { + "default": "Create AWS resources to support seamless domain join Windows EC2 instances" + }, + "DomainDNSName": { + "default": "Domain DNS Name" + }, + "DomainDNSServers": { + "default": "Domain DNS Servers" + }, + "DomainNetBiosName": { + "default": "Domain NetBIOS Name" + }, + "DomainJoinUser": { + "default": "Domain Join User" + }, + "DomainJoinUserPassword": { + "default": "Domain Join User Password" + }, + "LambdaFunctionName": { + "default": "Lambda Function Name" + }, + "LambdaLogLevel": { + "default": "Lambda Log Level" + }, + "LambdaLogsLogGroupRetention": { + "default": "CloudWatch log retention days for Lambda logs" + }, + "LambdaLogsCloudWatchKMSKey": { + "default": "CloudWatch Logs KMS Key for Lambda logs" + }, + "LambdaS3BucketName": { + "default": "Lambda S3 Bucket Name" + }, + "LambdaZipFileName": { + "default": "Lambda Zip File Name" + }, + "PrivateSubnet1ID": { + "default": "Private Subnet 1 ID" + }, + "PrivateSubnet2ID": { + "default": "Private Subnet 2 ID" + }, + "SecretsManagerDomainCredentialsSecretsKMSKey": { + "default": "Secrets Manager KMS Key for domain credentials secret" + }, + "SSMLogsBucketName": { + "default": "Systems Manager (SSM) Logs Bucket Name" + }, + "VPCID": { + "default": "VPC ID" + } + } + } + }, + "Parameters": { + "ADConnectorDescription": { + "Description": "Description for the directory", + "Type": "String", + "Default": "On-premises AD", + "AllowedPattern": "^[A-Za-z0-9][\\w@#%*+=:?.\\/! -]*$", + "MaxLength": 128 + }, + "ADConnectorSize": { + "Description": "Size of the directory", + "Type": "String", + "AllowedValues": [ + "Small", + "Large" + ], + "Default": "Small" + }, + "CreateDHCPOptionSet": { + "Description": "Create DHCP Option Set", + "Type": "String", + "AllowedValues": [ + "Yes", + "No" + ], + "Default": "No" + }, + "CreateADConnectorDomainMembersSG": { + "Description": "Create Domain Members Security Group. Note, using allow any type rules, restrict accordingly.", + "Type": "String", + "AllowedValues": [ + "Yes", + "No" + ], + "Default": "No" + }, + "CreateLinuxEC2DomainJoinResources": { + "Description": "Create AWS resources (IAM role, instance profile, & secret) to support seamless domain join Linux EC2 instances", + "Type": "String", + "AllowedValues": [ + "Yes", + "No" + ], + "Default": "No" + }, + "CreateWindowsEC2DomainJoinResources": { + "Description": "Create AWS resources (IAM role & instnace profile)to support seamless domain join Windows EC2 instances", + "Type": "String", + "AllowedValues": [ + "Yes", + "No" + ], + "Default": "No" + }, + "DomainDNSName": { + "Description": "Fully qualified name of the on-premises directory, such as corp.example.com", + "Type": "String", + "AllowedPattern": "[a-zA-Z0-9-]+\\..+", + "MaxLength": 25, + "MinLength": 3 + }, + "DomainDNSServers": { + "Description": "DNS or domain controller servers for the on-premises directory.", + "Type": "String", + "AllowedPattern": "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(,|, ))*(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$", + "ConstraintDescription": "Must be in the form of IP address. Additional IP addresses can be provided, separated by a \"comma\". (e.g., 10.1.1.1,10.2.2.2) Additional IP addresses can be provided, separated by a \"comma\"." + }, + "DomainNetBiosName": { + "Description": "Short name of your existing directory, such as CORP", + "Type": "String", + "AllowedPattern": "[a-zA-Z0-9-]+", + "MaxLength": 15, + "MinLength": 1 + }, + "DomainJoinUser": { + "Description": "Username of a user in the existing directory", + "Type": "String", + "AllowedPattern": "[a-zA-Z0-9]*", + "MaxLength": 25, + "MinLength": 5 + }, + "DomainJoinUserPassword": { + "Description": "Password for the existing user account", + "Type": "String", + "AllowedPattern": "(?=^.{6,255}$)((?=.*\\d)(?=.*[A-Z])(?=.*[a-z])|(?=.*\\d)(?=.*[^A-Za-z0-9])(?=.*[a-z])|(?=.*[^A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z])|(?=.*\\d)(?=.*[A-Z])(?=.*[^A-Za-z0-9]))^.*", + "MaxLength": 32, + "MinLength": 8, + "NoEcho": true + }, + "LambdaFunctionName": { + "Description": "Lambda Function Name for Custom Resource.", + "Type": "String", + "Default": "CR-ADConnector", + "AllowedPattern": "^[\\w-]{1,64}$", + "ConstraintDescription": "Max 64 alphanumeric characters. Also special characters supported [_, -]" + }, + "LambdaLogLevel": { + "Description": "Lambda logging level", + "Type": "String", + "AllowedValues": [ + "INFO", + "DEBUG" + ], + "Default": "INFO" + }, + "LambdaLogsLogGroupRetention": { + "Description": "Specifies the number of days you want to retain Lambda log events in the CloudWatch Logs", + "Type": "String", + "AllowedValues": [ + 1, + 3, + 5, + 7, + 14, + 30, + 60, + 90, + 120, + 150, + 180, + 365, + 400, + 545, + 731, + 1827, + 3653 + ], + "Default": 14 + }, + "LambdaLogsCloudWatchKMSKey": { + "Description": "(Optional) KMS Key ARN to use for encrypting the Lambda logs data. If empty, encryption is enabled with CloudWatch Logs managing the server-side encryption keys.", + "Type": "String", + "AllowedPattern": "^$|^arn:(aws[a-zA-Z-]*){1}:kms:[a-z0-9-]+:\\d{12}:key\\/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$", + "ConstraintDescription": "Key ARN example: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab" + }, + "LambdaS3BucketName": { + "Description": "Lambda S3 bucket name for the Lambda deployment package. Lambda bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-).", + "Type": "String", + "AllowedPattern": "(?=^.{3,63}$)(?!.*[.-]{2})(?!.*[--]{2})(?!^(?:(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\\.(?!$)|$)){4}$)(^(([a-z0-9]|[a-z0-9][a-z0-9\\-]*[a-z0-9])\\.)*([a-z0-9]|[a-z0-9][a-z0-9\\-]*[a-z0-9])$)", + "ConstraintDescription": "Lambda S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-)." + }, + "LambdaZipFileName": { + "Description": "Amazon S3 key of the deployment package.", + "Type": "String", + "Default": "adconnector_custom_resource.zip", + "MaxLength": 1024, + "MinLength": 1 + }, + "PrivateSubnet1ID": { + "Description": "ID of the private subnet 1 in Availability Zone 1 (e.g., subnet-a0246dcd)", + "Type": "AWS::EC2::Subnet::Id" + }, + "PrivateSubnet2ID": { + "Description": "ID of the private subnet 2 in Availability Zone 2 (e.g., subnet-a0246dcd)", + "Type": "AWS::EC2::Subnet::Id" + }, + "SecretsManagerDomainCredentialsSecretsKMSKey": { + "Description": "(Optional) KMS Key ARN to use for encrypting the SecretsManager domain credentials secret. If empty, encryption is enabled with SecretsManager managing the server-side encryption keys.", + "Type": "String", + "AllowedPattern": "^$|^arn:(aws[a-zA-Z-]*)?:kms:[a-z0-9-]+:\\d{12}:key\\/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$", + "ConstraintDescription": "Key ARN example: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab" + }, + "SSMLogsBucketName": { + "Description": "(Optional) SSM Logs bucket name for where Systems Manager logs should store log files. SSM Logs bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-).", + "Type": "String", + "Default": "", + "AllowedPattern": "^$|(?=^.{3,63}$)(?!.*[.-]{2})(?!.*[--]{2})(?!^(?:(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\\.(?!$)|$)){4}$)(^(([a-z0-9]|[a-z0-9][a-z0-9\\-]*[a-z0-9])\\.)*([a-z0-9]|[a-z0-9][a-z0-9\\-]*[a-z0-9])$)", + "ConstraintDescription": "SSM Logs bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-)." + }, + "VPCID": { + "Description": "ID of the VPC (e.g., vpc-0343606e)", + "Type": "AWS::EC2::VPC::Id" + } + }, + "Conditions": { + "DHCPOptionSetCondition": { + "Fn::Equals": [ + { + "Ref": "CreateDHCPOptionSet" + }, + "Yes" + ] + }, + "DomainMembersSGCondition": { + "Fn::Equals": [ + { + "Ref": "CreateADConnectorDomainMembersSG" + }, + "Yes" + ] + }, + "LambdaLogsCloudWatchKMSKeyCondition": { + "Fn::Not": [ + { + "Fn::Equals": [ + { + "Ref": "LambdaLogsCloudWatchKMSKey" + }, + "" + ] + } + ] + }, + "LinuxEC2DomainJoinResourcesCondition": { + "Fn::Equals": [ + { + "Ref": "CreateLinuxEC2DomainJoinResources" + }, + "Yes" + ] + }, + "SecretsManagerDomainCredentialsSecretsKMSKeyCondition": { + "Fn::Not": [ + { + "Fn::Equals": [ + { + "Ref": "SecretsManagerDomainCredentialsSecretsKMSKey" + }, + "" + ] + } + ] + }, + "SSMLogsBucketNameCondition": { + "Fn::Not": [ + { + "Fn::Equals": [ + { + "Ref": "SSMLogsBucketName" + }, + "" + ] + } + ] + }, + "WindowsEC2DomainJoinResourcesCondition": { + "Fn::Equals": [ + { + "Ref": "CreateWindowsEC2DomainJoinResources" + }, + "Yes" + ] + } + }, + "Resources": { + "ADConnectorDomainMembersSG": { + "Type": "AWS::EC2::SecurityGroup", + "Metadata": { + "cfn_nag": { + "rules_to_suppress": [ + { + "id": "W42", + "reason": "Allow all inbound communications from Private IP CIDRs (for Lab purposes)" + }, + { + "id": "W40", + "reason": "Allow all outbound communications (for Lab purposes)" + }, + { + "id": "W5", + "reason": "Allow all outbound communications (for Lab purposes)" + }, + { + "id": "W9", + "reason": "Allow all inbound communications from Private IP CIDRs (for Lab purposes)" + } + ] + } + }, + "Properties": { + "GroupDescription": { + "Fn::Sub": "${DomainNetBiosName} Domain Members SG via AD Connector" + }, + "VpcId": { + "Ref": "VPCID" + }, + "SecurityGroupIngress": [ + { + "IpProtocol": "-1", + "Description": "LAB - Allow All Private IP Communications", + "CidrIp": "10.0.0.0/8" + }, + { + "IpProtocol": "-1", + "Description": "LAB - Allow All Private IP Communications", + "CidrIp": "172.16.0.0/12" + }, + { + "IpProtocol": "-1", + "Description": "LAB - Allow All Private IP Communications", + "CidrIp": "192.168.0.0/16" + } + ], + "SecurityGroupEgress": [ + { + "Description": "Allow All Outbound Communications", + "IpProtocol": "-1", + "CidrIp": "0.0.0.0/0" + } + ], + "Tags": [ + { + "Key": "Name", + "Value": { + "Fn::Sub": "${DomainNetBiosName}-DomainMembersSG-ADConnector" + } + } + ] + }, + "Condition": "DomainMembersSGCondition" + }, + "ADConnectorLambdaFunction": { + "Type": "AWS::Lambda::Function", + "Metadata": { + "cfn_nag": { + "rules_to_suppress": [ + { + "id": "W58", + "reason": "Permissions to write to CloudWatch Logs provided by the attached IAM role" + } + ] + } + }, + "Properties": { + "FunctionName": { + "Ref": "LambdaFunctionName" + }, + "Handler": "adconnector_custom_resource.lambda_handler", + "Role": { + "Fn::GetAtt": [ + "ADConnectorLambdaRole", + "Arn" + ] + }, + "Runtime": "python3.8", + "MemorySize": 128, + "Timeout": 120, + "Environment": { + "Variables": { + "LOG_LEVEL": { + "Ref": "LambdaLogLevel" + } + } + }, + "Code": { + "S3Bucket": { + "Ref": "LambdaS3BucketName" + }, + "S3Key": { + "Ref": "LambdaZipFileName" + } + }, + "VpcConfig": { + "SubnetIds": [ + "PrivateSubnet1ID", + "PrivateSubnet2ID" + ], + "SecurityGroupIds": [ + { + "Ref": "ADConnectorDomainMembersSG" + } + ] + } + } + }, + "ADConnectorLambdaLogsLogGroup": { + "DeletionPolicy": "Retain", + "UpdateReplacePolicy": "Retain", + "Type": "AWS::Logs::LogGroup", + "Properties": { + "LogGroupName": { + "Fn::Sub": "/aws/lambda/${LambdaFunctionName}" + }, + "RetentionInDays": { + "Ref": "LambdaLogsLogGroupRetention" + }, + "KmsKeyId": { + "Fn::If": [ + "LambdaLogsCloudWatchKMSKeyCondition", + { + "Ref": "LambdaLogsCloudWatchKMSKey" + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + }, + "ADConnectorLambdaRole": { + "Type": "AWS::IAM::Role", + "Metadata": { + "cfn_nag": { + "rules_to_suppress": [ + { + "id": "W11", + "reason": "Allow * in resource when required" + }, + { + "id": "W28", + "reason": "The role name is defined to identify automation resources" + } + ] + } + }, + "Properties": { + "RoleName": { + "Fn::Sub": "${LambdaFunctionName}-LambdaRole" + }, + "Description": "Rights to Setup AD Connector", + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": "sts:AssumeRole", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "Path": "/", + "Tags": [ + { + "Key": "StackName", + "Value": { + "Ref": "AWS::StackName" + } + } + ], + "Policies": [ + { + "PolicyName": "CloudWatchLogGroup", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Sid": "CreateLogGroup", + "Effect": "Allow", + "Action": "logs:CreateLogGroup", + "Resource": { + "Fn::Sub": "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:${ADConnectorLambdaLogsLogGroup}" + } + }, + { + "Sid": "CreateLogStreamAndEvents", + "Effect": "Allow", + "Action": [ + "logs:CreateLogStream", + "logs:PutLogEvents" + ], + "Resource": { + "Fn::Sub": "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:${ADConnectorLambdaLogsLogGroup}:log-stream:*" + } + } + ] + } + }, + { + "PolicyName": "ADConnector", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Sid": "Directory", + "Effect": "Allow", + "Action": [ + "ds:ConnectDirectory", + "ds:DeleteDirectory" + ], + "Resource": "*" + }, + { + "Sid": "CreateAdConnectorEc2Resources", + "Effect": "Allow", + "Action": [ + "ec2:DescribeSubnets", + "ec2:DescribeVpcs", + "ec2:CreateSecurityGroup", + "ec2:CreateNetworkInterface", + "ec2:DescribeNetworkInterfaces", + "ec2:AuthorizeSecurityGroupIngress", + "ec2:AuthorizeSecurityGroupEgress", + "ec2:CreateTags" + ], + "Resource": "*", + "Condition": { + "Bool": { + "aws:ViaAWSService": true + } + } + }, + { + "Sid": "DeleteAdConnectorEc2Resources", + "Effect": "Allow", + "Action": [ + "ec2:DeleteSecurityGroup", + "ec2:DescribeNetworkInterfaces", + "ec2:DeleteNetworkInterface", + "ec2:RevokeSecurityGroupIngress", + "ec2:RevokeSecurityGroupEgress", + "ec2:DeleteTags" + ], + "Resource": "*", + "Condition": { + "Bool": { + "aws:ViaAWSService": true + } + } + } + ] + } + }, + { + "PolicyName": "ADConnectorServiceAccountSecret", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Sid": "GetSecret", + "Effect": "Allow", + "Action": "secretsmanager:GetSecretValue", + "Resource": { + "Ref": "ADConnectorServiceAccountSecret" + } + } + ] + } + }, + { + "Fn::If": [ + "SecretsManagerDomainCredentialsSecretsKMSKeyCondition", + { + "PolicyName": "KMSKeyForSecret", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": "kms:Decrypt", + "Resource": { + "Ref": "SecretsManagerDomainCredentialsSecretsKMSKey" + } + } + ] + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + ] + } + }, + "ADConnectorLinuxEC2DomainJoinInstanceProfile": { + "Type": "AWS::IAM::InstanceProfile", + "Properties": { + "InstanceProfileName": { + "Ref": "ADConnectorLinuxEC2DomainJoinRole" + }, + "Path": "/", + "Roles": [ + { + "Ref": "ADConnectorLinuxEC2DomainJoinRole" + } + ] + }, + "Condition": "LinuxEC2DomainJoinResourcesCondition" + }, + "ADConnectorLinuxEC2DomainJoinRole": { + "Type": "AWS::IAM::Role", + "Metadata": { + "cfn_nag": { + "rules_to_suppress": [ + { + "id": "W28", + "reason": "The role name is defined to identify automation resources" + } + ] + } + }, + "Properties": { + "RoleName": { + "Fn::Sub": "${DomainNetBiosName}-LinuxEC2DomainJoinRole-ADConnector" + }, + "Description": { + "Fn::Sub": "IAM Role to Seamlessly Join Linux EC2 Instances to ${DomainNetBiosName} Domain via AD Connector" + }, + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": "sts:AssumeRole", + "Principal": { + "Service": [ + "ec2.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + { + "Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/AmazonSSMManagedInstanceCore" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/AmazonSSMDirectoryServiceAccess" + } + ], + "Path": "/", + "Tags": [ + { + "Key": "StackName", + "Value": { + "Ref": "AWS::StackName" + } + } + ], + "Policies": [ + { + "PolicyName": "SSMAgent", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": "s3:GetObject", + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::aws-ssm-${AWS::Region}/*" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::aws-windows-downloads-${AWS::Region}/*" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::amazon-ssm-${AWS::Region}/*" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::amazon-ssm-packages-${AWS::Region}/*" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AWS::Region}-birdwatcher-prod/*" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::patch-baseline-snapshot-${AWS::Region}/*" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::aws-ssm-distributor-file-${AWS::Region}/*" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::aws-ssm-document-attachments-${AWS::Region}/*" + } + ] + } + ] + } + }, + { + "Fn::If": [ + "SSMLogsBucketNameCondition", + { + "PolicyName": "SsmLogs", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "s3:GetObject", + "s3:PutObject", + "s3:PutObjectAcl", + "s3:GetEncryptionConfiguration" + ], + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${SSMLogsBucketName}" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${SSMLogsBucketName}/*" + } + ] + } + ] + } + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + { + "PolicyName": "ADConnectorLinuxEC2SeamlessDomainJoinSecret", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "secretsmanager:GetSecretValue", + "secretsmanager:DescribeSecret" + ], + "Resource": { + "Ref": "ADConnectorLinuxEC2SeamlessDomainJoinSecret" + } + } + ] + } + }, + { + "Fn::If": [ + "SecretsManagerDomainCredentialsSecretsKMSKeyCondition", + { + "PolicyName": "KMSKeyForSecret", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": "kms:Decrypt", + "Resource": { + "Ref": "SecretsManagerDomainCredentialsSecretsKMSKey" + } + } + ] + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + ] + }, + "Condition": "LinuxEC2DomainJoinResourcesCondition" + }, + "ADConnectorLinuxEC2SeamlessDomainJoinSecret": { + "DeletionPolicy": "Retain", + "UpdateReplacePolicy": "Retain", + "Type": "AWS::SecretsManager::Secret", + "Properties": { + "Name": { + "Fn::Sub": "aws/directory-services/${ADConnectorResource}/seamless-domain-join" + }, + "Description": { + "Fn::Sub": "AD Credentials for Seamless Domain Join Windows/Linux EC2 instances to ${DomainNetBiosName} Domain via AD Connector" + }, + "SecretString": { + "Fn::Sub": "{ \"awsSeamlessDomainUsername\" : \"${DomainJoinUser}\", \"awsSeamlessDomainPassword\" : \"${DomainJoinUserPassword}\" }" + }, + "KmsKeyId": { + "Fn::If": [ + "SecretsManagerDomainCredentialsSecretsKMSKeyCondition", + { + "Ref": "SecretsManagerDomainCredentialsSecretsKMSKey" + }, + { + "Ref": "AWS::NoValue" + } + ] + } + }, + "Condition": "LinuxEC2DomainJoinResourcesCondition" + }, + "ADConnectorResource": { + "Type": "Custom::ADConnectorResource", + "Properties": { + "ServiceToken": { + "Fn::GetAtt": [ + "ADConnectorLambdaFunction", + "Arn" + ] + }, + "ADCONNECTOR_DESCRIPTION": { + "Ref": "ADConnectorDescription" + }, + "ADCONNECTOR_SIZE": { + "Ref": "ADConnectorSize" + }, + "ADCONNECTOR_SUBNET_ID1": { + "Ref": "PrivateSubnet1ID" + }, + "ADCONNECTOR_SUBNET_ID2": { + "Ref": "PrivateSubnet2ID" + }, + "ADCONNECTOR_VPCID": { + "Ref": "VPCID" + }, + "DOMAIN_DNS_NAME": { + "Ref": "DomainDNSName" + }, + "DOMAIN_DNS_SERVERS": { + "Ref": "DomainDNSServers" + }, + "DOMAIN_NETBIOS_NAME": { + "Ref": "DomainNetBiosName" + }, + "DOMAIN_JOIN_SECRET_ID": { + "Ref": "ADConnectorServiceAccountSecret" + } + }, + "Version": "1.0" + }, + "ADConnectorServiceAccountSecret": { + "DeletionPolicy": "Retain", + "UpdateReplacePolicy": "Retain", + "Type": "AWS::SecretsManager::Secret", + "Properties": { + "Name": { + "Fn::Sub": "ADConnector-ServiceAccount-${DomainNetBiosName}-Domain" + }, + "Description": { + "Fn::Sub": "ADConnector Service Account for ${DomainNetBiosName} Domain" + }, + "SecretString": { + "Fn::Sub": "{ \"username\" : \"${DomainJoinUser}\", \"password\" : \"${DomainJoinUserPassword}\" }" + }, + "KmsKeyId": { + "Fn::If": [ + "SecretsManagerDomainCredentialsSecretsKMSKeyCondition", + { + "Ref": "SecretsManagerDomainCredentialsSecretsKMSKey" + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + }, + "ADConnectorWindowsEC2DomainJoinInstanceProfile": { + "Type": "AWS::IAM::InstanceProfile", + "Properties": { + "InstanceProfileName": { + "Ref": "ADConnectorWindowsEC2DomainJoinRole" + }, + "Path": "/", + "Roles": [ + { + "Ref": "ADConnectorWindowsEC2DomainJoinRole" + } + ] + }, + "Condition": "WindowsEC2DomainJoinResourcesCondition" + }, + "ADConnectorWindowsEC2DomainJoinRole": { + "Type": "AWS::IAM::Role", + "Metadata": { + "cfn_nag": { + "rules_to_suppress": [ + { + "id": "W28", + "reason": "The role name is defined to identify automation resources" + } + ] + } + }, + "Properties": { + "RoleName": { + "Fn::Sub": "${DomainNetBiosName}-ADConnector-WindowsEC2DomainJoinRole" + }, + "Description": { + "Fn::Sub": "IAM Role to Seamlessly Join Windows EC2 Instances to ${DomainDNSName} Domain via AD Connector" + }, + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": "sts:AssumeRole", + "Principal": { + "Service": [ + "ec2.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + { + "Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/AmazonSSMManagedInstanceCore" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/AmazonSSMDirectoryServiceAccess" + } + ], + "Path": "/", + "Tags": [ + { + "Key": "StackName", + "Value": { + "Ref": "AWS::StackName" + } + } + ], + "Policies": [ + { + "PolicyName": "SSMAgent", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": "s3:GetObject", + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::aws-ssm-${AWS::Region}/*" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::aws-windows-downloads-${AWS::Region}/*" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::amazon-ssm-${AWS::Region}/*" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::amazon-ssm-packages-${AWS::Region}/*" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AWS::Region}-birdwatcher-prod/*" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::patch-baseline-snapshot-${AWS::Region}/*" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::aws-ssm-distributor-file-${AWS::Region}/*" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::aws-ssm-document-attachments-${AWS::Region}/*" + } + ] + } + ] + } + }, + { + "Fn::If": [ + "SSMLogsBucketNameCondition", + { + "PolicyName": "SsmLogs", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "s3:GetObject", + "s3:PutObject", + "s3:PutObjectAcl", + "s3:GetEncryptionConfiguration" + ], + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${SSMLogsBucketName}" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${SSMLogsBucketName}/*" + } + ] + } + ] + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + ] + }, + "Condition": "WindowsEC2DomainJoinResourcesCondition" + }, + "DHCPOptions": { + "Type": "AWS::EC2::DHCPOptions", + "Properties": { + "DomainName": { + "Ref": "DomainDNSName" + }, + "DomainNameServers": [ + { + "Ref": "DomainDNSServers" + } + ], + "Tags": [ + { + "Key": "Name", + "Value": { + "Ref": "DomainDNSName" + } + } + ] + }, + "Condition": "DHCPOptionSetCondition" + }, + "DHCPOptionsVPCAssociation": { + "Type": "AWS::EC2::VPCDHCPOptionsAssociation", + "Properties": { + "VpcId": { + "Ref": "VPCID" + }, + "DhcpOptionsId": { + "Ref": "DHCPOptions" + } + }, + "Condition": "DHCPOptionSetCondition" + } + }, + "Outputs": { + "ADConnectorDirectoryId": { + "Description": "AD Connector Directory ID", + "Value": { + "Ref": "ADConnectorResource" + }, + "Export": { + "Name": { + "Fn::Sub": "${AWS::StackName}-ADConnectorDirectoryId" + } + } + }, + "ADConnectorDirectoryName": { + "Description": "AD Connector Directory Name", + "Value": { + "Ref": "DomainDNSName" + }, + "Export": { + "Name": { + "Fn::Sub": "${AWS::StackName}-ADConnectorDirectoryName" + } + } + }, + "ADConnectorADConnectorDomainMembersSG": { + "Description": "ADConnector Domain Members Security Group", + "Value": { + "Ref": "ADConnectorDomainMembersSG" + }, + "Export": { + "Name": { + "Fn::Sub": "${AWS::StackName}-${DomainNetBiosName}-ADConnectorDomainMembersSG" + } + }, + "Condition": "DomainMembersSGCondition" + }, + "ADConnectorWindowsEC2SeamlessDomainJoinInstanceProfile": { + "Description": "IAM Instance Profile with SSM Document Rights to Join Windows Computers via AD Connector", + "Value": { + "Ref": "ADConnectorWindowsEC2DomainJoinInstanceProfile" + }, + "Export": { + "Name": { + "Fn::Sub": "${AWS::StackName}-${DomainNetBiosName}-ADConnectorWindowsEC2DomainJoinProfile" + } + }, + "Condition": "WindowsEC2DomainJoinResourcesCondition" + }, + "ADConnectorWindowsEC2SeamlessDomainJoinRole": { + "Description": "IAM Instance Profile with SSM Document Rights to Join Windows Computers via AD Connector", + "Value": { + "Ref": "ADConnectorWindowsEC2DomainJoinRole" + }, + "Export": { + "Name": { + "Fn::Sub": "${AWS::StackName}-${DomainNetBiosName}-ADConnectorWindowsEC2DomainJoinRole" + } + }, + "Condition": "WindowsEC2DomainJoinResourcesCondition" + }, + "ADConnectorLinuxEC2SeamlessDomainJoinInstanceProfile": { + "Description": "IAM Instance Profile with SSM Document Rights to Join Linux Computers via AD Connector", + "Value": { + "Ref": "ADConnectorLinuxEC2DomainJoinInstanceProfile" + }, + "Export": { + "Name": { + "Fn::Sub": "${AWS::StackName}-${DomainNetBiosName}-ADConnectorLinuxEC2DomainJoinProfile" + } + }, + "Condition": "LinuxEC2DomainJoinResourcesCondition" + }, + "ADConnectorLinuxEC2SeamlessDomainJoinRole": { + "Description": "IAM Instance Profile with SSM Document Rights to Join Linux Computers via AD Connector", + "Value": { + "Ref": "ADConnectorLinuxEC2DomainJoinRole" + }, + "Export": { + "Name": { + "Fn::Sub": "${AWS::StackName}-${DomainNetBiosName}-ADConnectorLinuxEC2DomainJoinRole" + } + }, + "Condition": "LinuxEC2DomainJoinResourcesCondition" + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/ADConnector/templates/ADCONNECTOR.cfn.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/ADConnector/templates/ADCONNECTOR.cfn.yaml new file mode 100644 index 0000000000000000000000000000000000000000..34d770e28c237b11b91f3fac9f2f9ab64054f158 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/ADConnector/templates/ADCONNECTOR.cfn.yaml @@ -0,0 +1,721 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: This template creates an AD Connector to connect to an on-premises directory. Tasks accomplished, (1) create AD Connector (2) option to create seamless domain join resources for Windows & Linux EC2 instances (3) option to create a domain members security group that allows all PrivateIP communications inbound (4) option to create DHCPOptionSet pointing to Domain DNS servers + +Metadata: + cfn-lint: + config: + ignore_checks: + - W1001 + + AWS::CloudFormation::Interface: + ParameterGroups: + - Label: Network Configuration + Parameters: + - VPCID + - PrivateSubnet1ID + - PrivateSubnet2ID + - CreateADConnectorDomainMembersSG + - CreateDHCPOptionSet + - Label: + default: Active Directory Configuration (Onprem) + Parameters: + - DomainDNSName + - DomainNetBiosName + - DomainJoinUser + - DomainJoinUserPassword + - DomainDNSServers + - SecretsManagerDomainCredentialsSecretsKMSKey + - Label: + default: AD Connector Configuration + Parameters: + - ADConnectorSize + - ADConnectorDescription + - CreateWindowsEC2DomainJoinResources + - CreateLinuxEC2DomainJoinResources + - SSMLogsBucketName + - Label: + default: Lambda Function Configuration (AD Connector Custom Resource) + Parameters: + - LambdaFunctionName + - LambdaS3BucketName + - LambdaZipFileName + - LambdaLogsLogGroupRetention + - LambdaLogsCloudWatchKMSKey + - LambdaLogLevel + ParameterLabels: + ADConnectorDescription: + default: AD Connector Description + ADConnectorSize: + default: AD Connector Size + CreateDHCPOptionSet: + default: Create DHCP Option Set + CreateADConnectorDomainMembersSG: + default: Create Domain Members Security Group + CreateLinuxEC2DomainJoinResources: + default: Create AWS resources to support seamless domain join Linux EC2 instances + CreateWindowsEC2DomainJoinResources: + default: Create AWS resources to support seamless domain join Windows EC2 instances + DomainDNSName: + default: Domain DNS Name + DomainDNSServers: + default: Domain DNS Servers + DomainNetBiosName: + default: Domain NetBIOS Name + DomainJoinUser: + default: Domain Join User + DomainJoinUserPassword: + default: Domain Join User Password + LambdaFunctionName: + default: Lambda Function Name + LambdaLogLevel: + default: Lambda Log Level + LambdaLogsLogGroupRetention: + default: CloudWatch log retention days for Lambda logs + LambdaLogsCloudWatchKMSKey: + default: CloudWatch Logs KMS Key for Lambda logs + LambdaS3BucketName: + default: Lambda S3 Bucket Name + LambdaZipFileName: + default: Lambda Zip File Name + PrivateSubnet1ID: + default: Private Subnet 1 ID + PrivateSubnet2ID: + default: Private Subnet 2 ID + SecretsManagerDomainCredentialsSecretsKMSKey: + default: Secrets Manager KMS Key for domain credentials secret + SSMLogsBucketName: + default: Systems Manager (SSM) Logs Bucket Name + VPCID: + default: VPC ID + +Parameters: + ADConnectorDescription: + Description: Description for the directory + Type: String + Default: On-premises AD + AllowedPattern: ^[A-Za-z0-9][\w@#%*+=:?.\/! -]*$ + MaxLength: 128 + + ADConnectorSize: + Description: Size of the directory + Type: String + AllowedValues: + - Small + - Large + Default: Small + + CreateDHCPOptionSet: + Description: Create DHCP Option Set + Type: String + AllowedValues: + - Yes + - No + Default: No + + CreateADConnectorDomainMembersSG: + Description: Create Domain Members Security Group. Note, using allow any type rules, restrict accordingly. + Type: String + AllowedValues: + - Yes + - No + Default: No + + CreateLinuxEC2DomainJoinResources: + Description: Create AWS resources (IAM role, instance profile, & secret) to support seamless domain join Linux EC2 instances + Type: String + AllowedValues: + - Yes + - No + Default: No + + CreateWindowsEC2DomainJoinResources: + Description: Create AWS resources (IAM role & instnace profile)to support seamless domain join Windows EC2 instances + Type: String + AllowedValues: + - Yes + - No + Default: No + + DomainDNSName: + Description: Fully qualified name of the on-premises directory, such as corp.example.com + Type: String + AllowedPattern: '[a-zA-Z0-9-]+\..+' + MaxLength: 25 + MinLength: 3 + + DomainDNSServers: + Description: DNS or domain controller servers for the on-premises directory. + Type: String + AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(,|, ))*(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$ + ConstraintDescription: Must be in the form of IP address. Additional IP addresses can be provided, separated by a "comma". (e.g., 10.1.1.1,10.2.2.2) Additional IP addresses can be provided, separated by a "comma". + + DomainNetBiosName: + Description: Short name of your existing directory, such as CORP + Type: String + AllowedPattern: '[a-zA-Z0-9-]+' + MaxLength: 15 + MinLength: 1 + + DomainJoinUser: + Description: Username of a user in the existing directory + Type: String + AllowedPattern: '[a-zA-Z0-9]*' + MaxLength: 25 + MinLength: 5 + + DomainJoinUserPassword: + Description: Password for the existing user account + Type: String + AllowedPattern: (?=^.{6,255}$)((?=.*\d)(?=.*[A-Z])(?=.*[a-z])|(?=.*\d)(?=.*[^A-Za-z0-9])(?=.*[a-z])|(?=.*[^A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z])|(?=.*\d)(?=.*[A-Z])(?=.*[^A-Za-z0-9]))^.* + MaxLength: 32 + MinLength: 8 + NoEcho: true + + LambdaFunctionName: + Description: Lambda Function Name for Custom Resource. + Type: String + Default: CR-ADConnector + AllowedPattern: ^[\w-]{1,64}$ + ConstraintDescription: Max 64 alphanumeric characters. Also special characters supported [_, -] + + LambdaLogLevel: + Description: Lambda logging level + Type: String + AllowedValues: + - INFO + - DEBUG + Default: INFO + + LambdaLogsLogGroupRetention: + Description: Specifies the number of days you want to retain Lambda log events in the CloudWatch Logs + Type: String + AllowedValues: + - 1 + - 3 + - 5 + - 7 + - 14 + - 30 + - 60 + - 90 + - 120 + - 150 + - 180 + - 365 + - 400 + - 545 + - 731 + - 1827 + - 3653 + Default: 14 + + LambdaLogsCloudWatchKMSKey: + Description: (Optional) KMS Key ARN to use for encrypting the Lambda logs data. If empty, encryption is enabled with CloudWatch Logs managing the server-side encryption keys. + Type: String + AllowedPattern: ^$|^arn:(aws[a-zA-Z-]*){1}:kms:[a-z0-9-]+:\d{12}:key\/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$ + ConstraintDescription: 'Key ARN example: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab' + + LambdaS3BucketName: + Description: Lambda S3 bucket name for the Lambda deployment package. Lambda bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-). + Type: String + AllowedPattern: (?=^.{3,63}$)(?!.*[.-]{2})(?!.*[--]{2})(?!^(?:(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\.(?!$)|$)){4}$)(^(([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])\.)*([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])$) + ConstraintDescription: Lambda S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-). + + LambdaZipFileName: + Description: Amazon S3 key of the deployment package. + Type: String + Default: adconnector_custom_resource.zip + MaxLength: 1024 + MinLength: 1 + + PrivateSubnet1ID: + Description: ID of the private subnet 1 in Availability Zone 1 (e.g., subnet-a0246dcd) + Type: AWS::EC2::Subnet::Id + + PrivateSubnet2ID: + Description: ID of the private subnet 2 in Availability Zone 2 (e.g., subnet-a0246dcd) + Type: AWS::EC2::Subnet::Id + + SecretsManagerDomainCredentialsSecretsKMSKey: + Description: (Optional) KMS Key ARN to use for encrypting the SecretsManager domain credentials secret. If empty, encryption is enabled with SecretsManager managing the server-side encryption keys. + Type: String + AllowedPattern: ^$|^arn:(aws[a-zA-Z-]*)?:kms:[a-z0-9-]+:\d{12}:key\/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$ + ConstraintDescription: 'Key ARN example: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab' + + SSMLogsBucketName: + Description: (Optional) SSM Logs bucket name for where Systems Manager logs should store log files. SSM Logs bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-). + Type: String + Default: "" + AllowedPattern: ^$|(?=^.{3,63}$)(?!.*[.-]{2})(?!.*[--]{2})(?!^(?:(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\.(?!$)|$)){4}$)(^(([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])\.)*([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])$) + ConstraintDescription: SSM Logs bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-). + + VPCID: + Description: ID of the VPC (e.g., vpc-0343606e) + Type: AWS::EC2::VPC::Id + +Conditions: + DHCPOptionSetCondition: !Equals + - !Ref CreateDHCPOptionSet + - Yes + + DomainMembersSGCondition: !Equals + - !Ref CreateADConnectorDomainMembersSG + - Yes + + LambdaLogsCloudWatchKMSKeyCondition: !Not + - !Equals + - !Ref LambdaLogsCloudWatchKMSKey + - "" + + LinuxEC2DomainJoinResourcesCondition: !Equals + - !Ref CreateLinuxEC2DomainJoinResources + - Yes + + SecretsManagerDomainCredentialsSecretsKMSKeyCondition: !Not + - !Equals + - !Ref SecretsManagerDomainCredentialsSecretsKMSKey + - "" + + SSMLogsBucketNameCondition: !Not + - !Equals + - !Ref SSMLogsBucketName + - "" + + WindowsEC2DomainJoinResourcesCondition: !Equals + - !Ref CreateWindowsEC2DomainJoinResources + - Yes + +Resources: + ADConnectorDomainMembersSG: + Type: AWS::EC2::SecurityGroup + Metadata: + cfn_nag: + rules_to_suppress: + - id: W42 + reason: Allow all inbound communications from Private IP CIDRs (for Lab purposes) + - id: W40 + reason: Allow all outbound communications (for Lab purposes) + - id: W5 + reason: Allow all outbound communications (for Lab purposes) + - id: W9 + reason: Allow all inbound communications from Private IP CIDRs (for Lab purposes) + Properties: + GroupDescription: !Sub ${DomainNetBiosName} Domain Members SG via AD Connector + VpcId: !Ref VPCID + SecurityGroupIngress: + - IpProtocol: "-1" + Description: LAB - Allow All Private IP Communications + CidrIp: 10.0.0.0/8 + - IpProtocol: "-1" + Description: LAB - Allow All Private IP Communications + CidrIp: 172.16.0.0/12 + - IpProtocol: "-1" + Description: LAB - Allow All Private IP Communications + CidrIp: 192.168.0.0/16 + SecurityGroupEgress: + - Description: Allow All Outbound Communications + IpProtocol: "-1" + CidrIp: 0.0.0.0/0 + Tags: + - Key: Name + Value: !Sub ${DomainNetBiosName}-DomainMembersSG-ADConnector + Condition: DomainMembersSGCondition + + ADConnectorLambdaFunction: + Type: AWS::Lambda::Function + Metadata: + cfn_nag: + rules_to_suppress: + - id: W58 + reason: Permissions to write to CloudWatch Logs provided by the attached IAM role + Properties: + FunctionName: !Ref LambdaFunctionName + Handler: adconnector_custom_resource.lambda_handler + Role: !GetAtt ADConnectorLambdaRole.Arn + Runtime: python3.8 + MemorySize: 128 + Timeout: 120 + Environment: + Variables: + LOG_LEVEL: !Ref LambdaLogLevel + Code: + S3Bucket: !Ref LambdaS3BucketName + S3Key: !Ref LambdaZipFileName + VpcConfig: + SubnetIds: + - PrivateSubnet1ID + - PrivateSubnet2ID + SecurityGroupIds: + - !Ref ADConnectorDomainMembersSG + + ADConnectorLambdaLogsLogGroup: + DeletionPolicy: Retain + UpdateReplacePolicy: Retain + Type: AWS::Logs::LogGroup + Properties: + LogGroupName: !Sub /aws/lambda/${LambdaFunctionName} + RetentionInDays: !Ref LambdaLogsLogGroupRetention + KmsKeyId: !If + - LambdaLogsCloudWatchKMSKeyCondition + - !Ref LambdaLogsCloudWatchKMSKey + - !Ref AWS::NoValue + + ADConnectorLambdaRole: + Type: AWS::IAM::Role + Metadata: + cfn_nag: + rules_to_suppress: + - id: W11 + reason: Allow * in resource when required + - id: W28 + reason: The role name is defined to identify automation resources + Properties: + RoleName: !Sub ${LambdaFunctionName}-LambdaRole + Description: Rights to Setup AD Connector + AssumeRolePolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: sts:AssumeRole + Principal: + Service: + - lambda.amazonaws.com + Path: / + Tags: + - Key: StackName + Value: !Ref AWS::StackName + Policies: + - PolicyName: CloudWatchLogGroup + PolicyDocument: + Version: "2012-10-17" + Statement: + - Sid: CreateLogGroup + Effect: Allow + Action: logs:CreateLogGroup + Resource: !Sub arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:${ADConnectorLambdaLogsLogGroup} + - Sid: CreateLogStreamAndEvents + Effect: Allow + Action: + - logs:CreateLogStream + - logs:PutLogEvents + Resource: !Sub arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:${ADConnectorLambdaLogsLogGroup}:log-stream:* + - PolicyName: ADConnector + PolicyDocument: + Version: "2012-10-17" + Statement: + - Sid: Directory + Effect: Allow + Action: + - ds:ConnectDirectory + - ds:DeleteDirectory + Resource: '*' + - Sid: CreateAdConnectorEc2Resources + Effect: Allow + Action: + - ec2:DescribeSubnets + - ec2:DescribeVpcs + - ec2:CreateSecurityGroup + - ec2:CreateNetworkInterface + - ec2:DescribeNetworkInterfaces + - ec2:AuthorizeSecurityGroupIngress + - ec2:AuthorizeSecurityGroupEgress + - ec2:CreateTags + Resource: '*' + Condition: + Bool: + aws:ViaAWSService: true + - Sid: DeleteAdConnectorEc2Resources + Effect: Allow + Action: + - ec2:DeleteSecurityGroup + - ec2:DescribeNetworkInterfaces + - ec2:DeleteNetworkInterface + - ec2:RevokeSecurityGroupIngress + - ec2:RevokeSecurityGroupEgress + - ec2:DeleteTags + Resource: '*' + Condition: + Bool: + aws:ViaAWSService: true + - PolicyName: ADConnectorServiceAccountSecret + PolicyDocument: + Version: "2012-10-17" + Statement: + - Sid: GetSecret + Effect: Allow + Action: secretsmanager:GetSecretValue + Resource: !Ref ADConnectorServiceAccountSecret + - !If + - SecretsManagerDomainCredentialsSecretsKMSKeyCondition + - PolicyName: KMSKeyForSecret + PolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: kms:Decrypt + Resource: !Ref SecretsManagerDomainCredentialsSecretsKMSKey + - !Ref AWS::NoValue + + ADConnectorLinuxEC2DomainJoinInstanceProfile: + Type: AWS::IAM::InstanceProfile + Properties: + InstanceProfileName: !Ref ADConnectorLinuxEC2DomainJoinRole + Path: / + Roles: + - !Ref ADConnectorLinuxEC2DomainJoinRole + Condition: LinuxEC2DomainJoinResourcesCondition + + ADConnectorLinuxEC2DomainJoinRole: + Type: AWS::IAM::Role + Metadata: + cfn_nag: + rules_to_suppress: + - id: W28 + reason: The role name is defined to identify automation resources + Properties: + RoleName: !Sub ${DomainNetBiosName}-LinuxEC2DomainJoinRole-ADConnector + Description: !Sub IAM Role to Seamlessly Join Linux EC2 Instances to ${DomainNetBiosName} Domain via AD Connector + AssumeRolePolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: sts:AssumeRole + Principal: + Service: + - ec2.amazonaws.com + ManagedPolicyArns: + - !Sub arn:${AWS::Partition}:iam::aws:policy/AmazonSSMManagedInstanceCore + - !Sub arn:${AWS::Partition}:iam::aws:policy/AmazonSSMDirectoryServiceAccess + Path: / + Tags: + - Key: StackName + Value: !Ref AWS::StackName + Policies: + - PolicyName: SSMAgent + PolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: s3:GetObject + Resource: + - !Sub arn:${AWS::Partition}:s3:::aws-ssm-${AWS::Region}/* + - !Sub arn:${AWS::Partition}:s3:::aws-windows-downloads-${AWS::Region}/* + - !Sub arn:${AWS::Partition}:s3:::amazon-ssm-${AWS::Region}/* + - !Sub arn:${AWS::Partition}:s3:::amazon-ssm-packages-${AWS::Region}/* + - !Sub arn:${AWS::Partition}:s3:::${AWS::Region}-birdwatcher-prod/* + - !Sub arn:${AWS::Partition}:s3:::patch-baseline-snapshot-${AWS::Region}/* + - !Sub arn:${AWS::Partition}:s3:::aws-ssm-distributor-file-${AWS::Region}/* + - !Sub arn:${AWS::Partition}:s3:::aws-ssm-document-attachments-${AWS::Region}/* + - !If + - SSMLogsBucketNameCondition + - PolicyName: SsmLogs + PolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: + - s3:GetObject + - s3:PutObject + - s3:PutObjectAcl + - s3:GetEncryptionConfiguration + Resource: + - !Sub arn:${AWS::Partition}:s3:::${SSMLogsBucketName} + - !Sub arn:${AWS::Partition}:s3:::${SSMLogsBucketName}/* + - !Ref AWS::NoValue + - PolicyName: ADConnectorLinuxEC2SeamlessDomainJoinSecret + PolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: + - secretsmanager:GetSecretValue + - secretsmanager:DescribeSecret + Resource: !Ref ADConnectorLinuxEC2SeamlessDomainJoinSecret + - !If + - SecretsManagerDomainCredentialsSecretsKMSKeyCondition + - PolicyName: KMSKeyForSecret + PolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: kms:Decrypt + Resource: !Ref SecretsManagerDomainCredentialsSecretsKMSKey + - !Ref AWS::NoValue + Condition: LinuxEC2DomainJoinResourcesCondition + + ADConnectorLinuxEC2SeamlessDomainJoinSecret: + DeletionPolicy: Retain + UpdateReplacePolicy: Retain + Type: AWS::SecretsManager::Secret + Properties: + Name: !Sub aws/directory-services/${ADConnectorResource}/seamless-domain-join + Description: !Sub AD Credentials for Seamless Domain Join Windows/Linux EC2 instances to ${DomainNetBiosName} Domain via AD Connector + SecretString: !Sub '{ "awsSeamlessDomainUsername" : "${DomainJoinUser}", "awsSeamlessDomainPassword" : "${DomainJoinUserPassword}" }' + KmsKeyId: !If + - SecretsManagerDomainCredentialsSecretsKMSKeyCondition + - !Ref SecretsManagerDomainCredentialsSecretsKMSKey + - !Ref AWS::NoValue + Condition: LinuxEC2DomainJoinResourcesCondition + + ADConnectorResource: + Type: Custom::ADConnectorResource + Properties: + ServiceToken: !GetAtt ADConnectorLambdaFunction.Arn + ADCONNECTOR_DESCRIPTION: !Ref ADConnectorDescription + ADCONNECTOR_SIZE: !Ref ADConnectorSize + ADCONNECTOR_SUBNET_ID1: !Ref PrivateSubnet1ID + ADCONNECTOR_SUBNET_ID2: !Ref PrivateSubnet2ID + ADCONNECTOR_VPCID: !Ref VPCID + DOMAIN_DNS_NAME: !Ref DomainDNSName + DOMAIN_DNS_SERVERS: !Ref DomainDNSServers + DOMAIN_NETBIOS_NAME: !Ref DomainNetBiosName + DOMAIN_JOIN_SECRET_ID: !Ref ADConnectorServiceAccountSecret + Version: "1.0" + + ADConnectorServiceAccountSecret: + DeletionPolicy: Retain + UpdateReplacePolicy: Retain + Type: AWS::SecretsManager::Secret + Properties: + Name: !Sub ADConnector-ServiceAccount-${DomainNetBiosName}-Domain + Description: !Sub ADConnector Service Account for ${DomainNetBiosName} Domain + SecretString: !Sub '{ "username" : "${DomainJoinUser}", "password" : "${DomainJoinUserPassword}" }' + KmsKeyId: !If + - SecretsManagerDomainCredentialsSecretsKMSKeyCondition + - !Ref SecretsManagerDomainCredentialsSecretsKMSKey + - !Ref AWS::NoValue + + ADConnectorWindowsEC2DomainJoinInstanceProfile: + Type: AWS::IAM::InstanceProfile + Properties: + InstanceProfileName: !Ref ADConnectorWindowsEC2DomainJoinRole + Path: / + Roles: + - !Ref ADConnectorWindowsEC2DomainJoinRole + Condition: WindowsEC2DomainJoinResourcesCondition + + ADConnectorWindowsEC2DomainJoinRole: + Type: AWS::IAM::Role + Metadata: + cfn_nag: + rules_to_suppress: + - id: W28 + reason: The role name is defined to identify automation resources + Properties: + RoleName: !Sub ${DomainNetBiosName}-ADConnector-WindowsEC2DomainJoinRole + Description: !Sub IAM Role to Seamlessly Join Windows EC2 Instances to ${DomainDNSName} Domain via AD Connector + AssumeRolePolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: sts:AssumeRole + Principal: + Service: + - ec2.amazonaws.com + ManagedPolicyArns: + - !Sub arn:${AWS::Partition}:iam::aws:policy/AmazonSSMManagedInstanceCore + - !Sub arn:${AWS::Partition}:iam::aws:policy/AmazonSSMDirectoryServiceAccess + Path: / + Tags: + - Key: StackName + Value: !Ref AWS::StackName + Policies: + - PolicyName: SSMAgent + PolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: s3:GetObject + Resource: + - !Sub arn:${AWS::Partition}:s3:::aws-ssm-${AWS::Region}/* + - !Sub arn:${AWS::Partition}:s3:::aws-windows-downloads-${AWS::Region}/* + - !Sub arn:${AWS::Partition}:s3:::amazon-ssm-${AWS::Region}/* + - !Sub arn:${AWS::Partition}:s3:::amazon-ssm-packages-${AWS::Region}/* + - !Sub arn:${AWS::Partition}:s3:::${AWS::Region}-birdwatcher-prod/* + - !Sub arn:${AWS::Partition}:s3:::patch-baseline-snapshot-${AWS::Region}/* + - !Sub arn:${AWS::Partition}:s3:::aws-ssm-distributor-file-${AWS::Region}/* + - !Sub arn:${AWS::Partition}:s3:::aws-ssm-document-attachments-${AWS::Region}/* + - !If + - SSMLogsBucketNameCondition + - PolicyName: SsmLogs + PolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: + - s3:GetObject + - s3:PutObject + - s3:PutObjectAcl + - s3:GetEncryptionConfiguration + Resource: + - !Sub arn:${AWS::Partition}:s3:::${SSMLogsBucketName} + - !Sub arn:${AWS::Partition}:s3:::${SSMLogsBucketName}/* + - !Ref AWS::NoValue + Condition: WindowsEC2DomainJoinResourcesCondition + + DHCPOptions: + Type: AWS::EC2::DHCPOptions + Properties: + DomainName: !Ref DomainDNSName + DomainNameServers: + - !Ref DomainDNSServers + Tags: + - Key: Name + Value: !Ref DomainDNSName + Condition: DHCPOptionSetCondition + + DHCPOptionsVPCAssociation: + Type: AWS::EC2::VPCDHCPOptionsAssociation + Properties: + VpcId: !Ref VPCID + DhcpOptionsId: !Ref DHCPOptions + Condition: DHCPOptionSetCondition + +Outputs: + ADConnectorDirectoryId: + Description: AD Connector Directory ID + Value: !Ref ADConnectorResource + Export: + Name: !Sub ${AWS::StackName}-ADConnectorDirectoryId + + ADConnectorDirectoryName: + Description: AD Connector Directory Name + Value: !Ref DomainDNSName + Export: + Name: !Sub ${AWS::StackName}-ADConnectorDirectoryName + + ADConnectorADConnectorDomainMembersSG: + Description: ADConnector Domain Members Security Group + Value: !Ref ADConnectorDomainMembersSG + Export: + Name: !Sub ${AWS::StackName}-${DomainNetBiosName}-ADConnectorDomainMembersSG + Condition: DomainMembersSGCondition + + ADConnectorWindowsEC2SeamlessDomainJoinInstanceProfile: + Description: IAM Instance Profile with SSM Document Rights to Join Windows Computers via AD Connector + Value: !Ref ADConnectorWindowsEC2DomainJoinInstanceProfile + Export: + Name: !Sub ${AWS::StackName}-${DomainNetBiosName}-ADConnectorWindowsEC2DomainJoinProfile + Condition: WindowsEC2DomainJoinResourcesCondition + + ADConnectorWindowsEC2SeamlessDomainJoinRole: + Description: IAM Instance Profile with SSM Document Rights to Join Windows Computers via AD Connector + Value: !Ref ADConnectorWindowsEC2DomainJoinRole + Export: + Name: !Sub ${AWS::StackName}-${DomainNetBiosName}-ADConnectorWindowsEC2DomainJoinRole + Condition: WindowsEC2DomainJoinResourcesCondition + + ADConnectorLinuxEC2SeamlessDomainJoinInstanceProfile: + Description: IAM Instance Profile with SSM Document Rights to Join Linux Computers via AD Connector + Value: !Ref ADConnectorLinuxEC2DomainJoinInstanceProfile + Export: + Name: !Sub ${AWS::StackName}-${DomainNetBiosName}-ADConnectorLinuxEC2DomainJoinProfile + Condition: LinuxEC2DomainJoinResourcesCondition + + ADConnectorLinuxEC2SeamlessDomainJoinRole: + Description: IAM Instance Profile with SSM Document Rights to Join Linux Computers via AD Connector + Value: !Ref ADConnectorLinuxEC2DomainJoinRole + Export: + Name: !Sub ${AWS::StackName}-${DomainNetBiosName}-ADConnectorLinuxEC2DomainJoinRole + Condition: LinuxEC2DomainJoinResourcesCondition diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/README.md b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/README.md new file mode 100644 index 0000000000000000000000000000000000000000..cddd8f2f9151b9e225e8a70971f5f700c8e115c3 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/README.md @@ -0,0 +1,9 @@ +# Deploy the Amazon CloudWatch agent to Amazon EC2 instances using AWS CloudFormation +The /inline and /ssm directories include templates to help you install the Amazon CloudWatch agent on Amazon EC2 instances using AWS CloudFormation. You can also use the templates to update the agent configuration after deployment. For more information, see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-CloudFormation-Templates.html. + + +## /inline directory +The templates in the /inline directory have the CloudWatch agent configuration embedded into the AWS CloudFormation template. You can modify your CloudWatch agent configuration by modifying the template. + +## /ssm directory +The templates in the /ssm directory load the agent configuration from Parameter Store. To use these templates, you must first create a configuration file and upload it to Parameter Store. diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/amazon_linux.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/amazon_linux.json new file mode 100644 index 0000000000000000000000000000000000000000..181256e563e5030b2337e593e8f7bb851f2a46e4 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/amazon_linux.json @@ -0,0 +1,159 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "Template to install CloudWatchAgent on amazon linux. It was validated on amazon linux 2", + "Parameters": { + "KeyName": { + "Description": "Name of an existing EC2 KeyPair to enable SSH access to the instance", + "Type": "AWS::EC2::KeyPair::KeyName", + "ConstraintDescription": "must be the name of an existing EC2 KeyPair." + }, + "InstanceType": { + "Description": "EC2 instance type", + "Type": "String", + "Default": "t3.medium", + "ConstraintDescription": "must be a valid EC2 instance type." + }, + "InstanceAMI": { + "Description": "Managed AMI ID for EC2 Instance", + "Type": "AWS::SSM::Parameter::Value", + "Default": "/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64" + }, + "IAMRole": { + "Description": "EC2 attached IAM role", + "Type": "String", + "Default": "CloudWatchAgentAdminRole", + "ConstraintDescription": "must be an existing IAM role which will be attached to EC2 instance." + }, + "SSHLocation": { + "Description": "The IP address range that can be used to SSH to the EC2 instances", + "Type": "String", + "Default": "0.0.0.0/0", + "MinLength": "9", + "MaxLength": "18", + "AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})", + "ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x." + }, + "SubnetId": { + "Type": "AWS::EC2::Subnet::Id" + } + }, + "Resources": { + "EC2Instance": { + "CreationPolicy": { + "ResourceSignal": { + "Count": 1, + "Timeout": "PT15M" + } + }, + "Type": "AWS::EC2::Instance", + "Metadata": { + "AWS::CloudFormation::Init": { + "configSets": { + "default": [ + "01_setupCfnHup", + "02_config-amazon-cloudwatch-agent", + "03_restart_amazon-cloudwatch-agent" + ], + "UpdateEnvironment": [ + "02_config-amazon-cloudwatch-agent", + "03_restart_amazon-cloudwatch-agent" + ] + }, + "02_config-amazon-cloudwatch-agent": { + "files": { + "/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json": { + "content": "{\n \"metrics\": {\n \"append_dimensions\": {\n \"AutoScalingGroupName\": \"${!aws:AutoScalingGroupName}\",\n \"ImageId\": \"${!aws:ImageId}\",\n \"InstanceId\": \"${!aws:InstanceId}\",\n \"InstanceType\": \"${!aws:InstanceType}\"\n },\n \"metrics_collected\": {\n \"mem\": {\n \"measurement\": [\n \"mem_used_percent\"\n ]\n },\n \"swap\": {\n \"measurement\": [\n \"swap_used_percent\"\n ]\n }\n }\n }\n}\n" + } + } + }, + "03_restart_amazon-cloudwatch-agent": { + "commands": { + "01_stop_service": { + "command": "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop" + }, + "02_start_service": { + "command": "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json -s" + } + } + }, + "01_setupCfnHup": { + "files": { + "/etc/cfn/cfn-hup.conf": { + "content": { + "Fn::Sub": "[main]\nstack=${AWS::StackId}\nregion=${AWS::Region}\ninterval=1\n" + }, + "mode": "000400", + "owner": "root", + "group": "root" + }, + "/etc/cfn/hooks.d/amazon-cloudwatch-agent-auto-reloader.conf": { + "content": { + "Fn::Sub": "[cfn-auto-reloader-hook]\ntriggers=post.update\npath=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init.02_config-amazon-cloudwatch-agent\naction=/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets UpdateEnvironment\nrunas=root\n" + }, + "mode": "000400", + "owner": "root", + "group": "root" + }, + "/lib/systemd/system/cfn-hup.service": { + "content": "[Unit]\nDescription=cfn-hup daemon\n[Service]\nType=simple\nExecStart=/opt/aws/bin/cfn-hup\nRestart=always\n[Install]\nWantedBy=multi-user.target\n" + } + }, + "commands": { + "01enable_cfn_hup": { + "command": "systemctl enable cfn-hup.service" + }, + "02start_cfn_hup": { + "command": "systemctl start cfn-hup.service" + } + } + } + } + }, + "Properties": { + "InstanceType": { + "Ref": "InstanceType" + }, + "IamInstanceProfile": { + "Ref": "IAMRole" + }, + "KeyName": { + "Ref": "KeyName" + }, + "ImageId": { + "Ref": "InstanceAMI" + }, + "SubnetId": { + "Ref": "SubnetId" + }, + "SecurityGroupIds": [ + { + + "Fn::GetAtt" : [ "InstanceSecurityGroup", "GroupId" ] + } + + ], + "UserData": { + "Fn::Base64": { + "Fn::Sub": "#!/bin/bash\nrpm -Uvh https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm\n/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets default\n/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region}\n" + } + } + } + }, + "InstanceSecurityGroup": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "Enable SSH access via port 22", + "SecurityGroupIngress": [ + { + "IpProtocol": "tcp", + "FromPort": "22", + "ToPort": "22", + "CidrIp": { + "Ref": "SSHLocation" + } + } + ] + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/amazon_linux.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/amazon_linux.yaml new file mode 100644 index 0000000000000000000000000000000000000000..895075e45545cce833df7803d1d6271e57766cfd --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/amazon_linux.yaml @@ -0,0 +1,155 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: Template to install CloudWatchAgent on amazon linux. It was validated on amazon linux 2 + +Parameters: + KeyName: + Description: Name of an existing EC2 KeyPair to enable SSH access to the instance + Type: AWS::EC2::KeyPair::KeyName + ConstraintDescription: must be the name of an existing EC2 KeyPair. + + InstanceType: + Description: EC2 instance type + Type: String + Default: t3.medium + ConstraintDescription: must be a valid EC2 instance type. + + InstanceAMI: + Description: Managed AMI ID for EC2 Instance + Type: AWS::SSM::Parameter::Value + Default: /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64 + + IAMRole: + Description: EC2 attached IAM role + Type: String + Default: CloudWatchAgentAdminRole + ConstraintDescription: must be an existing IAM role which will be attached to EC2 instance. + + SSHLocation: + Description: The IP address range that can be used to SSH to the EC2 instances + Type: String + Default: 0.0.0.0/0 + MinLength: "9" + MaxLength: "18" + AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2}) + ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x. + + SubnetId: + Type: AWS::EC2::Subnet::Id + +Resources: + EC2Instance: + CreationPolicy: + ResourceSignal: + Count: 1 + Timeout: PT15M + Type: AWS::EC2::Instance + Metadata: + AWS::CloudFormation::Init: + configSets: + default: + - 01_setupCfnHup + - 02_config-amazon-cloudwatch-agent + - 03_restart_amazon-cloudwatch-agent + UpdateEnvironment: + - 02_config-amazon-cloudwatch-agent + - 03_restart_amazon-cloudwatch-agent + + # Definition of json configuration of AmazonCloudWatchAgent, you can change the configuration below. + 02_config-amazon-cloudwatch-agent: + files: + /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json: + content: | + { + "metrics": { + "append_dimensions": { + "AutoScalingGroupName": "${!aws:AutoScalingGroupName}", + "ImageId": "${!aws:ImageId}", + "InstanceId": "${!aws:InstanceId}", + "InstanceType": "${!aws:InstanceType}" + }, + "metrics_collected": { + "mem": { + "measurement": [ + "mem_used_percent" + ] + }, + "swap": { + "measurement": [ + "swap_used_percent" + ] + } + } + } + } + + # Invoke amazon-cloudwatch-agent-ctl to restart the AmazonCloudWatchAgent. + 03_restart_amazon-cloudwatch-agent: + commands: + 01_stop_service: + command: /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop + 02_start_service: + command: /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json -s + + # Cfn-hup setting, it is to monitor the change of metadata. + # When there is change in the contents of json file in the metadata section, cfn-hup will call cfn-init to restart the AmazonCloudWatchAgent. + 01_setupCfnHup: + files: + /etc/cfn/cfn-hup.conf: + content: !Sub | + [main] + stack=${AWS::StackId} + region=${AWS::Region} + interval=1 + mode: "000400" + owner: root + group: root + /etc/cfn/hooks.d/amazon-cloudwatch-agent-auto-reloader.conf: + content: !Sub | + [cfn-auto-reloader-hook] + triggers=post.update + path=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init.02_config-amazon-cloudwatch-agent + action=/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets UpdateEnvironment + runas=root + mode: "000400" + owner: root + group: root + /lib/systemd/system/cfn-hup.service: + content: | + [Unit] + Description=cfn-hup daemon + [Service] + Type=simple + ExecStart=/opt/aws/bin/cfn-hup + Restart=always + [Install] + WantedBy=multi-user.target + commands: + 01enable_cfn_hup: + command: systemctl enable cfn-hup.service + 02start_cfn_hup: + command: systemctl start cfn-hup.service + Properties: + InstanceType: !Ref InstanceType + IamInstanceProfile: !Ref IAMRole + KeyName: !Ref KeyName + ImageId: !Ref InstanceAMI + SubnetId: !Ref SubnetId + SecurityGroupIds: + - !GetAtt InstanceSecurityGroup.GroupId + UserData: !Base64 + Fn::Sub: | + #!/bin/bash + rpm -Uvh https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm + /opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets default + /opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} + + InstanceSecurityGroup: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Enable SSH access via port 22 + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: "22" + ToPort: "22" + CidrIp: !Ref SSHLocation diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/centos.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/centos.json new file mode 100644 index 0000000000000000000000000000000000000000..d259dad0ac7f0963ec4466f02e0ddff517859227 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/centos.json @@ -0,0 +1,203 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "Template to install CloudWatchAgent on centos. It was validated on centos 7", + "Parameters": { + "KeyName": { + "Description": "Name of an existing EC2 KeyPair to enable SSH access to the instance", + "Type": "AWS::EC2::KeyPair::KeyName", + "ConstraintDescription": "must be the name of an existing EC2 KeyPair." + }, + "InstanceType": { + "Description": "EC2 instance type", + "Type": "String", + "Default": "t3.medium", + "ConstraintDescription": "must be a valid EC2 instance type." + }, + "CentOSVersion": { + "Type": "String", + "AllowedValues": [ + "CentOS9" + ], + "Default": "CentOS9", + "Description": "CentOS version to deploy" + }, + "IAMRole": { + "Description": "EC2 attached IAM role", + "Type": "String", + "Default": "CloudWatchAgentAdminRole", + "ConstraintDescription": "must be an existing IAM role which will be attached to EC2 instance." + }, + "SSHLocation": { + "Description": "The IP address range that can be used to SSH to the EC2 instances", + "Type": "String", + "Default": "0.0.0.0/0", + "MinLength": "9", + "MaxLength": "18", + "AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})", + "ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x." + }, + "SubnetId": { + "Type": "AWS::EC2::Subnet::Id" + } + }, + "Mappings": { + "RegionMap": { + "us-east-1": { + "CentOS9": "ami-0705f7887207411ca" + }, + "us-east-2": { + "CentOS9": "ami-0fe2c46c1dc3889fa" + }, + "us-west-1": { + "CentOS9": "ami-0f4f63d1732fd4ef5" + }, + "us-west-2": { + "CentOS9": "ami-00b231246df1d28de" + }, + "eu-west-1": { + "CentOS9": "ami-05a7b8270231783b2" + }, + "eu-west-2": { + "RHEL9": "ami-0086646e63ce5aaf1" + }, + "ap-northeast-1": { + "RHEL9": "ami-0d8ee41b4b6f8343b" + }, + "ap-northeast-2": { + "RHEL9": "ami-031e0786d2134adf6" + }, + "ap-southeast-1": { + "RHEL9": "ami-0a9082a6b182a840b" + }, + "ap-southeast-2": { + "RHEL9": "ami-05ffc8a6cb624035b" + } + } + }, + "Resources": { + "EC2Instance": { + "CreationPolicy": { + "ResourceSignal": { + "Count": 1, + "Timeout": "PT15M" + } + }, + "Type": "AWS::EC2::Instance", + "Metadata": { + "AWS::CloudFormation::Init": { + "configSets": { + "default": [ + "01_setupCfnHup", + "02_config-amazon-cloudwatch-agent", + "03_restart_amazon-cloudwatch-agent" + ], + "UpdateEnvironment": [ + "02_config-amazon-cloudwatch-agent", + "03_restart_amazon-cloudwatch-agent" + ] + }, + "02_config-amazon-cloudwatch-agent": { + "files": { + "/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json": { + "content": "{\n \"metrics\": {\n \"append_dimensions\": {\n \"AutoScalingGroupName\": \"${!aws:AutoScalingGroupName}\",\n \"ImageId\": \"${!aws:ImageId}\",\n \"InstanceId\": \"${!aws:InstanceId}\",\n \"InstanceType\": \"${!aws:InstanceType}\"\n },\n \"metrics_collected\": {\n \"mem\": {\n \"measurement\": [\n \"mem_used_percent\"\n ]\n },\n \"swap\": {\n \"measurement\": [\n \"swap_used_percent\"\n ]\n }\n }\n }\n}\n" + } + } + }, + "03_restart_amazon-cloudwatch-agent": { + "commands": { + "01_stop_service": { + "command": "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop" + }, + "02_start_service": { + "command": "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json -s" + } + } + }, + "01_setupCfnHup": { + "files": { + "/etc/cfn/cfn-hup.conf": { + "content": { + "Fn::Sub": "[main]\nstack=${AWS::StackId}\nregion=${AWS::Region}\ninterval=1\n" + }, + "mode": "000400", + "owner": "root", + "group": "root" + }, + "/etc/cfn/hooks.d/amazon-cloudwatch-agent-auto-reloader.conf": { + "content": { + "Fn::Sub": "[cfn-auto-reloader-hook]\ntriggers=post.update\npath=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init.02_config-amazon-cloudwatch-agent\naction=/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets UpdateEnvironment\nrunas=root\n" + }, + "mode": "000400", + "owner": "root", + "group": "root" + }, + "/lib/systemd/system/cfn-hup.service": { + "content": "[Unit]\nDescription=cfn-hup daemon\n[Service]\nType=simple\nExecStart=/opt/aws/bin/cfn-hup\nRestart=always\n[Install]\nWantedBy=multi-user.target\n" + } + }, + "commands": { + "01enable_cfn_hup": { + "command": "systemctl enable cfn-hup.service" + }, + "02start_cfn_hup": { + "command": "systemctl start cfn-hup.service" + } + } + } + } + }, + "Properties": { + "InstanceType": { + "Ref": "InstanceType" + }, + "IamInstanceProfile": { + "Ref": "IAMRole" + }, + "KeyName": { + "Ref": "KeyName" + }, + "ImageId": { + "Fn::FindInMap": [ + "RegionMap", + { + "Ref": "AWS::Region" + }, + { + "Ref": "CentOSVersion" + } + ] + }, + "SubnetId": { + "Ref": "SubnetId" + }, + "SecurityGroupIds": [ + { + + "Fn::GetAtt" : [ "InstanceSecurityGroup", "GroupId" ] + } + ], + "UserData": { + "Fn::Base64": { + "Fn::Sub": "#!/bin/bash\nrpm -Uvh https://s3.amazonaws.com/amazoncloudwatch-agent/centos/amd64/latest/amazon-cloudwatch-agent.rpm\nyum update -y\nyum install python3 -y\ncurl -O https://bootstrap.pypa.io/get-pip.py\n# Install pip using python3\npython3 get-pip.py\nexport PATH=$PATH:/usr/local/bin\npip3 install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz\ncfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets default\ncfn-signal -e $? --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region}\n" + } + } + } + }, + "InstanceSecurityGroup": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "Enable SSH access via port 22", + "SecurityGroupIngress": [ + { + "IpProtocol": "tcp", + "FromPort": "22", + "ToPort": "22", + "CidrIp": { + "Ref": "SSHLocation" + } + } + ] + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/centos.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/centos.yaml new file mode 100644 index 0000000000000000000000000000000000000000..51d813cb1e51d7325623ab15e78d684617e9a9e1 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/centos.yaml @@ -0,0 +1,190 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: Template to install CloudWatchAgent on centos. It was validated on centos 7 + +Parameters: + KeyName: + Description: Name of an existing EC2 KeyPair to enable SSH access to the instance + Type: AWS::EC2::KeyPair::KeyName + ConstraintDescription: must be the name of an existing EC2 KeyPair. + + InstanceType: + Description: EC2 instance type + Type: String + Default: t3.medium + ConstraintDescription: must be a valid EC2 instance type. + + CentOSVersion: + Type: String + AllowedValues: + - CentOS9 + Default: CentOS9 + Description: CentOS version to deploy + + IAMRole: + Description: EC2 attached IAM role + Type: String + Default: CloudWatchAgentAdminRole + ConstraintDescription: must be an existing IAM role which will be attached to EC2 instance. + + SSHLocation: + Description: The IP address range that can be used to SSH to the EC2 instances + Type: String + Default: 0.0.0.0/0 + MinLength: "9" + MaxLength: "18" + AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2}) + ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x. + + SubnetId: + Type: AWS::EC2::Subnet::Id + +Mappings: + RegionMap: + us-east-1: + CentOS9: ami-0705f7887207411ca + us-east-2: + CentOS9: ami-0fe2c46c1dc3889fa + us-west-1: + CentOS9: ami-0f4f63d1732fd4ef5 + us-west-2: + CentOS9: ami-00b231246df1d28de + eu-west-1: + CentOS9: ami-05a7b8270231783b2 + eu-west-2: + CentOS9: ami-0086646e63ce5aaf1 + ap-northeast-1: + CentOS9: ami-0d8ee41b4b6f8343b + ap-northeast-2: + CentOS9: ami-031e0786d2134adf6 + ap-southeast-1: + CentOS9: ami-0a9082a6b182a840b + ap-southeast-2: + CentOS9: ami-05ffc8a6cb624035b + +Resources: + EC2Instance: + CreationPolicy: + ResourceSignal: + Count: 1 + Timeout: PT15M + Type: AWS::EC2::Instance + Metadata: + AWS::CloudFormation::Init: + configSets: + default: + - 01_setupCfnHup + - 02_config-amazon-cloudwatch-agent + - 03_restart_amazon-cloudwatch-agent + UpdateEnvironment: + - 02_config-amazon-cloudwatch-agent + - 03_restart_amazon-cloudwatch-agent + + # Definition of json configuration of AmazonCloudWatchAgent, you can change the configuration below. + 02_config-amazon-cloudwatch-agent: + files: + /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json: + content: | + { + "metrics": { + "append_dimensions": { + "AutoScalingGroupName": "${!aws:AutoScalingGroupName}", + "ImageId": "${!aws:ImageId}", + "InstanceId": "${!aws:InstanceId}", + "InstanceType": "${!aws:InstanceType}" + }, + "metrics_collected": { + "mem": { + "measurement": [ + "mem_used_percent" + ] + }, + "swap": { + "measurement": [ + "swap_used_percent" + ] + } + } + } + } + + # Invoke amazon-cloudwatch-agent-ctl to restart the AmazonCloudWatchAgent. + 03_restart_amazon-cloudwatch-agent: + commands: + 01_stop_service: + command: /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop + 02_start_service: + command: /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json -s + + # Cfn-hup setting, it is to monitor the change of metadata. + # When there is change in the contents of json file in the metadata section, cfn-hup will call cfn-init to restart the AmazonCloudWatchAgent. + 01_setupCfnHup: + files: + /etc/cfn/cfn-hup.conf: + content: !Sub | + [main] + stack=${AWS::StackId} + region=${AWS::Region} + interval=1 + mode: "000400" + owner: root + group: root + /etc/cfn/hooks.d/amazon-cloudwatch-agent-auto-reloader.conf: + content: !Sub | + [cfn-auto-reloader-hook] + triggers=post.update + path=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init.02_config-amazon-cloudwatch-agent + action=/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets UpdateEnvironment + runas=root + mode: "000400" + owner: root + group: root + /lib/systemd/system/cfn-hup.service: + content: | + [Unit] + Description=cfn-hup daemon + [Service] + Type=simple + ExecStart=/opt/aws/bin/cfn-hup + Restart=always + [Install] + WantedBy=multi-user.target + commands: + 01enable_cfn_hup: + command: systemctl enable cfn-hup.service + 02start_cfn_hup: + command: systemctl start cfn-hup.service + Properties: + InstanceType: !Ref InstanceType + IamInstanceProfile: !Ref IAMRole + KeyName: !Ref KeyName + ImageId: !FindInMap + - RegionMap + - !Ref 'AWS::Region' + - !Ref CentOSVersion + SubnetId: !Ref SubnetId + SecurityGroupIds: + - !GetAtt InstanceSecurityGroup.GroupId + UserData: !Base64 + Fn::Sub: | + #!/bin/bash + rpm -Uvh https://s3.amazonaws.com/amazoncloudwatch-agent/centos/amd64/latest/amazon-cloudwatch-agent.rpm + yum update -y + yum install python3 -y + curl -O https://bootstrap.pypa.io/get-pip.py + # Install pip using python3 + python3 get-pip.py + export PATH=$PATH:/usr/local/bin + pip3 install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz + cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets default + cfn-signal -e $? --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} + + InstanceSecurityGroup: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Enable SSH access via port 22 + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: "22" + ToPort: "22" + CidrIp: !Ref SSHLocation diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/debian.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/debian.json new file mode 100644 index 0000000000000000000000000000000000000000..6e8b52c53533186fe6fd0dcc29db4083bc8391db --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/debian.json @@ -0,0 +1,158 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "Template to install CloudWatchAgent on debian. It was validated on debian 12.0", + "Parameters": { + "KeyName": { + "Description": "Name of an existing EC2 KeyPair to enable SSH access to the instance", + "Type": "AWS::EC2::KeyPair::KeyName", + "ConstraintDescription": "must be the name of an existing EC2 KeyPair." + }, + "InstanceType": { + "Description": "EC2 instance type", + "Type": "String", + "Default": "t3.medium", + "ConstraintDescription": "must be a valid EC2 instance type." + }, + "InstanceAMI": { + "Description": "Managed AMI ID for EC2 Instance", + "Type": "AWS::SSM::Parameter::Value", + "Default": "/aws/service/debian/release/10/latest/amd64" + }, + "IAMRole": { + "Description": "EC2 attached IAM role", + "Type": "String", + "Default": "CloudWatchAgentAdminRole", + "ConstraintDescription": "must be an existing IAM role which will be attached to EC2 instance." + }, + "SSHLocation": { + "Description": "The IP address range that can be used to SSH to the EC2 instances", + "Type": "String", + "Default": "0.0.0.0/0", + "MinLength": "9", + "MaxLength": "18", + "AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})", + "ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x." + }, + "SubnetId": { + "Type": "AWS::EC2::Subnet::Id" + } + }, + "Resources": { + "EC2Instance": { + "CreationPolicy": { + "ResourceSignal": { + "Count": 1, + "Timeout": "PT15M" + } + }, + "Type": "AWS::EC2::Instance", + "Metadata": { + "AWS::CloudFormation::Init": { + "configSets": { + "default": [ + "01_setupCfnHup", + "02_config-amazon-cloudwatch-agent", + "03_restart_amazon-cloudwatch-agent" + ], + "UpdateEnvironment": [ + "02_config-amazon-cloudwatch-agent", + "03_restart_amazon-cloudwatch-agent" + ] + }, + "02_config-amazon-cloudwatch-agent": { + "files": { + "/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json": { + "content": "{\n \"metrics\": {\n \"append_dimensions\": {\n \"AutoScalingGroupName\": \"${!aws:AutoScalingGroupName}\",\n \"ImageId\": \"${!aws:ImageId}\",\n \"InstanceId\": \"${!aws:InstanceId}\",\n \"InstanceType\": \"${!aws:InstanceType}\"\n },\n \"metrics_collected\": {\n \"mem\": {\n \"measurement\": [\n \"mem_used_percent\"\n ]\n },\n \"swap\": {\n \"measurement\": [\n \"swap_used_percent\"\n ]\n }\n }\n }\n}\n" + } + } + }, + "03_restart_amazon-cloudwatch-agent": { + "commands": { + "01_stop_service": { + "command": "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop" + }, + "02_start_service": { + "command": "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json -s" + } + } + }, + "01_setupCfnHup": { + "files": { + "/etc/cfn/cfn-hup.conf": { + "content": { + "Fn::Sub": "[main]\nstack=${AWS::StackId}\nregion=${AWS::Region}\ninterval=1\n" + }, + "mode": "000400", + "owner": "root", + "group": "root" + }, + "/etc/cfn/hooks.d/amazon-cloudwatch-agent-auto-reloader.conf": { + "content": { + "Fn::Sub": "[cfn-auto-reloader-hook]\ntriggers=post.update\npath=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init.02_config-amazon-cloudwatch-agent\naction=/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets UpdateEnvironment\nrunas=root\n" + }, + "mode": "000400", + "owner": "root", + "group": "root" + }, + "/lib/systemd/system/cfn-hup.service": { + "content": "[Unit]\nDescription=cfn-hup daemon\n[Service]\nType=simple\nExecStart=/opt/aws/bin/cfn-hup\nRestart=always\n[Install]\nWantedBy=multi-user.target\n" + } + }, + "commands": { + "01enable_cfn_hup": { + "command": "systemctl enable cfn-hup.service" + }, + "02start_cfn_hup": { + "command": "systemctl start cfn-hup.service" + } + } + } + } + }, + "Properties": { + "InstanceType": { + "Ref": "InstanceType" + }, + "IamInstanceProfile": { + "Ref": "IAMRole" + }, + "KeyName": { + "Ref": "KeyName" + }, + "ImageId": { + "Ref": "InstanceAMI" + }, + "SubnetId": { + "Ref": "SubnetId" + }, + "SecurityGroupIds": [ + { + + "Fn::GetAtt" : [ "InstanceSecurityGroup", "GroupId" ] + } + ], + "UserData": { + "Fn::Base64": { + "Fn::Sub": "#!/bin/bash\nwget https://s3.amazonaws.com/amazoncloudwatch-agent/debian/amd64/latest/amazon-cloudwatch-agent.deb -O /tmp/amazon-cloudwatch-agent.deb\nsudo dpkg -i /tmp/amazon-cloudwatch-agent.deb\nwget https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz -O /tmp/aws-cfn-bootstrap-py3-latest.tar.gz\nsudo apt-get update -y\nsudo apt-get install -y python3-pip python3-venv\n\n# Create and activate a virtual environment\npython3 -m venv /opt/aws/virtualenv\nsource /opt/aws/virtualenv/bin/activate\n\n# Install the bootstrap package\npip install /tmp/aws-cfn-bootstrap-py3-latest.tar.gz\n\n# Create necessary symlinks\nsudo mkdir -p /opt/aws/bin\nsudo ln -s /opt/aws/virtualenv/bin/cfn-* /opt/aws/bin/\n\n# Run cfn-init\n/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets default\n/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region}\n" + } + } + } + }, + "InstanceSecurityGroup": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "Enable SSH access via port 22", + "SecurityGroupIngress": [ + { + "IpProtocol": "tcp", + "FromPort": "22", + "ToPort": "22", + "CidrIp": { + "Ref": "SSHLocation" + } + } + ] + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/debian.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/debian.yaml new file mode 100644 index 0000000000000000000000000000000000000000..147bef72903e116fb3c7550d820a315ad5544c0a --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/debian.yaml @@ -0,0 +1,172 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: Template to install CloudWatchAgent on debian. It was validated on debian 12.0 + +Parameters: + KeyName: + Description: Name of an existing EC2 KeyPair to enable SSH access to the instance + Type: AWS::EC2::KeyPair::KeyName + ConstraintDescription: must be the name of an existing EC2 KeyPair. + + InstanceType: + Description: EC2 instance type + Type: String + Default: t3.medium + ConstraintDescription: must be a valid EC2 instance type. + + InstanceAMI: + Description: Managed AMI ID for EC2 Instance + Type: AWS::SSM::Parameter::Value + Default: /aws/service/debian/release/10/latest/amd64 + + IAMRole: + Description: EC2 attached IAM role + Type: String + Default: CloudWatchAgentAdminRole + ConstraintDescription: must be an existing IAM role which will be attached to EC2 instance. + + SSHLocation: + Description: The IP address range that can be used to SSH to the EC2 instances + Type: String + Default: 0.0.0.0/0 + MinLength: "9" + MaxLength: "18" + AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2}) + ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x. + + SubnetId: + Type: AWS::EC2::Subnet::Id + +Resources: + EC2Instance: + CreationPolicy: + ResourceSignal: + Count: 1 + Timeout: PT15M + Type: AWS::EC2::Instance + Metadata: + AWS::CloudFormation::Init: + configSets: + default: + - 01_setupCfnHup + - 02_config-amazon-cloudwatch-agent + - 03_restart_amazon-cloudwatch-agent + UpdateEnvironment: + - 02_config-amazon-cloudwatch-agent + - 03_restart_amazon-cloudwatch-agent + + # Definition of json configuration of AmazonCloudWatchAgent, you can change the configuration below. + 02_config-amazon-cloudwatch-agent: + files: + /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json: + content: | + { + "metrics": { + "append_dimensions": { + "AutoScalingGroupName": "${!aws:AutoScalingGroupName}", + "ImageId": "${!aws:ImageId}", + "InstanceId": "${!aws:InstanceId}", + "InstanceType": "${!aws:InstanceType}" + }, + "metrics_collected": { + "mem": { + "measurement": [ + "mem_used_percent" + ] + }, + "swap": { + "measurement": [ + "swap_used_percent" + ] + } + } + } + } + + # Invoke amazon-cloudwatch-agent-ctl to restart the AmazonCloudWatchAgent. + 03_restart_amazon-cloudwatch-agent: + commands: + 01_stop_service: + command: /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop + 02_start_service: + command: /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json -s + + # Cfn-hup setting, it is to monitor the change of metadata. + # When there is change in the contents of json file in the metadata section, cfn-hup will call cfn-init to restart the AmazonCloudWatchAgent. + 01_setupCfnHup: + files: + /etc/cfn/cfn-hup.conf: + content: !Sub | + [main] + stack=${AWS::StackId} + region=${AWS::Region} + interval=1 + mode: "000400" + owner: root + group: root + /etc/cfn/hooks.d/amazon-cloudwatch-agent-auto-reloader.conf: + content: !Sub | + [cfn-auto-reloader-hook] + triggers=post.update + path=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init.02_config-amazon-cloudwatch-agent + action=/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets UpdateEnvironment + runas=root + mode: "000400" + owner: root + group: root + /lib/systemd/system/cfn-hup.service: + content: | + [Unit] + Description=cfn-hup daemon + [Service] + Type=simple + ExecStart=/opt/aws/bin/cfn-hup + Restart=always + [Install] + WantedBy=multi-user.target + commands: + 01enable_cfn_hup: + command: systemctl enable cfn-hup.service + 02start_cfn_hup: + command: systemctl start cfn-hup.service + Properties: + InstanceType: !Ref InstanceType + IamInstanceProfile: !Ref IAMRole + KeyName: !Ref KeyName + ImageId: !Ref InstanceAMI + SubnetId: !Ref SubnetId + SecurityGroupIds: + - !GetAtt InstanceSecurityGroup.GroupId + UserData: !Base64 + Fn::Sub: | + #!/bin/bash + wget https://s3.amazonaws.com/amazoncloudwatch-agent/debian/amd64/latest/amazon-cloudwatch-agent.deb -O /tmp/amazon-cloudwatch-agent.deb + sudo dpkg -i /tmp/amazon-cloudwatch-agent.deb + wget https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz -O /tmp/aws-cfn-bootstrap-py3-latest.tar.gz + sudo apt-get update -y + sudo apt-get install -y python3-pip python3-venv + + # Create and activate a virtual environment + python3 -m venv /opt/aws/virtualenv + source /opt/aws/virtualenv/bin/activate + + # Install the bootstrap package + pip install /tmp/aws-cfn-bootstrap-py3-latest.tar.gz + + # Create necessary symlinks + sudo mkdir -p /opt/aws/bin + sudo ln -s /opt/aws/virtualenv/bin/cfn-* /opt/aws/bin/ + + # Run cfn-init + /opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets default + /opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} + + InstanceSecurityGroup: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Enable SSH access via port 22 + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: "22" + ToPort: "22" + CidrIp: !Ref SSHLocation diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/redhat.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/redhat.json new file mode 100644 index 0000000000000000000000000000000000000000..69b7d8d221e9966eee86cd13d27e7f7223038bbf --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/redhat.json @@ -0,0 +1,205 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "Template to install CloudWatchAgent on redhat. It was validated on redhat 7.5", + "Parameters": { + "KeyName": { + "Description": "Name of an existing EC2 KeyPair to enable SSH access to the instance", + "Type": "AWS::EC2::KeyPair::KeyName", + "ConstraintDescription": "must be the name of an existing EC2 KeyPair." + }, + "InstanceType": { + "Description": "EC2 instance type", + "Type": "String", + "Default": "t3.medium", + "ConstraintDescription": "must be a valid EC2 instance type." + }, + "RHELVersion": { + "Type": "String", + "AllowedValues": [ + "RHEL9" + ], + "Default": "RHEL9", + "Description": "RHEL version to deploy" + }, + "IAMRole": { + "Description": "EC2 attached IAM role", + "Type": "String", + "Default": "CloudWatchAgentAdminRole", + "ConstraintDescription": "must be an existing IAM role which will be attached to EC2 instance." + }, + "SSHLocation": { + "Description": "The IP address range that can be used to SSH to the EC2 instances", + "Type": "String", + "Default": "0.0.0.0/0", + "MinLength": "9", + "MaxLength": "18", + "AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})", + "ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x." + }, + "SubnetId": { + "Type": "AWS::EC2::Subnet::Id" + } + }, + + "Mappings": { + "RegionMap": { + "us-east-1": { + "RHEL9": "ami-0fb13bb53494158e9" + }, + "us-east-2": { + "RHEL9": "ami-0aeea2f24f6d3ba32" + }, + "us-west-1": { + "RHEL9": "ami-068c2af1200ef7356" + }, + "us-west-2": { + "RHEL9": "ami-0367f2b5c3d1ef960" + }, + "eu-west-1": { + "RHEL9": "ami-0f0f1c02e5e4d9d9f" + }, + "eu-west-2": { + "RHEL9": "ami-02b1e3a99e36afd1a" + }, + "ap-northeast-1": { + "RHEL9": "ami-0eade93757ef7bb6c" + }, + "ap-northeast-2": { + "RHEL9": "ami-097698b6cd8164ea2" + }, + "ap-southeast-1": { + "RHEL9": "ami-0b9521fddc9871128" + }, + "ap-southeast-2": { + "RHEL9": "ami-0eea634029e7b983c" + } + } + }, + + "Resources": { + "EC2Instance": { + "CreationPolicy": { + "ResourceSignal": { + "Count": 1, + "Timeout": "PT15M" + } + }, + "Type": "AWS::EC2::Instance", + "Metadata": { + "AWS::CloudFormation::Init": { + "configSets": { + "default": [ + "01_setupCfnHup", + "02_config-amazon-cloudwatch-agent", + "03_restart_amazon-cloudwatch-agent" + ], + "UpdateEnvironment": [ + "02_config-amazon-cloudwatch-agent", + "03_restart_amazon-cloudwatch-agent" + ] + }, + "02_config-amazon-cloudwatch-agent": { + "files": { + "/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json": { + "content": "{\n \"metrics\": {\n \"append_dimensions\": {\n \"AutoScalingGroupName\": \"${!aws:AutoScalingGroupName}\",\n \"ImageId\": \"${!aws:ImageId}\",\n \"InstanceId\": \"${!aws:InstanceId}\",\n \"InstanceType\": \"${!aws:InstanceType}\"\n },\n \"metrics_collected\": {\n \"mem\": {\n \"measurement\": [\n \"mem_used_percent\"\n ]\n },\n \"swap\": {\n \"measurement\": [\n \"swap_used_percent\"\n ]\n }\n }\n }\n}\n" + } + } + }, + "03_restart_amazon-cloudwatch-agent": { + "commands": { + "01_stop_service": { + "command": "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop" + }, + "02_start_service": { + "command": "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json -s" + } + } + }, + "01_setupCfnHup": { + "files": { + "/etc/cfn/cfn-hup.conf": { + "content": { + "Fn::Sub": "[main]\nstack=${AWS::StackId}\nregion=${AWS::Region}\ninterval=1\n" + }, + "mode": "000400", + "owner": "root", + "group": "root" + }, + "/etc/cfn/hooks.d/amazon-cloudwatch-agent-auto-reloader.conf": { + "content": { + "Fn::Sub": "[cfn-auto-reloader-hook]\ntriggers=post.update\npath=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init.02_config-amazon-cloudwatch-agent\naction=/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets UpdateEnvironment\nrunas=root\n" + }, + "mode": "000400", + "owner": "root", + "group": "root" + }, + "/lib/systemd/system/cfn-hup.service": { + "content": "[Unit]\nDescription=cfn-hup daemon\n[Service]\nType=simple\nExecStart=/opt/aws/bin/cfn-hup\nRestart=always\n[Install]\nWantedBy=multi-user.target\n" + } + }, + "commands": { + "01enable_cfn_hup": { + "command": "systemctl enable cfn-hup.service" + }, + "02start_cfn_hup": { + "command": "systemctl start cfn-hup.service" + } + } + } + } + }, + "Properties": { + "InstanceType": { + "Ref": "InstanceType" + }, + "IamInstanceProfile": { + "Ref": "IAMRole" + }, + "KeyName": { + "Ref": "KeyName" + }, + "ImageId": { + "Fn::FindInMap": [ + "RegionMap", + { + "Ref": "AWS::Region" + }, + { + "Ref": "RHELVersion" + } + ] + }, + "SubnetId": { + "Ref": "SubnetId" + }, + "SecurityGroupIds": [ + { + + "Fn::GetAtt" : [ "InstanceSecurityGroup", "GroupId" ] + } + ], + "UserData": { + "Fn::Base64": { + "Fn::Sub": "#!/bin/bash\nrpm -Uvh https://s3.amazonaws.com/amazoncloudwatch-agent/redhat/amd64/latest/amazon-cloudwatch-agent.rpm\nyum update -y\nyum install python3 -y\ncurl -O https://bootstrap.pypa.io/get-pip.py\n# Install pip using python3\npython3 get-pip.py\nexport PATH=$PATH:/usr/local/bin\npip3 install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz\ncfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets default\ncfn-signal -e $? --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region}\n" + } + } + } + }, + "InstanceSecurityGroup": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "Enable SSH access via port 22", + "SecurityGroupIngress": [ + { + "IpProtocol": "tcp", + "FromPort": "22", + "ToPort": "22", + "CidrIp": { + "Ref": "SSHLocation" + } + } + ] + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/redhat.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/redhat.yaml new file mode 100644 index 0000000000000000000000000000000000000000..acc0228d069bfde58e6beb4be60d24e96649ec3c --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/redhat.yaml @@ -0,0 +1,192 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: Template to install CloudWatchAgent on redhat. It was validated on redhat 7.5 + +Parameters: + KeyName: + Description: Name of an existing EC2 KeyPair to enable SSH access to the instance + Type: AWS::EC2::KeyPair::KeyName + ConstraintDescription: must be the name of an existing EC2 KeyPair. + + InstanceType: + Description: EC2 instance type + Type: String + Default: t3.medium + ConstraintDescription: must be a valid EC2 instance type. + + RHELVersion: + Type: String + AllowedValues: + - RHEL9 + Default: RHEL9 + Description: RHEL version to deploy + + IAMRole: + Description: EC2 attached IAM role + Type: String + Default: CloudWatchAgentAdminRole + ConstraintDescription: must be an existing IAM role which will be attached to EC2 instance. + + SSHLocation: + Description: The IP address range that can be used to SSH to the EC2 instances + Type: String + Default: 0.0.0.0/0 + MinLength: "9" + MaxLength: "18" + AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2}) + ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x. + + SubnetId: + Type: AWS::EC2::Subnet::Id + +Mappings: + RegionMap: + us-east-1: + RHEL9: ami-0fb13bb53494158e9 + us-east-2: + RHEL9: ami-0aeea2f24f6d3ba32 + us-west-1: + RHEL9: ami-068c2af1200ef7356 + us-west-2: + RHEL9: ami-0367f2b5c3d1ef960 + eu-west-1: + RHEL9: ami-0e28d6c0c65e7f82f + eu-west-2: + RHEL9: ami-02b1e3a99e36afd1a + ap-northeast-1: + RHEL9: ami-0eade93757ef7bb6c + ap-northeast-2: + RHEL9: ami-097698b6cd8164ea2 + ap-southeast-1: + RHEL9: ami-0b9521fddc9871128 + ap-southeast-2: + RHEL9: ami-0eea634029e7b983c + + + +Resources: + EC2Instance: + CreationPolicy: + ResourceSignal: + Count: 1 + Timeout: PT15M + Type: AWS::EC2::Instance + Metadata: + AWS::CloudFormation::Init: + configSets: + default: + - 01_setupCfnHup + - 02_config-amazon-cloudwatch-agent + - 03_restart_amazon-cloudwatch-agent + UpdateEnvironment: + - 02_config-amazon-cloudwatch-agent + - 03_restart_amazon-cloudwatch-agent + + # Definition of json configuration of AmazonCloudWatchAgent, you can change the configuration below. + 02_config-amazon-cloudwatch-agent: + files: + /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json: + content: | + { + "metrics": { + "append_dimensions": { + "AutoScalingGroupName": "${!aws:AutoScalingGroupName}", + "ImageId": "${!aws:ImageId}", + "InstanceId": "${!aws:InstanceId}", + "InstanceType": "${!aws:InstanceType}" + }, + "metrics_collected": { + "mem": { + "measurement": [ + "mem_used_percent" + ] + }, + "swap": { + "measurement": [ + "swap_used_percent" + ] + } + } + } + } + + # Invoke amazon-cloudwatch-agent-ctl to restart the AmazonCloudWatchAgent. + 03_restart_amazon-cloudwatch-agent: + commands: + 01_stop_service: + command: /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop + 02_start_service: + command: /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json -s + + # Cfn-hup setting, it is to monitor the change of metadata. + # When there is change in the contents of json file in the metadata section, cfn-hup will call cfn-init to restart the AmazonCloudWatchAgent. + 01_setupCfnHup: + files: + /etc/cfn/cfn-hup.conf: + content: !Sub | + [main] + stack=${AWS::StackId} + region=${AWS::Region} + interval=1 + mode: "000400" + owner: root + group: root + /etc/cfn/hooks.d/amazon-cloudwatch-agent-auto-reloader.conf: + content: !Sub | + [cfn-auto-reloader-hook] + triggers=post.update + path=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init.02_config-amazon-cloudwatch-agent + action=/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets UpdateEnvironment + runas=root + mode: "000400" + owner: root + group: root + /lib/systemd/system/cfn-hup.service: + content: | + [Unit] + Description=cfn-hup daemon + [Service] + Type=simple + ExecStart=/opt/aws/bin/cfn-hup + Restart=always + [Install] + WantedBy=multi-user.target + commands: + 01enable_cfn_hup: + command: systemctl enable cfn-hup.service + 02start_cfn_hup: + command: systemctl start cfn-hup.service + Properties: + InstanceType: !Ref InstanceType + IamInstanceProfile: !Ref IAMRole + KeyName: !Ref KeyName + ImageId: !FindInMap + - RegionMap + - !Ref 'AWS::Region' + - !Ref RHELVersion + SubnetId: !Ref SubnetId + SecurityGroupIds: + - !GetAtt InstanceSecurityGroup.GroupId + UserData: !Base64 + Fn::Sub: | + #!/bin/bash + rpm -Uvh https://s3.amazonaws.com/amazoncloudwatch-agent/redhat/amd64/latest/amazon-cloudwatch-agent.rpm + yum update -y + yum install python3 -y + curl -O https://bootstrap.pypa.io/get-pip.py + # Install pip using python3 + python3 get-pip.py + export PATH=$PATH:/usr/local/bin + pip3 install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz + cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets default + cfn-signal -e $? --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} + + InstanceSecurityGroup: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Enable SSH access via port 22 + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: "22" + ToPort: "22" + CidrIp: !Ref SSHLocation diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/suse.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/suse.json new file mode 100644 index 0000000000000000000000000000000000000000..ce87177c2e6bf73a5d2cb013d33098157f322006 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/suse.json @@ -0,0 +1,203 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "Template to install CloudWatchAgent on suse. It was validated on suse 12", + "Parameters": { + "KeyName": { + "Description": "Name of an existing EC2 KeyPair to enable SSH access to the instance", + "Type": "AWS::EC2::KeyPair::KeyName", + "ConstraintDescription": "must be the name of an existing EC2 KeyPair." + }, + "InstanceType": { + "Description": "EC2 instance type", + "Type": "String", + "Default": "t3.medium", + "ConstraintDescription": "must be a valid EC2 instance type." + }, + "SUSEVersion": { + "Type": "String", + "AllowedValues": [ + "SLES15SP5" + ], + "Default": "SLES15SP5", + "Description": "SUSE Linux Enterprise Server version to deploy" + }, + "IAMRole": { + "Description": "EC2 attached IAM role", + "Type": "String", + "Default": "CloudWatchAgentAdminRole", + "ConstraintDescription": "must be an existing IAM role which will be attached to EC2 instance." + }, + "SSHLocation": { + "Description": "The IP address range that can be used to SSH to the EC2 instances", + "Type": "String", + "Default": "0.0.0.0/0", + "MinLength": "9", + "MaxLength": "18", + "AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})", + "ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x." + }, + "SubnetId": { + "Type": "AWS::EC2::Subnet::Id" + } + }, + "Mappings": { + "RegionMap": { + "us-east-1": { + "SLES15SP5": "ami-0d62a8e6541a2d491" + }, + "us-east-2": { + "SLES15SP5": "ami-05d1f1c3db2b2eb0c" + }, + "us-west-1": { + "SLES15SP5": "ami-060034d187be82d31" + }, + "us-west-2": { + "SLES15SP5": "ami-066c85d277ae33d38" + }, + "eu-west-1": { + "SLES15SP5": "ami-028867095499bce4b" + }, + "eu-west-2": { + "RHEL9": "ami-03d783398e1e54eb1" + }, + "ap-northeast-1": { + "RHEL9": "ami-05ef8ea5a07946994" + }, + "ap-northeast-2": { + "RHEL9": "ami-0f8bf550807d8d01a" + }, + "ap-southeast-1": { + "RHEL9": "ami-0db03992e79210b9f" + }, + "ap-southeast-2": { + "RHEL9": "ami-084fd76702fabcf2c" + } + } + }, + "Resources": { + "EC2Instance": { + "CreationPolicy": { + "ResourceSignal": { + "Count": 1, + "Timeout": "PT15M" + } + }, + "Type": "AWS::EC2::Instance", + "Metadata": { + "AWS::CloudFormation::Init": { + "configSets": { + "default": [ + "01_setupCfnHup", + "02_config-amazon-cloudwatch-agent", + "03_restart_amazon-cloudwatch-agent" + ], + "UpdateEnvironment": [ + "02_config-amazon-cloudwatch-agent", + "03_restart_amazon-cloudwatch-agent" + ] + }, + "02_config-amazon-cloudwatch-agent": { + "files": { + "/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json": { + "content": "{\n \"metrics\": {\n \"append_dimensions\": {\n \"AutoScalingGroupName\": \"${!aws:AutoScalingGroupName}\",\n \"ImageId\": \"${!aws:ImageId}\",\n \"InstanceId\": \"${!aws:InstanceId}\",\n \"InstanceType\": \"${!aws:InstanceType}\"\n },\n \"metrics_collected\": {\n \"mem\": {\n \"measurement\": [\n \"mem_used_percent\"\n ]\n },\n \"swap\": {\n \"measurement\": [\n \"swap_used_percent\"\n ]\n }\n }\n }\n}\n" + } + } + }, + "03_restart_amazon-cloudwatch-agent": { + "commands": { + "01_stop_service": { + "command": "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop" + }, + "02_start_service": { + "command": "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json -s" + } + } + }, + "01_setupCfnHup": { + "files": { + "/etc/cfn/cfn-hup.conf": { + "content": { + "Fn::Sub": "[main]\nstack=${AWS::StackId}\nregion=${AWS::Region}\ninterval=1\n" + }, + "mode": "000400", + "owner": "root", + "group": "root" + }, + "/etc/cfn/hooks.d/amazon-cloudwatch-agent-auto-reloader.conf": { + "content": { + "Fn::Sub": "[cfn-auto-reloader-hook]\ntriggers=post.update\npath=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init.02_config-amazon-cloudwatch-agent\naction=/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets UpdateEnvironment\nrunas=root\n" + }, + "mode": "000400", + "owner": "root", + "group": "root" + }, + "/lib/systemd/system/cfn-hup.service": { + "content": "[Unit]\nDescription=cfn-hup daemon\n[Service]\nType=simple\nExecStart=/opt/aws/bin/cfn-hup\nRestart=always\n[Install]\nWantedBy=multi-user.target\n" + } + }, + "commands": { + "01enable_cfn_hup": { + "command": "systemctl enable cfn-hup.service" + }, + "02start_cfn_hup": { + "command": "systemctl start cfn-hup.service" + } + } + } + } + }, + "Properties": { + "InstanceType": { + "Ref": "InstanceType" + }, + "IamInstanceProfile": { + "Ref": "IAMRole" + }, + "KeyName": { + "Ref": "KeyName" + }, + "ImageId": { + "Fn::FindInMap": [ + "RegionMap", + { + "Ref": "AWS::Region" + }, + { + "Ref": "SUSEVersion" + } + ] + }, + "SubnetId": { + "Ref": "SubnetId" + }, + "SecurityGroupIds": [ + { + + "Fn::GetAtt" : [ "InstanceSecurityGroup", "GroupId" ] + } + ], + "UserData": { + "Fn::Base64": { + "Fn::Sub": "#!/bin/bash\nrpm -Uvh https://s3.amazonaws.com/amazoncloudwatch-agent/suse/amd64/latest/amazon-cloudwatch-agent.rpm\ncurl -O https://bootstrap.pypa.io/pip/3.6/get-pip.py\n# Install pip using python3\npython3 get-pip.py\nexport PATH=$PATH:/usr/local/bin\npip3 install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz\ncfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets default\ncfn-signal -e $? --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region}\n" + } + } + } + }, + "InstanceSecurityGroup": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "Enable SSH access via port 22", + "SecurityGroupIngress": [ + { + "IpProtocol": "tcp", + "FromPort": "22", + "ToPort": "22", + "CidrIp": { + "Ref": "SSHLocation" + } + } + ] + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/suse.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/suse.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e0ea47d7ffe9bbfd3e75444c10e9fe05c7c40ac5 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/suse.yaml @@ -0,0 +1,189 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: Template to install CloudWatchAgent on suse. It was validated on suse 12 + +Parameters: + KeyName: + Description: Name of an existing EC2 KeyPair to enable SSH access to the instance + Type: AWS::EC2::KeyPair::KeyName + ConstraintDescription: must be the name of an existing EC2 KeyPair. + + InstanceType: + Description: EC2 instance type + Type: String + Default: t3.medium + ConstraintDescription: must be a valid EC2 instance type. + + SUSEVersion: + Type: String + AllowedValues: + - SLES15SP5 + Default: SLES15SP5 + Description: SUSE Linux Enterprise Server version to deploy + + + IAMRole: + Description: EC2 attached IAM role + Type: String + Default: CloudWatchAgentAdminRole + ConstraintDescription: must be an existing IAM role which will be attached to EC2 instance. + + SSHLocation: + Description: The IP address range that can be used to SSH to the EC2 instances + Type: String + Default: 0.0.0.0/0 + MinLength: "9" + MaxLength: "18" + AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2}) + ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x. + + SubnetId: + Type: AWS::EC2::Subnet::Id + +Mappings: + RegionMap: + us-east-1: + SLES15SP5: ami-0d62a8e6541a2d491 + us-east-2: + SLES15SP5: ami-05d1f1c3db2b2eb0c + us-west-1: + SLES15SP5: ami-060034d187be82d31 + us-west-2: + SLES15SP5: ami-066c85d277ae33d38 + eu-west-1: + SLES15SP5: ami-028867095499bce4b + eu-west-2: + SLES15SP5: ami-03d783398e1e54eb1 + ap-northeast-1: + SLES15SP5: ami-05ef8ea5a07946994 + ap-northeast-2: + SLES15SP5: ami-0f8bf550807d8d01a + ap-southeast-1: + SLES15SP5: ami-0db03992e79210b9f + ap-southeast-2: + SLES15SP5: ami-084fd76702fabcf2c + +Resources: + EC2Instance: + CreationPolicy: + ResourceSignal: + Count: 1 + Timeout: PT15M + Type: AWS::EC2::Instance + Metadata: + AWS::CloudFormation::Init: + configSets: + default: + - 01_setupCfnHup + - 02_config-amazon-cloudwatch-agent + - 03_restart_amazon-cloudwatch-agent + UpdateEnvironment: + - 02_config-amazon-cloudwatch-agent + - 03_restart_amazon-cloudwatch-agent + + # Definition of json configuration of AmazonCloudWatchAgent, you can change the configuration below. + 02_config-amazon-cloudwatch-agent: + files: + /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json: + content: | + { + "metrics": { + "append_dimensions": { + "AutoScalingGroupName": "${!aws:AutoScalingGroupName}", + "ImageId": "${!aws:ImageId}", + "InstanceId": "${!aws:InstanceId}", + "InstanceType": "${!aws:InstanceType}" + }, + "metrics_collected": { + "mem": { + "measurement": [ + "mem_used_percent" + ] + }, + "swap": { + "measurement": [ + "swap_used_percent" + ] + } + } + } + } + + # Invoke amazon-cloudwatch-agent-ctl to restart the AmazonCloudWatchAgent. + 03_restart_amazon-cloudwatch-agent: + commands: + 01_stop_service: + command: /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop + 02_start_service: + command: /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json -s + + # Cfn-hup setting, it is to monitor the change of metadata. + # When there is change in the contents of json file in the metadata section, cfn-hup will call cfn-init to restart the AmazonCloudWatchAgent. + 01_setupCfnHup: + files: + /etc/cfn/cfn-hup.conf: + content: !Sub | + [main] + stack=${AWS::StackId} + region=${AWS::Region} + interval=1 + mode: "000400" + owner: root + group: root + /etc/cfn/hooks.d/amazon-cloudwatch-agent-auto-reloader.conf: + content: !Sub | + [cfn-auto-reloader-hook] + triggers=post.update + path=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init.02_config-amazon-cloudwatch-agent + action=/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets UpdateEnvironment + runas=root + mode: "000400" + owner: root + group: root + /lib/systemd/system/cfn-hup.service: + content: | + [Unit] + Description=cfn-hup daemon + [Service] + Type=simple + ExecStart=/opt/aws/bin/cfn-hup + Restart=always + [Install] + WantedBy=multi-user.target + commands: + 01enable_cfn_hup: + command: systemctl enable cfn-hup.service + 02start_cfn_hup: + command: systemctl start cfn-hup.service + Properties: + InstanceType: !Ref InstanceType + IamInstanceProfile: !Ref IAMRole + KeyName: !Ref KeyName + ImageId: !FindInMap + - RegionMap + - !Ref 'AWS::Region' + - !Ref SUSEVersion + SubnetId: !Ref SubnetId + SecurityGroupIds: + - !GetAtt InstanceSecurityGroup.GroupId + UserData: !Base64 + Fn::Sub: | + #!/bin/bash + rpm -Uvh https://s3.amazonaws.com/amazoncloudwatch-agent/suse/amd64/latest/amazon-cloudwatch-agent.rpm + curl -O https://bootstrap.pypa.io/pip/3.6/get-pip.py + # Install pip using python3 + python3 get-pip.py + export PATH=$PATH:/usr/local/bin + pip3 install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz + cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets default + cfn-signal -e $? --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} + + InstanceSecurityGroup: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Enable SSH access via port 22 + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: "22" + ToPort: "22" + CidrIp: !Ref SSHLocation diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/ubuntu.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/ubuntu.json new file mode 100644 index 0000000000000000000000000000000000000000..1934c3a3164af9290c1095b82c818e859d8a5dfd --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/ubuntu.json @@ -0,0 +1,158 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "Template to install CloudWatchAgent on ubuntu. It was validated on ubuntu 22.04", + "Parameters": { + "KeyName": { + "Description": "Name of an existing EC2 KeyPair to enable SSH access to the instance", + "Type": "AWS::EC2::KeyPair::KeyName", + "ConstraintDescription": "must be the name of an existing EC2 KeyPair." + }, + "InstanceType": { + "Description": "EC2 instance type", + "Type": "String", + "Default": "t3.medium", + "ConstraintDescription": "must be a valid EC2 instance type." + }, + "InstanceAMI": { + "Description": "Managed AMI ID for EC2 Instance", + "Type": "AWS::SSM::Parameter::Value", + "Default": "/aws/service/canonical/ubuntu/eks-pro/22.04/1.29/stable/current/amd64/hvm/ebs-gp2/ami-id" + }, + "IAMRole": { + "Description": "EC2 attached IAM role", + "Type": "String", + "Default": "CloudWatchAgentAdminRole", + "ConstraintDescription": "must be an existing IAM role which will be attached to EC2 instance." + }, + "SSHLocation": { + "Description": "The IP address range that can be used to SSH to the EC2 instances", + "Type": "String", + "Default": "0.0.0.0/0", + "MinLength": "9", + "MaxLength": "18", + "AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})", + "ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x." + }, + "SubnetId": { + "Type": "AWS::EC2::Subnet::Id" + } + }, + "Resources": { + "EC2Instance": { + "CreationPolicy": { + "ResourceSignal": { + "Count": 1, + "Timeout": "PT15M" + } + }, + "Type": "AWS::EC2::Instance", + "Metadata": { + "AWS::CloudFormation::Init": { + "configSets": { + "default": [ + "01_setupCfnHup", + "02_config-amazon-cloudwatch-agent", + "03_restart_amazon-cloudwatch-agent" + ], + "UpdateEnvironment": [ + "02_config-amazon-cloudwatch-agent", + "03_restart_amazon-cloudwatch-agent" + ] + }, + "02_config-amazon-cloudwatch-agent": { + "files": { + "/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json": { + "content": "{\n \"metrics\": {\n \"append_dimensions\": {\n \"AutoScalingGroupName\": \"${!aws:AutoScalingGroupName}\",\n \"ImageId\": \"${!aws:ImageId}\",\n \"InstanceId\": \"${!aws:InstanceId}\",\n \"InstanceType\": \"${!aws:InstanceType}\"\n },\n \"metrics_collected\": {\n \"mem\": {\n \"measurement\": [\n \"mem_used_percent\"\n ]\n },\n \"swap\": {\n \"measurement\": [\n \"swap_used_percent\"\n ]\n }\n }\n }\n}\n" + } + } + }, + "03_restart_amazon-cloudwatch-agent": { + "commands": { + "01_stop_service": { + "command": "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop" + }, + "02_start_service": { + "command": "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json -s" + } + } + }, + "01_setupCfnHup": { + "files": { + "/etc/cfn/cfn-hup.conf": { + "content": { + "Fn::Sub": "[main]\nstack=${AWS::StackId}\nregion=${AWS::Region}\ninterval=1\n" + }, + "mode": "000400", + "owner": "root", + "group": "root" + }, + "/etc/cfn/hooks.d/amazon-cloudwatch-agent-auto-reloader.conf": { + "content": { + "Fn::Sub": "[cfn-auto-reloader-hook]\ntriggers=post.update\npath=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init.02_config-amazon-cloudwatch-agent\naction=/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets UpdateEnvironment\nrunas=root\n" + }, + "mode": "000400", + "owner": "root", + "group": "root" + }, + "/lib/systemd/system/cfn-hup.service": { + "content": "[Unit]\nDescription=cfn-hup daemon\n[Service]\nType=simple\nExecStart=/opt/aws/bin/cfn-hup\nRestart=always\n[Install]\nWantedBy=multi-user.target\n" + } + }, + "commands": { + "01enable_cfn_hup": { + "command": "systemctl enable cfn-hup.service" + }, + "02start_cfn_hup": { + "command": "systemctl start cfn-hup.service" + } + } + } + } + }, + "Properties": { + "InstanceType": { + "Ref": "InstanceType" + }, + "IamInstanceProfile": { + "Ref": "IAMRole" + }, + "KeyName": { + "Ref": "KeyName" + }, + "ImageId": { + "Ref": "InstanceAMI" + }, + "SubnetId": { + "Ref": "SubnetId" + }, + "SecurityGroupIds": [ + { + + "Fn::GetAtt" : [ "InstanceSecurityGroup", "GroupId" ] + } + ], + "UserData": { + "Fn::Base64": { + "Fn::Sub": "#!/bin/bash\nwget https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb -O /tmp/amazon-cloudwatch-agent.deb\ndpkg -i /tmp/amazon-cloudwatch-agent.deb\napt-get update -y\napt-get install -y python3 python3-pip\npip3 install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz\ncfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets default\ncfn-signal -e $? --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region}\n" + } + } + } + }, + "InstanceSecurityGroup": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "Enable SSH access via port 22", + "SecurityGroupIngress": [ + { + "IpProtocol": "tcp", + "FromPort": "22", + "ToPort": "22", + "CidrIp": { + "Ref": "SSHLocation" + } + } + ] + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/ubuntu.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/ubuntu.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e486eb8edc596dcd7bac8d641e4a97ae808bdcf8 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/ubuntu.yaml @@ -0,0 +1,159 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: Template to install CloudWatchAgent on ubuntu. It was validated on ubuntu 22.04 + +Parameters: + KeyName: + Description: Name of an existing EC2 KeyPair to enable SSH access to the instance + Type: AWS::EC2::KeyPair::KeyName + ConstraintDescription: must be the name of an existing EC2 KeyPair. + + InstanceType: + Description: EC2 instance type + Type: String + Default: t3.medium + ConstraintDescription: must be a valid EC2 instance type. + + InstanceAMI: + Description: Managed AMI ID for EC2 Instance + Type: AWS::SSM::Parameter::Value + Default: /aws/service/canonical/ubuntu/eks-pro/22.04/1.29/stable/current/amd64/hvm/ebs-gp2/ami-id + + IAMRole: + Description: EC2 attached IAM role + Type: String + Default: CloudWatchAgentAdminRole + ConstraintDescription: must be an existing IAM role which will be attached to EC2 instance. + + SSHLocation: + Description: The IP address range that can be used to SSH to the EC2 instances + Type: String + Default: 0.0.0.0/0 + MinLength: "9" + MaxLength: "18" + AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2}) + ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x. + + SubnetId: + Type: AWS::EC2::Subnet::Id + +Resources: + EC2Instance: + CreationPolicy: + ResourceSignal: + Count: 1 + Timeout: PT15M + Type: AWS::EC2::Instance + Metadata: + AWS::CloudFormation::Init: + configSets: + default: + - 01_setupCfnHup + - 02_config-amazon-cloudwatch-agent + - 03_restart_amazon-cloudwatch-agent + UpdateEnvironment: + - 02_config-amazon-cloudwatch-agent + - 03_restart_amazon-cloudwatch-agent + + # Definition of json configuration of AmazonCloudWatchAgent, you can change the configuration below. + 02_config-amazon-cloudwatch-agent: + files: + /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json: + content: | + { + "metrics": { + "append_dimensions": { + "AutoScalingGroupName": "${!aws:AutoScalingGroupName}", + "ImageId": "${!aws:ImageId}", + "InstanceId": "${!aws:InstanceId}", + "InstanceType": "${!aws:InstanceType}" + }, + "metrics_collected": { + "mem": { + "measurement": [ + "mem_used_percent" + ] + }, + "swap": { + "measurement": [ + "swap_used_percent" + ] + } + } + } + } + + # Invoke amazon-cloudwatch-agent-ctl to restart the AmazonCloudWatchAgent. + 03_restart_amazon-cloudwatch-agent: + commands: + 01_stop_service: + command: /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop + 02_start_service: + command: /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json -s + + # Cfn-hup setting, it is to monitor the change of metadata. + # When there is change in the contents of json file in the metadata section, cfn-hup will call cfn-init to restart the AmazonCloudWatchAgent. + 01_setupCfnHup: + files: + /etc/cfn/cfn-hup.conf: + content: !Sub | + [main] + stack=${AWS::StackId} + region=${AWS::Region} + interval=1 + mode: "000400" + owner: root + group: root + /etc/cfn/hooks.d/amazon-cloudwatch-agent-auto-reloader.conf: + content: !Sub | + [cfn-auto-reloader-hook] + triggers=post.update + path=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init.02_config-amazon-cloudwatch-agent + action=/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets UpdateEnvironment + runas=root + mode: "000400" + owner: root + group: root + /lib/systemd/system/cfn-hup.service: + content: | + [Unit] + Description=cfn-hup daemon + [Service] + Type=simple + ExecStart=/opt/aws/bin/cfn-hup + Restart=always + [Install] + WantedBy=multi-user.target + commands: + 01enable_cfn_hup: + command: systemctl enable cfn-hup.service + 02start_cfn_hup: + command: systemctl start cfn-hup.service + Properties: + InstanceType: !Ref InstanceType + IamInstanceProfile: !Ref IAMRole + KeyName: !Ref KeyName + ImageId: !Ref InstanceAMI + SubnetId: !Ref SubnetId + SecurityGroupIds: + - !GetAtt InstanceSecurityGroup.GroupId + UserData: !Base64 + Fn::Sub: | + #!/bin/bash + wget https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb -O /tmp/amazon-cloudwatch-agent.deb + dpkg -i /tmp/amazon-cloudwatch-agent.deb + apt-get update -y + apt-get install -y python3 python3-pip + pip3 install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz + cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets default + cfn-signal -e $? --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} + + InstanceSecurityGroup: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Enable SSH access via port 22 + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: "22" + ToPort: "22" + CidrIp: !Ref SSHLocation diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/windows.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/windows.json new file mode 100644 index 0000000000000000000000000000000000000000..7c351285bedbeacb8a3106d1cb5d007203da1dce --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/windows.json @@ -0,0 +1,125 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "Template to install CloudWatchAgent on windows. It was validated on windows 2016", + "Parameters": { + "KeyName": { + "Description": "Name of an existing EC2 KeyPair to enable SSH access to the instance", + "Type": "AWS::EC2::KeyPair::KeyName", + "ConstraintDescription": "must be the name of an existing EC2 KeyPair." + }, + "InstanceType": { + "Description": "EC2 instance type", + "Type": "String", + "Default": "t3.medium", + "ConstraintDescription": "must be a valid EC2 instance type." + }, + "InstanceAMI": { + "Description": "Managed AMI ID for EC2 Instance", + "Type": "AWS::SSM::Parameter::Value", + "Default": "/aws/service/ami-windows-latest/Windows_Server-2022-English-Full-SQL_2022_Web" + }, + "IAMRole": { + "Description": "EC2 attached IAM role", + "Type": "String", + "Default": "CloudWatchAgentAdminRole", + "ConstraintDescription": "must be an existing IAM role which will be attached to EC2 instance." + }, + "SubnetId": { + "Type": "AWS::EC2::Subnet::Id" + } + }, + "Resources": { + "EC2Instance": { + "CreationPolicy": { + "ResourceSignal": { + "Count": 1, + "Timeout": "PT15M" + } + }, + "Type": "AWS::EC2::Instance", + "Metadata": { + "AWS::CloudFormation::Init": { + "configSets": { + "default": [ + "00_setupCfnHup", + "01_CfnHup_service", + "02_config-amazon-cloudwatch-agent", + "03_restart_amazon-cloudwatch-agent" + ], + "UpdateEnvironment": [ + "02_config-amazon-cloudwatch-agent", + "03_restart_amazon-cloudwatch-agent" + ] + }, + "00_setupCfnHup": { + "files": { + "c:\\cfn\\cfn-hup.conf": { + "content": { + "Fn::Sub": "[main]\nstack=${AWS::StackId}\nregion=${AWS::Region}\ninterval=1\n" + } + }, + "c:\\cfn\\hooks.d\\amazon-cloudwatch-agent-auto-reloader.conf": { + "content": { + "Fn::Sub": "[cfn-auto-reloader-hook]\ntriggers=post.update\npath=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init.02_config-amazon-cloudwatch-agent\naction=cfn-init.exe -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets UpdateEnvironment\n" + } + } + } + }, + "01_CfnHup_service": { + "services": { + "windows": { + "cfn-hup": { + "enabled": "true", + "ensureRunning": "true", + "files": [ + "c:\\cfn\\cfn-hup.conf", + "c:\\cfn\\hooks.d\\cfn-auto-reloader.conf" + ] + } + } + } + }, + "02_config-amazon-cloudwatch-agent": { + "files": { + "C:\\ProgramData\\Amazon\\AmazonCloudWatchAgent\\amazon-cloudwatch-agent.json": { + "content": "{\n \"metrics\": {\n \"append_dimensions\": {\n \"AutoScalingGroupName\": \"${!aws:AutoScalingGroupName}\",\n \"ImageId\": \"${!aws:ImageId}\",\n \"InstanceId\": \"${!aws:InstanceId}\",\n \"InstanceType\": \"${!aws:InstanceType}\"\n },\n \"metrics_collected\": {\n \"Memory\": {\n \"measurement\": [\n \"% Committed Bytes In Use\"\n ],\n \"metrics_collection_interval\": 60\n },\n \"Paging File\": {\n \"measurement\": [\n \"% Usage\"\n ],\n \"metrics_collection_interval\": 60,\n \"resources\": [\n \"*\"\n ]\n }\n }\n }\n}\n" + } + } + }, + "03_restart_amazon-cloudwatch-agent": { + "commands": { + "01_stop_service": { + "command": "powershell -Command \"C:\\\\'Program Files'\\\\Amazon\\\\AmazonCloudWatchAgent\\\\amazon-cloudwatch-agent-ctl.ps1 -a stop\"" + }, + "02_start_service": { + "command": "powershell -Command \"C:\\\\'Program Files'\\\\Amazon\\\\AmazonCloudWatchAgent\\\\amazon-cloudwatch-agent-ctl.ps1 -a fetch-config -m ec2 -c file:C:\\\\ProgramData\\\\Amazon\\\\AmazonCloudWatchAgent\\\\amazon-cloudwatch-agent.json -s\"" + } + } + } + } + }, + "Properties": { + "InstanceType": { + "Ref": "InstanceType" + }, + "IamInstanceProfile": { + "Ref": "IAMRole" + }, + "KeyName": { + "Ref": "KeyName" + }, + "ImageId": { + "Ref": "InstanceAMI" + }, + "SubnetId": { + "Ref": "SubnetId" + }, + "UserData": { + "Fn::Base64": { + "Fn::Sub": "" + } + } + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/windows.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/windows.yaml new file mode 100644 index 0000000000000000000000000000000000000000..0154bf718619cd6a765c1023e3e34e2f6c0651c4 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/inline/windows.yaml @@ -0,0 +1,130 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: Template to install CloudWatchAgent on windows. It was validated on windows 2016 + +Parameters: + KeyName: + Description: Name of an existing EC2 KeyPair to enable SSH access to the instance + Type: AWS::EC2::KeyPair::KeyName + ConstraintDescription: must be the name of an existing EC2 KeyPair. + + InstanceType: + Description: EC2 instance type + Type: String + Default: t3.medium + ConstraintDescription: must be a valid EC2 instance type. + + InstanceAMI: + Description: Managed AMI ID for EC2 Instance + Type: AWS::SSM::Parameter::Value + Default: /aws/service/ami-windows-latest/Windows_Server-2022-English-Full-SQL_2022_Web + + IAMRole: + Description: EC2 attached IAM role + Type: String + Default: CloudWatchAgentAdminRole + ConstraintDescription: must be an existing IAM role which will be attached to EC2 instance. + + SubnetId: + Type: AWS::EC2::Subnet::Id + +Resources: + EC2Instance: + CreationPolicy: + ResourceSignal: + Count: 1 + Timeout: PT15M + Type: AWS::EC2::Instance + Metadata: + AWS::CloudFormation::Init: + configSets: + default: + - 00_setupCfnHup + - 01_CfnHup_service + - 02_config-amazon-cloudwatch-agent + - 03_restart_amazon-cloudwatch-agent + UpdateEnvironment: + - 02_config-amazon-cloudwatch-agent + - 03_restart_amazon-cloudwatch-agent + + # Cfn-hup setting, it is to monitor the change of metadata. + # When there is change in the contents of json file in the metadata section, cfn-hup will call cfn-init to restart the AmazonCloudWatchAgent. + 00_setupCfnHup: + files: + c:\cfn\cfn-hup.conf: + content: !Sub | + [main] + stack=${AWS::StackId} + region=${AWS::Region} + interval=1 + c:\cfn\hooks.d\amazon-cloudwatch-agent-auto-reloader.conf: + content: !Sub | + [cfn-auto-reloader-hook] + triggers=post.update + path=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init.02_config-amazon-cloudwatch-agent + action=cfn-init.exe -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets UpdateEnvironment + 01_CfnHup_service: + services: + windows: + cfn-hup: + enabled: "true" + ensureRunning: "true" + files: + - c:\cfn\cfn-hup.conf + - c:\cfn\hooks.d\cfn-auto-reloader.conf + + # Definition of json configuration of AmazonCloudWatchAgent, you can change the configuration below. + 02_config-amazon-cloudwatch-agent: + files: + C:\ProgramData\Amazon\AmazonCloudWatchAgent\amazon-cloudwatch-agent.json: + content: | + { + "metrics": { + "append_dimensions": { + "AutoScalingGroupName": "${!aws:AutoScalingGroupName}", + "ImageId": "${!aws:ImageId}", + "InstanceId": "${!aws:InstanceId}", + "InstanceType": "${!aws:InstanceType}" + }, + "metrics_collected": { + "Memory": { + "measurement": [ + "% Committed Bytes In Use" + ], + "metrics_collection_interval": 60 + }, + "Paging File": { + "measurement": [ + "% Usage" + ], + "metrics_collection_interval": 60, + "resources": [ + "*" + ] + } + } + } + } + + # Invoke amazon-cloudwatch-agent-ctl to restart the AmazonCloudWatchAgent. + 03_restart_amazon-cloudwatch-agent: + commands: + 01_stop_service: + command: powershell -Command "C:\\'Program Files'\\Amazon\\AmazonCloudWatchAgent\\amazon-cloudwatch-agent-ctl.ps1 -a stop" + 02_start_service: + command: powershell -Command "C:\\'Program Files'\\Amazon\\AmazonCloudWatchAgent\\amazon-cloudwatch-agent-ctl.ps1 -a fetch-config -m ec2 -c file:C:\\ProgramData\\Amazon\\AmazonCloudWatchAgent\\amazon-cloudwatch-agent.json -s" + Properties: + InstanceType: !Ref InstanceType + IamInstanceProfile: !Ref IAMRole + KeyName: !Ref KeyName + ImageId: !Ref InstanceAMI + SubnetId: !Ref SubnetId + UserData: !Base64 + Fn::Sub: |- + diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/amazon_linux.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/amazon_linux.json new file mode 100644 index 0000000000000000000000000000000000000000..249ff44ad8699cc5d9dc08c3514ca3bd3c73140c --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/amazon_linux.json @@ -0,0 +1,180 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "Template to install CloudWatchAgent on amazon linux. It was validated on amazon linux 2", + "Parameters": { + "SSMKey": { + "Description": "Name of parameter store which contains the json configuration of CWAgent.", + "Type": "String", + "Default": "AmazonCloudWatch-DefaultLinuxConfigCloudFormation" + }, + "KeyName": { + "Description": "Name of an existing EC2 KeyPair to enable SSH access to the instance", + "Type": "AWS::EC2::KeyPair::KeyName", + "ConstraintDescription": "must be the name of an existing EC2 KeyPair." + }, + "InstanceType": { + "Description": "EC2 instance type", + "Type": "String", + "Default": "t3.medium", + "ConstraintDescription": "must be a valid EC2 instance type." + }, + "InstanceAMI": { + "Description": "Managed AMI ID for EC2 Instance", + "Type": "AWS::SSM::Parameter::Value", + "Default": "/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64" + }, + "IAMRole": { + "Description": "EC2 attached IAM role", + "Type": "String", + "Default": "CloudWatchAgentAdminRole", + "ConstraintDescription": "must be an existing IAM role which will be attached to EC2 instance." + }, + "SSHLocation": { + "Description": "The IP address range that can be used to SSH to the EC2 instances", + "Type": "String", + "Default": "0.0.0.0/0", + "MinLength": "9", + "MaxLength": "18", + "AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})", + "ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x." + }, + "SubnetId": { + "Type": "AWS::EC2::Subnet::Id" + } + }, + "Resources": { + "EC2Instance": { + "CreationPolicy": { + "ResourceSignal": { + "Count": 1, + "Timeout": "PT15M" + } + }, + "Type": "AWS::EC2::Instance", + "Metadata": { + "AWS::CloudFormation::Init": { + "configSets": { + "default": [ + "01_setupCfnHup", + "02_config-amazon-cloudwatch-agent", + "03_restart_amazon-cloudwatch-agent" + ], + "UpdateEnvironment": [ + "02_config-amazon-cloudwatch-agent", + "03_restart_amazon-cloudwatch-agent" + ] + }, + "02_config-amazon-cloudwatch-agent": { + "files": { + "/opt/aws/amazon-cloudwatch-agent/etc/dummy.version": { + "content": "\"You can change the VERSION below to to simulate the update of metadata\"\n\"VERSION=1.0\"\n" + } + } + }, + "03_restart_amazon-cloudwatch-agent": { + "commands": { + "01_stop_service": { + "command": "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop" + }, + "02_start_service": { + "command": { + "Fn::Sub": [ + "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:${ssmkey} -s\n", + { + "ssmkey": { + "Ref": "SSMKey" + } + } + ] + } + } + } + }, + "01_setupCfnHup": { + "files": { + "/etc/cfn/cfn-hup.conf": { + "content": { + "Fn::Sub": "[main]\nstack=${AWS::StackId}\nregion=${AWS::Region}\ninterval=1\n" + }, + "mode": "000400", + "owner": "root", + "group": "root" + }, + "/etc/cfn/hooks.d/amazon-cloudwatch-agent-auto-reloader.conf": { + "content": { + "Fn::Sub": "[cfn-auto-reloader-hook]\ntriggers=post.update\npath=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init.02_config-amazon-cloudwatch-agent\naction=/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets UpdateEnvironment\nrunas=root\n" + }, + "mode": "000400", + "owner": "root", + "group": "root" + }, + "/lib/systemd/system/cfn-hup.service": { + "content": "[Unit]\nDescription=cfn-hup daemon\n[Service]\nType=simple\nExecStart=/opt/aws/bin/cfn-hup\nRestart=always\n[Install]\nWantedBy=multi-user.target\n" + } + }, + "commands": { + "01enable_cfn_hup": { + "command": "systemctl enable cfn-hup.service" + }, + "02start_cfn_hup": { + "command": "systemctl start cfn-hup.service" + } + } + } + } + }, + "Properties": { + "InstanceType": { + "Ref": "InstanceType" + }, + "IamInstanceProfile": { + "Ref": "IAMRole" + }, + "KeyName": { + "Ref": "KeyName" + }, + "ImageId": { + "Ref": "InstanceAMI" + }, + "SubnetId": { + "Ref": "SubnetId" + }, + "SecurityGroupIds": [ + { + + "Fn::GetAtt" : [ "InstanceSecurityGroup", "GroupId" ] + } + + ], + "UserData": { + "Fn::Base64": { + "Fn::Sub": [ + "#!/bin/bash\nrpm -Uvh https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm\n/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:${ssmkey} -s\n/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets default\n/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region}\n", + { + "ssmkey": { + "Ref": "SSMKey" + } + } + ] + } + } + } + }, + "InstanceSecurityGroup": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "Enable SSH access via port 22", + "SecurityGroupIngress": [ + { + "IpProtocol": "tcp", + "FromPort": "22", + "ToPort": "22", + "CidrIp": { + "Ref": "SSHLocation" + } + } + ] + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/amazon_linux.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/amazon_linux.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ea60f5f08fc275b77884be0bfc225573de0a8982 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/amazon_linux.yaml @@ -0,0 +1,146 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: Template to install CloudWatchAgent on amazon linux. It was validated on amazon linux 2 + +Parameters: + SSMKey: + Description: Name of parameter store which contains the json configuration of CWAgent. + Type: String + Default: AmazonCloudWatch-DefaultLinuxConfigCloudFormation + + KeyName: + Description: Name of an existing EC2 KeyPair to enable SSH access to the instance + Type: AWS::EC2::KeyPair::KeyName + ConstraintDescription: must be the name of an existing EC2 KeyPair. + + InstanceType: + Description: EC2 instance type + Type: String + Default: t3.medium + ConstraintDescription: must be a valid EC2 instance type. + + InstanceAMI: + Description: Managed AMI ID for EC2 Instance + Type: AWS::SSM::Parameter::Value + Default: /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64 + + IAMRole: + Description: EC2 attached IAM role + Type: String + Default: CloudWatchAgentAdminRole + ConstraintDescription: must be an existing IAM role which will be attached to EC2 instance. + + SSHLocation: + Description: The IP address range that can be used to SSH to the EC2 instances + Type: String + Default: 0.0.0.0/0 + MinLength: "9" + MaxLength: "18" + AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2}) + ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x. + + SubnetId: + Type: AWS::EC2::Subnet::Id + +Resources: + EC2Instance: + CreationPolicy: + ResourceSignal: + Count: 1 + Timeout: PT15M + Type: AWS::EC2::Instance + Metadata: + AWS::CloudFormation::Init: + configSets: + default: + - 01_setupCfnHup + - 02_config-amazon-cloudwatch-agent + - 03_restart_amazon-cloudwatch-agent + UpdateEnvironment: + - 02_config-amazon-cloudwatch-agent + - 03_restart_amazon-cloudwatch-agent + + # Definition of a dummy file, that change the contents of the dummy file can trigger the agent to reload the configuration from SSM parameter store. + 02_config-amazon-cloudwatch-agent: + files: + /opt/aws/amazon-cloudwatch-agent/etc/dummy.version: + content: | + "You can change the VERSION below to to simulate the update of metadata" + "VERSION=1.0" + + # Invoke amazon-cloudwatch-agent-ctl to restart the AmazonCloudWatchAgent. + 03_restart_amazon-cloudwatch-agent: + commands: + 01_stop_service: + command: /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop + 02_start_service: + command: !Sub + - | + /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:${ssmkey} -s + - ssmkey: !Ref SSMKey + + # Cfn-hup setting, it is to monitor the change of metadata. + # When there is change in the contents of json file in the metadata section, cfn-hup will call cfn-init to restart the AmazonCloudWatchAgent. + 01_setupCfnHup: + files: + /etc/cfn/cfn-hup.conf: + content: !Sub | + [main] + stack=${AWS::StackId} + region=${AWS::Region} + interval=1 + mode: "000400" + owner: root + group: root + /etc/cfn/hooks.d/amazon-cloudwatch-agent-auto-reloader.conf: + content: !Sub | + [cfn-auto-reloader-hook] + triggers=post.update + path=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init.02_config-amazon-cloudwatch-agent + action=/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets UpdateEnvironment + runas=root + mode: "000400" + owner: root + group: root + /lib/systemd/system/cfn-hup.service: + content: | + [Unit] + Description=cfn-hup daemon + [Service] + Type=simple + ExecStart=/opt/aws/bin/cfn-hup + Restart=always + [Install] + WantedBy=multi-user.target + commands: + 01enable_cfn_hup: + command: systemctl enable cfn-hup.service + 02start_cfn_hup: + command: systemctl start cfn-hup.service + Properties: + InstanceType: !Ref InstanceType + IamInstanceProfile: !Ref IAMRole + KeyName: !Ref KeyName + ImageId: !Ref InstanceAMI + SubnetId: !Ref SubnetId + SecurityGroupIds: + - !GetAtt InstanceSecurityGroup.GroupId + UserData: !Base64 + Fn::Sub: + - | + #!/bin/bash + rpm -Uvh https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm + /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:${ssmkey} -s + /opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets default + /opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} + - ssmkey: !Ref SSMKey + + InstanceSecurityGroup: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Enable SSH access via port 22 + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: "22" + ToPort: "22" + CidrIp: !Ref SSHLocation diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/centos.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/centos.json new file mode 100644 index 0000000000000000000000000000000000000000..b5dafb0a99c3fcb41dc5136653b7f1ae8d79c1e4 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/centos.json @@ -0,0 +1,224 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "Template to install CloudWatchAgent on centos. It was validated on centos 7", + "Parameters": { + "SSMKey": { + "Description": "Name of parameter store which contains the json configuration of CWAgent.", + "Type": "String", + "Default": "AmazonCloudWatch-DefaultLinuxConfigCloudFormation" + }, + "KeyName": { + "Description": "Name of an existing EC2 KeyPair to enable SSH access to the instance", + "Type": "AWS::EC2::KeyPair::KeyName", + "ConstraintDescription": "must be the name of an existing EC2 KeyPair." + }, + "InstanceType": { + "Description": "EC2 instance type", + "Type": "String", + "Default": "t3.medium", + "ConstraintDescription": "must be a valid EC2 instance type." + }, + "CentOSVersion": { + "Type": "String", + "AllowedValues": [ + "CentOS9" + ], + "Default": "CentOS9", + "Description": "CentOS version to deploy" + }, + "IAMRole": { + "Description": "EC2 attached IAM role", + "Type": "String", + "Default": "CloudWatchAgentAdminRole", + "ConstraintDescription": "must be an existing IAM role which will be attached to EC2 instance." + }, + "SSHLocation": { + "Description": "The IP address range that can be used to SSH to the EC2 instances", + "Type": "String", + "Default": "0.0.0.0/0", + "MinLength": "9", + "MaxLength": "18", + "AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})", + "ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x." + }, + "SubnetId": { + "Type": "AWS::EC2::Subnet::Id" + } + }, + "Mappings": { + "RegionMap": { + "us-east-1": { + "CentOS9": "ami-0705f7887207411ca" + }, + "us-east-2": { + "CentOS9": "ami-0fe2c46c1dc3889fa" + }, + "us-west-1": { + "CentOS9": "ami-0f4f63d1732fd4ef5" + }, + "us-west-2": { + "CentOS9": "ami-00b231246df1d28de" + }, + "eu-west-1": { + "CentOS9": "ami-05a7b8270231783b2" + }, + "eu-west-2": { + "RHEL9": "ami-0086646e63ce5aaf1" + }, + "ap-northeast-1": { + "RHEL9": "ami-0d8ee41b4b6f8343b" + }, + "ap-northeast-2": { + "RHEL9": "ami-031e0786d2134adf6" + }, + "ap-southeast-1": { + "RHEL9": "ami-0a9082a6b182a840b" + }, + "ap-southeast-2": { + "RHEL9": "ami-05ffc8a6cb624035b" + } + } + }, + "Resources": { + "EC2Instance": { + "CreationPolicy": { + "ResourceSignal": { + "Count": 1, + "Timeout": "PT15M" + } + }, + "Type": "AWS::EC2::Instance", + "Metadata": { + "AWS::CloudFormation::Init": { + "configSets": { + "default": [ + "01_setupCfnHup", + "02_config-amazon-cloudwatch-agent", + "03_restart_amazon-cloudwatch-agent" + ], + "UpdateEnvironment": [ + "02_config-amazon-cloudwatch-agent", + "03_restart_amazon-cloudwatch-agent" + ] + }, + "02_config-amazon-cloudwatch-agent": { + "files": { + "/opt/aws/amazon-cloudwatch-agent/etc/dummy.version": { + "content": "\"You can change the VERSION below to to simulate the update of metadata\"\n\"VERSION=1.0\"\n" + } + } + }, + "03_restart_amazon-cloudwatch-agent": { + "commands": { + "01_stop_service": { + "command": "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop" + }, + "02_start_service": { + "command": { + "Fn::Sub": [ + "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:${ssmkey} -s\n", + { + "ssmkey": { + "Ref": "SSMKey" + } + } + ] + } + } + } + }, + "01_setupCfnHup": { + "files": { + "/etc/cfn/cfn-hup.conf": { + "content": { + "Fn::Sub": "[main]\nstack=${AWS::StackId}\nregion=${AWS::Region}\ninterval=1\n" + }, + "mode": "000400", + "owner": "root", + "group": "root" + }, + "/etc/cfn/hooks.d/amazon-cloudwatch-agent-auto-reloader.conf": { + "content": { + "Fn::Sub": "[cfn-auto-reloader-hook]\ntriggers=post.update\npath=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init.02_config-amazon-cloudwatch-agent\naction=/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets UpdateEnvironment\nrunas=root\n" + }, + "mode": "000400", + "owner": "root", + "group": "root" + }, + "/lib/systemd/system/cfn-hup.service": { + "content": "[Unit]\nDescription=cfn-hup daemon\n[Service]\nType=simple\nExecStart=/opt/aws/bin/cfn-hup\nRestart=always\n[Install]\nWantedBy=multi-user.target\n" + } + }, + "commands": { + "01enable_cfn_hup": { + "command": "systemctl enable cfn-hup.service" + }, + "02start_cfn_hup": { + "command": "systemctl start cfn-hup.service" + } + } + } + } + }, + "Properties": { + "InstanceType": { + "Ref": "InstanceType" + }, + "IamInstanceProfile": { + "Ref": "IAMRole" + }, + "KeyName": { + "Ref": "KeyName" + }, + "ImageId": { + "Fn::FindInMap": [ + "RegionMap", + { + "Ref": "AWS::Region" + }, + { + "Ref": "CentOSVersion" + } + ] + }, + "SubnetId": { + "Ref": "SubnetId" + }, + "SecurityGroupIds": [ + { + + "Fn::GetAtt" : [ "InstanceSecurityGroup", "GroupId" ] + } + ], + "UserData": { + "Fn::Base64": { + "Fn::Sub": [ + "#!/bin/bash\nrpm -Uvh https://s3.amazonaws.com/amazoncloudwatch-agent/centos/amd64/latest/amazon-cloudwatch-agent.rpm\n/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:${ssmkey} -s\nyum update -y\nyum install python3 -y\ncurl -O https://bootstrap.pypa.io/get-pip.py\n# Install pip using python3\npython3 get-pip.py\nexport PATH=$PATH:/usr/local/bin\npip3 install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz\ncfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets default\ncfn-signal -e $? --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region}\n", + { + "ssmkey": { + "Ref": "SSMKey" + } + } + ] + } + } + } + }, + "InstanceSecurityGroup": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "Enable SSH access via port 22", + "SecurityGroupIngress": [ + { + "IpProtocol": "tcp", + "FromPort": "22", + "ToPort": "22", + "CidrIp": { + "Ref": "SSHLocation" + } + } + ] + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/centos.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/centos.yaml new file mode 100644 index 0000000000000000000000000000000000000000..42872ca5efbf8af1f8d0a9e4505ddccc32e245c7 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/centos.yaml @@ -0,0 +1,181 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: Template to install CloudWatchAgent on centos. It was validated on centos 7 + +Parameters: + SSMKey: + Description: Name of parameter store which contains the json configuration of CWAgent. + Type: String + Default: AmazonCloudWatch-DefaultLinuxConfigCloudFormation + + KeyName: + Description: Name of an existing EC2 KeyPair to enable SSH access to the instance + Type: AWS::EC2::KeyPair::KeyName + ConstraintDescription: must be the name of an existing EC2 KeyPair. + + InstanceType: + Description: EC2 instance type + Type: String + Default: t3.medium + ConstraintDescription: must be a valid EC2 instance type. + + CentOSVersion: + Type: String + AllowedValues: + - CentOS9 + Default: CentOS9 + Description: CentOS version to deploy + + IAMRole: + Description: EC2 attached IAM role + Type: String + Default: CloudWatchAgentAdminRole + ConstraintDescription: must be an existing IAM role which will be attached to EC2 instance. + + SSHLocation: + Description: The IP address range that can be used to SSH to the EC2 instances + Type: String + Default: 0.0.0.0/0 + MinLength: "9" + MaxLength: "18" + AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2}) + ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x. + + SubnetId: + Type: AWS::EC2::Subnet::Id + +Mappings: + RegionMap: + us-east-1: + CentOS9: ami-0705f7887207411ca + us-east-2: + CentOS9: ami-0fe2c46c1dc3889fa + us-west-1: + CentOS9: ami-0f4f63d1732fd4ef5 + us-west-2: + CentOS9: ami-00b231246df1d28de + eu-west-1: + CentOS9: ami-05a7b8270231783b2 + eu-west-2: + CentOS9: ami-0086646e63ce5aaf1 + ap-northeast-1: + CentOS9: ami-0d8ee41b4b6f8343b + ap-northeast-2: + CentOS9: ami-031e0786d2134adf6 + ap-southeast-1: + CentOS9: ami-0a9082a6b182a840b + ap-southeast-2: + CentOS9: ami-05ffc8a6cb624035b + +Resources: + EC2Instance: + CreationPolicy: + ResourceSignal: + Count: 1 + Timeout: PT15M + Type: AWS::EC2::Instance + Metadata: + AWS::CloudFormation::Init: + configSets: + default: + - 01_setupCfnHup + - 02_config-amazon-cloudwatch-agent + - 03_restart_amazon-cloudwatch-agent + UpdateEnvironment: + - 02_config-amazon-cloudwatch-agent + - 03_restart_amazon-cloudwatch-agent + + # Definition of a dummy file, that change the contents of the dummy file can trigger the agent to reload the configuration from SSM parameter store. + 02_config-amazon-cloudwatch-agent: + files: + /opt/aws/amazon-cloudwatch-agent/etc/dummy.version: + content: | + "You can change the VERSION below to to simulate the update of metadata" + "VERSION=1.0" + + # Invoke amazon-cloudwatch-agent-ctl to restart the AmazonCloudWatchAgent. + 03_restart_amazon-cloudwatch-agent: + commands: + 01_stop_service: + command: /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop + 02_start_service: + command: !Sub + - | + /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:${ssmkey} -s + - ssmkey: !Ref SSMKey + + # Cfn-hup setting, it is to monitor the change of metadata. + # When there is change in the contents of json file in the metadata section, cfn-hup will call cfn-init to restart the AmazonCloudWatchAgent. + 01_setupCfnHup: + files: + /etc/cfn/cfn-hup.conf: + content: !Sub | + [main] + stack=${AWS::StackId} + region=${AWS::Region} + interval=1 + mode: "000400" + owner: root + group: root + /etc/cfn/hooks.d/amazon-cloudwatch-agent-auto-reloader.conf: + content: !Sub | + [cfn-auto-reloader-hook] + triggers=post.update + path=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init.02_config-amazon-cloudwatch-agent + action=/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets UpdateEnvironment + runas=root + mode: "000400" + owner: root + group: root + /lib/systemd/system/cfn-hup.service: + content: | + [Unit] + Description=cfn-hup daemon + [Service] + Type=simple + ExecStart=/opt/aws/bin/cfn-hup + Restart=always + [Install] + WantedBy=multi-user.target + commands: + 01enable_cfn_hup: + command: systemctl enable cfn-hup.service + 02start_cfn_hup: + command: systemctl start cfn-hup.service + Properties: + InstanceType: !Ref InstanceType + IamInstanceProfile: !Ref IAMRole + KeyName: !Ref KeyName + ImageId: !FindInMap + - RegionMap + - !Ref 'AWS::Region' + - !Ref CentOSVersion + SubnetId: !Ref SubnetId + SecurityGroupIds: + - !GetAtt InstanceSecurityGroup.GroupId + UserData: !Base64 + Fn::Sub: + - | + #!/bin/bash + rpm -Uvh https://s3.amazonaws.com/amazoncloudwatch-agent/centos/amd64/latest/amazon-cloudwatch-agent.rpm + /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:${ssmkey} -s + yum update -y + yum install python3 -y + curl -O https://bootstrap.pypa.io/get-pip.py + # Install pip using python3 + python3 get-pip.py + export PATH=$PATH:/usr/local/bin + pip3 install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz + cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets default + cfn-signal -e $? --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} + - ssmkey: !Ref SSMKey + + InstanceSecurityGroup: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Enable SSH access via port 22 + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: "22" + ToPort: "22" + CidrIp: !Ref SSHLocation diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/debian.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/debian.json new file mode 100644 index 0000000000000000000000000000000000000000..db764c9270c4d2af7a9c81696cf4c1876118faf2 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/debian.json @@ -0,0 +1,179 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "Template to install CloudWatchAgent on debian. It was validated on debian 12.0", + "Parameters": { + "SSMKey": { + "Description": "Name of parameter store which contains the json configuration of CWAgent.", + "Type": "String", + "Default": "AmazonCloudWatch-DefaultLinuxConfigCloudFormation" + }, + "KeyName": { + "Description": "Name of an existing EC2 KeyPair to enable SSH access to the instance", + "Type": "AWS::EC2::KeyPair::KeyName", + "ConstraintDescription": "must be the name of an existing EC2 KeyPair." + }, + "InstanceType": { + "Description": "EC2 instance type", + "Type": "String", + "Default": "t3.medium", + "ConstraintDescription": "must be a valid EC2 instance type." + }, + "InstanceAMI": { + "Description": "Managed AMI ID for EC2 Instance", + "Type": "AWS::SSM::Parameter::Value", + "Default": "/aws/service/debian/release/10/latest/amd64" + }, + "IAMRole": { + "Description": "EC2 attached IAM role", + "Type": "String", + "Default": "CloudWatchAgentAdminRole", + "ConstraintDescription": "must be an existing IAM role which will be attached to EC2 instance." + }, + "SSHLocation": { + "Description": "The IP address range that can be used to SSH to the EC2 instances", + "Type": "String", + "Default": "0.0.0.0/0", + "MinLength": "9", + "MaxLength": "18", + "AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})", + "ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x." + }, + "SubnetId": { + "Type": "AWS::EC2::Subnet::Id" + } + }, + "Resources": { + "EC2Instance": { + "CreationPolicy": { + "ResourceSignal": { + "Count": 1, + "Timeout": "PT15M" + } + }, + "Type": "AWS::EC2::Instance", + "Metadata": { + "AWS::CloudFormation::Init": { + "configSets": { + "default": [ + "01_setupCfnHup", + "02_config-amazon-cloudwatch-agent", + "03_restart_amazon-cloudwatch-agent" + ], + "UpdateEnvironment": [ + "02_config-amazon-cloudwatch-agent", + "03_restart_amazon-cloudwatch-agent" + ] + }, + "02_config-amazon-cloudwatch-agent": { + "files": { + "/opt/aws/amazon-cloudwatch-agent/etc/dummy.version": { + "content": "\"You can change the VERSION below to to simulate the update of metadata\"\n\"VERSION=1.0\"\n" + } + } + }, + "03_restart_amazon-cloudwatch-agent": { + "commands": { + "01_stop_service": { + "command": "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop" + }, + "02_start_service": { + "command": { + "Fn::Sub": [ + "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:${ssmkey} -s\n", + { + "ssmkey": { + "Ref": "SSMKey" + } + } + ] + } + } + } + }, + "01_setupCfnHup": { + "files": { + "/etc/cfn/cfn-hup.conf": { + "content": { + "Fn::Sub": "[main]\nstack=${AWS::StackId}\nregion=${AWS::Region}\ninterval=1\n" + }, + "mode": "000400", + "owner": "root", + "group": "root" + }, + "/etc/cfn/hooks.d/amazon-cloudwatch-agent-auto-reloader.conf": { + "content": { + "Fn::Sub": "[cfn-auto-reloader-hook]\ntriggers=post.update\npath=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init.02_config-amazon-cloudwatch-agent\naction=/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets UpdateEnvironment\nrunas=root\n" + }, + "mode": "000400", + "owner": "root", + "group": "root" + }, + "/lib/systemd/system/cfn-hup.service": { + "content": "[Unit]\nDescription=cfn-hup daemon\n[Service]\nType=simple\nExecStart=/opt/aws/bin/cfn-hup\nRestart=always\n[Install]\nWantedBy=multi-user.target\n" + } + }, + "commands": { + "01enable_cfn_hup": { + "command": "systemctl enable cfn-hup.service" + }, + "02start_cfn_hup": { + "command": "systemctl start cfn-hup.service" + } + } + } + } + }, + "Properties": { + "InstanceType": { + "Ref": "InstanceType" + }, + "IamInstanceProfile": { + "Ref": "IAMRole" + }, + "KeyName": { + "Ref": "KeyName" + }, + "ImageId": { + "Ref": "InstanceAMI" + }, + "SubnetId": { + "Ref": "SubnetId" + }, + "SecurityGroupIds": [ + { + + "Fn::GetAtt" : [ "InstanceSecurityGroup", "GroupId" ] + } + ], + "UserData": { + "Fn::Base64": { + "Fn::Sub": [ + "#!/bin/bash\nwget https://s3.amazonaws.com/amazoncloudwatch-agent/debian/amd64/latest/amazon-cloudwatch-agent.deb -O /tmp/amazon-cloudwatch-agent.deb\nsudo dpkg -i /tmp/amazon-cloudwatch-agent.deb\n/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:${ssmkey} -s\nwget https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz -O /tmp/aws-cfn-bootstrap-py3-latest.tar.gz\nsudo apt-get update -y\nsudo apt-get install -y python3-pip python3-venv\n\n# Create and activate a virtual environment\npython3 -m venv /opt/aws/virtualenv\nsource /opt/aws/virtualenv/bin/activate\n\n# Install the bootstrap package\npip install /tmp/aws-cfn-bootstrap-py3-latest.tar.gz\n\n# Create necessary symlinks\nsudo mkdir -p /opt/aws/bin\nsudo ln -s /opt/aws/virtualenv/bin/cfn-* /opt/aws/bin/\n\n# Run cfn-init\n/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets default\n/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region}\n", + { + "ssmkey": { + "Ref": "SSMKey" + } + } + ] + } + } + } + }, + "InstanceSecurityGroup": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "Enable SSH access via port 22", + "SecurityGroupIngress": [ + { + "IpProtocol": "tcp", + "FromPort": "22", + "ToPort": "22", + "CidrIp": { + "Ref": "SSHLocation" + } + } + ] + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/debian.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/debian.yaml new file mode 100644 index 0000000000000000000000000000000000000000..a7a5ad4e1eea0ef15f84e9e60da34061fd567615 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/debian.yaml @@ -0,0 +1,163 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: Template to install CloudWatchAgent on debian. It was validated on debian 12.0 + +Parameters: + SSMKey: + Description: Name of parameter store which contains the json configuration of CWAgent. + Type: String + Default: AmazonCloudWatch-DefaultLinuxConfigCloudFormation + + KeyName: + Description: Name of an existing EC2 KeyPair to enable SSH access to the instance + Type: AWS::EC2::KeyPair::KeyName + ConstraintDescription: must be the name of an existing EC2 KeyPair. + + InstanceType: + Description: EC2 instance type + Type: String + Default: t3.medium + ConstraintDescription: must be a valid EC2 instance type. + + InstanceAMI: + Description: Managed AMI ID for EC2 Instance + Type: AWS::SSM::Parameter::Value + Default: /aws/service/debian/release/10/latest/amd64 + + IAMRole: + Description: EC2 attached IAM role + Type: String + Default: CloudWatchAgentAdminRole + ConstraintDescription: must be an existing IAM role which will be attached to EC2 instance. + + SSHLocation: + Description: The IP address range that can be used to SSH to the EC2 instances + Type: String + Default: 0.0.0.0/0 + MinLength: "9" + MaxLength: "18" + AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2}) + ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x. + + SubnetId: + Type: AWS::EC2::Subnet::Id + +Resources: + EC2Instance: + CreationPolicy: + ResourceSignal: + Count: 1 + Timeout: PT15M + Type: AWS::EC2::Instance + Metadata: + AWS::CloudFormation::Init: + configSets: + default: + - 01_setupCfnHup + - 02_config-amazon-cloudwatch-agent + - 03_restart_amazon-cloudwatch-agent + UpdateEnvironment: + - 02_config-amazon-cloudwatch-agent + - 03_restart_amazon-cloudwatch-agent + + # Definition of a dummy file, that change the contents of the dummy file can trigger the agent to reload the configuration from SSM parameter store. + 02_config-amazon-cloudwatch-agent: + files: + /opt/aws/amazon-cloudwatch-agent/etc/dummy.version: + content: | + "You can change the VERSION below to to simulate the update of metadata" + "VERSION=1.0" + + # Invoke amazon-cloudwatch-agent-ctl to restart the AmazonCloudWatchAgent. + 03_restart_amazon-cloudwatch-agent: + commands: + 01_stop_service: + command: /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop + 02_start_service: + command: !Sub + - | + /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:${ssmkey} -s + - ssmkey: !Ref SSMKey + + # Cfn-hup setting, it is to monitor the change of metadata. + # When there is change in the contents of json file in the metadata section, cfn-hup will call cfn-init to restart the AmazonCloudWatchAgent. + 01_setupCfnHup: + files: + /etc/cfn/cfn-hup.conf: + content: !Sub | + [main] + stack=${AWS::StackId} + region=${AWS::Region} + interval=1 + mode: "000400" + owner: root + group: root + /etc/cfn/hooks.d/amazon-cloudwatch-agent-auto-reloader.conf: + content: !Sub | + [cfn-auto-reloader-hook] + triggers=post.update + path=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init.02_config-amazon-cloudwatch-agent + action=/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets UpdateEnvironment + runas=root + mode: "000400" + owner: root + group: root + /lib/systemd/system/cfn-hup.service: + content: | + [Unit] + Description=cfn-hup daemon + [Service] + Type=simple + ExecStart=/opt/aws/bin/cfn-hup + Restart=always + [Install] + WantedBy=multi-user.target + commands: + 01enable_cfn_hup: + command: systemctl enable cfn-hup.service + 02start_cfn_hup: + command: systemctl start cfn-hup.service + Properties: + InstanceType: !Ref InstanceType + IamInstanceProfile: !Ref IAMRole + KeyName: !Ref KeyName + ImageId: !Ref InstanceAMI + SubnetId: !Ref SubnetId + SecurityGroupIds: + - !GetAtt InstanceSecurityGroup.GroupId + UserData: !Base64 + Fn::Sub: + - | + #!/bin/bash + wget https://s3.amazonaws.com/amazoncloudwatch-agent/debian/amd64/latest/amazon-cloudwatch-agent.deb -O /tmp/amazon-cloudwatch-agent.deb + sudo dpkg -i /tmp/amazon-cloudwatch-agent.deb + /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:${ssmkey} -s + wget https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz -O /tmp/aws-cfn-bootstrap-py3-latest.tar.gz + sudo apt-get update -y + sudo apt-get install -y python3-pip python3-venv + + # Create and activate a virtual environment + python3 -m venv /opt/aws/virtualenv + source /opt/aws/virtualenv/bin/activate + + # Install the bootstrap package + pip install /tmp/aws-cfn-bootstrap-py3-latest.tar.gz + + # Create necessary symlinks + sudo mkdir -p /opt/aws/bin + sudo ln -s /opt/aws/virtualenv/bin/cfn-* /opt/aws/bin/ + + # Run cfn-init + /opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets default + /opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} + - ssmkey: !Ref SSMKey + + InstanceSecurityGroup: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Enable SSH access via port 22 + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: "22" + ToPort: "22" + CidrIp: !Ref SSHLocation diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/redhat.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/redhat.json new file mode 100644 index 0000000000000000000000000000000000000000..feaf35c02fbe83ce0db33427db0358f3b731a6bd --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/redhat.json @@ -0,0 +1,226 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "Template to install CloudWatchAgent on redhat. It was validated on redhat 7.5", + "Parameters": { + "SSMKey": { + "Description": "Name of parameter store which contains the json configuration of CWAgent.", + "Type": "String", + "Default": "AmazonCloudWatch-DefaultLinuxConfigCloudFormation" + }, + "KeyName": { + "Description": "Name of an existing EC2 KeyPair to enable SSH access to the instance", + "Type": "AWS::EC2::KeyPair::KeyName", + "ConstraintDescription": "must be the name of an existing EC2 KeyPair." + }, + "InstanceType": { + "Description": "EC2 instance type", + "Type": "String", + "Default": "t3.medium", + "ConstraintDescription": "must be a valid EC2 instance type." + }, + "RHELVersion": { + "Type": "String", + "AllowedValues": [ + "RHEL9" + ], + "Default": "RHEL9", + "Description": "RHEL version to deploy" + }, + "IAMRole": { + "Description": "EC2 attached IAM role", + "Type": "String", + "Default": "CloudWatchAgentAdminRole", + "ConstraintDescription": "must be an existing IAM role which will be attached to EC2 instance." + }, + "SSHLocation": { + "Description": "The IP address range that can be used to SSH to the EC2 instances", + "Type": "String", + "Default": "0.0.0.0/0", + "MinLength": "9", + "MaxLength": "18", + "AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})", + "ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x." + }, + "SubnetId": { + "Type": "AWS::EC2::Subnet::Id" + } + }, + + "Mappings": { + "RegionMap": { + "us-east-1": { + "RHEL9": "ami-0fb13bb53494158e9" + }, + "us-east-2": { + "RHEL9": "ami-0aeea2f24f6d3ba32" + }, + "us-west-1": { + "RHEL9": "ami-068c2af1200ef7356" + }, + "us-west-2": { + "RHEL9": "ami-0367f2b5c3d1ef960" + }, + "eu-west-1": { + "RHEL9": "ami-0f0f1c02e5e4d9d9f" + }, + "eu-west-2": { + "RHEL9": "ami-02b1e3a99e36afd1a" + }, + "ap-northeast-1": { + "RHEL9": "ami-0eade93757ef7bb6c" + }, + "ap-northeast-2": { + "RHEL9": "ami-097698b6cd8164ea2" + }, + "ap-southeast-1": { + "RHEL9": "ami-0b9521fddc9871128" + }, + "ap-southeast-2": { + "RHEL9": "ami-0eea634029e7b983c" + } + } + }, + + "Resources": { + "EC2Instance": { + "CreationPolicy": { + "ResourceSignal": { + "Count": 1, + "Timeout": "PT15M" + } + }, + "Type": "AWS::EC2::Instance", + "Metadata": { + "AWS::CloudFormation::Init": { + "configSets": { + "default": [ + "01_setupCfnHup", + "02_config-amazon-cloudwatch-agent", + "03_restart_amazon-cloudwatch-agent" + ], + "UpdateEnvironment": [ + "02_config-amazon-cloudwatch-agent", + "03_restart_amazon-cloudwatch-agent" + ] + }, + "02_config-amazon-cloudwatch-agent": { + "files": { + "/opt/aws/amazon-cloudwatch-agent/etc/dummy.version": { + "content": "\"You can change the VERSION below to to simulate the update of metadata\"\n\"VERSION=1.0\"\n" + } + } + }, + "03_restart_amazon-cloudwatch-agent": { + "commands": { + "01_stop_service": { + "command": "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop" + }, + "02_start_service": { + "command": { + "Fn::Sub": [ + "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:${ssmkey} -s\n", + { + "ssmkey": { + "Ref": "SSMKey" + } + } + ] + } + } + } + }, + "01_setupCfnHup": { + "files": { + "/etc/cfn/cfn-hup.conf": { + "content": { + "Fn::Sub": "[main]\nstack=${AWS::StackId}\nregion=${AWS::Region}\ninterval=1\n" + }, + "mode": "000400", + "owner": "root", + "group": "root" + }, + "/etc/cfn/hooks.d/amazon-cloudwatch-agent-auto-reloader.conf": { + "content": { + "Fn::Sub": "[cfn-auto-reloader-hook]\ntriggers=post.update\npath=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init.02_config-amazon-cloudwatch-agent\naction=/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets UpdateEnvironment\nrunas=root\n" + }, + "mode": "000400", + "owner": "root", + "group": "root" + }, + "/lib/systemd/system/cfn-hup.service": { + "content": "[Unit]\nDescription=cfn-hup daemon\n[Service]\nType=simple\nExecStart=/opt/aws/bin/cfn-hup\nRestart=always\n[Install]\nWantedBy=multi-user.target\n" + } + }, + "commands": { + "01enable_cfn_hup": { + "command": "systemctl enable cfn-hup.service" + }, + "02start_cfn_hup": { + "command": "systemctl start cfn-hup.service" + } + } + } + } + }, + "Properties": { + "InstanceType": { + "Ref": "InstanceType" + }, + "IamInstanceProfile": { + "Ref": "IAMRole" + }, + "KeyName": { + "Ref": "KeyName" + }, + "ImageId": { + "Fn::FindInMap": [ + "RegionMap", + { + "Ref": "AWS::Region" + }, + { + "Ref": "RHELVersion" + } + ] + }, + "SubnetId": { + "Ref": "SubnetId" + }, + "SecurityGroupIds": [ + { + + "Fn::GetAtt" : [ "InstanceSecurityGroup", "GroupId" ] + } + ], + "UserData": { + "Fn::Base64": { + "Fn::Sub": [ + "#!/bin/bash\nrpm -Uvh https://s3.amazonaws.com/amazoncloudwatch-agent/redhat/amd64/latest/amazon-cloudwatch-agent.rpm\n/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:${ssmkey} -s\nyum update -y\nyum install python3 -y\ncurl -O https://bootstrap.pypa.io/get-pip.py\n# Install pip using python3\npython3 get-pip.py\nexport PATH=$PATH:/usr/local/bin\npip3 install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz\ncfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets default\ncfn-signal -e $? --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region}\n", + { + "ssmkey": { + "Ref": "SSMKey" + } + } + ] + } + } + } + }, + "InstanceSecurityGroup": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "Enable SSH access via port 22", + "SecurityGroupIngress": [ + { + "IpProtocol": "tcp", + "FromPort": "22", + "ToPort": "22", + "CidrIp": { + "Ref": "SSHLocation" + } + } + ] + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/redhat.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/redhat.yaml new file mode 100644 index 0000000000000000000000000000000000000000..a4592c230abfd7ab942e9c0388f665d605649072 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/redhat.yaml @@ -0,0 +1,183 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: Template to install CloudWatchAgent on redhat. It was validated on redhat 7.5 + +Parameters: + SSMKey: + Description: Name of parameter store which contains the json configuration of CWAgent. + Type: String + Default: AmazonCloudWatch-DefaultLinuxConfigCloudFormation + + KeyName: + Description: Name of an existing EC2 KeyPair to enable SSH access to the instance + Type: AWS::EC2::KeyPair::KeyName + ConstraintDescription: must be the name of an existing EC2 KeyPair. + + InstanceType: + Description: EC2 instance type + Type: String + Default: t3.medium + ConstraintDescription: must be a valid EC2 instance type. + + RHELVersion: + Type: String + AllowedValues: + - RHEL9 + Default: RHEL9 + Description: RHEL version to deploy + + IAMRole: + Description: EC2 attached IAM role + Type: String + Default: CloudWatchAgentAdminRole + ConstraintDescription: must be an existing IAM role which will be attached to EC2 instance. + + SSHLocation: + Description: The IP address range that can be used to SSH to the EC2 instances + Type: String + Default: 0.0.0.0/0 + MinLength: "9" + MaxLength: "18" + AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2}) + ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x. + + SubnetId: + Type: AWS::EC2::Subnet::Id + +Mappings: + RegionMap: + us-east-1: + RHEL9: ami-0fb13bb53494158e9 + us-east-2: + RHEL9: ami-0aeea2f24f6d3ba32 + us-west-1: + RHEL9: ami-068c2af1200ef7356 + us-west-2: + RHEL9: ami-0367f2b5c3d1ef960 + eu-west-1: + RHEL9: ami-0e28d6c0c65e7f82f + eu-west-2: + RHEL9: ami-02b1e3a99e36afd1a + ap-northeast-1: + RHEL9: ami-0eade93757ef7bb6c + ap-northeast-2: + RHEL9: ami-097698b6cd8164ea2 + ap-southeast-1: + RHEL9: ami-0b9521fddc9871128 + ap-southeast-2: + RHEL9: ami-0eea634029e7b983c + + + +Resources: + EC2Instance: + CreationPolicy: + ResourceSignal: + Count: 1 + Timeout: PT15M + Type: AWS::EC2::Instance + Metadata: + AWS::CloudFormation::Init: + configSets: + default: + - 01_setupCfnHup + - 02_config-amazon-cloudwatch-agent + - 03_restart_amazon-cloudwatch-agent + UpdateEnvironment: + - 02_config-amazon-cloudwatch-agent + - 03_restart_amazon-cloudwatch-agent + + # Definition of a dummy file, that change the contents of the dummy file can trigger the agent to reload the configuration from SSM parameter store. + 02_config-amazon-cloudwatch-agent: + files: + /opt/aws/amazon-cloudwatch-agent/etc/dummy.version: + content: | + "You can change the VERSION below to to simulate the update of metadata" + "VERSION=1.0" + + # Invoke amazon-cloudwatch-agent-ctl to restart the AmazonCloudWatchAgent. + 03_restart_amazon-cloudwatch-agent: + commands: + 01_stop_service: + command: /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop + 02_start_service: + command: !Sub + - | + /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:${ssmkey} -s + - ssmkey: !Ref SSMKey + + # Cfn-hup setting, it is to monitor the change of metadata. + # When there is change in the contents of json file in the metadata section, cfn-hup will call cfn-init to restart the AmazonCloudWatchAgent. + 01_setupCfnHup: + files: + /etc/cfn/cfn-hup.conf: + content: !Sub | + [main] + stack=${AWS::StackId} + region=${AWS::Region} + interval=1 + mode: "000400" + owner: root + group: root + /etc/cfn/hooks.d/amazon-cloudwatch-agent-auto-reloader.conf: + content: !Sub | + [cfn-auto-reloader-hook] + triggers=post.update + path=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init.02_config-amazon-cloudwatch-agent + action=/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets UpdateEnvironment + runas=root + mode: "000400" + owner: root + group: root + /lib/systemd/system/cfn-hup.service: + content: | + [Unit] + Description=cfn-hup daemon + [Service] + Type=simple + ExecStart=/opt/aws/bin/cfn-hup + Restart=always + [Install] + WantedBy=multi-user.target + commands: + 01enable_cfn_hup: + command: systemctl enable cfn-hup.service + 02start_cfn_hup: + command: systemctl start cfn-hup.service + Properties: + InstanceType: !Ref InstanceType + IamInstanceProfile: !Ref IAMRole + KeyName: !Ref KeyName + ImageId: !FindInMap + - RegionMap + - !Ref 'AWS::Region' + - !Ref RHELVersion + SubnetId: !Ref SubnetId + SecurityGroupIds: + - !GetAtt InstanceSecurityGroup.GroupId + UserData: !Base64 + Fn::Sub: + - | + #!/bin/bash + rpm -Uvh https://s3.amazonaws.com/amazoncloudwatch-agent/redhat/amd64/latest/amazon-cloudwatch-agent.rpm + /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:${ssmkey} -s + yum update -y + yum install python3 -y + curl -O https://bootstrap.pypa.io/get-pip.py + # Install pip using python3 + python3 get-pip.py + export PATH=$PATH:/usr/local/bin + pip3 install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz + cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets default + cfn-signal -e $? --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} + - ssmkey: !Ref SSMKey + + InstanceSecurityGroup: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Enable SSH access via port 22 + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: "22" + ToPort: "22" + CidrIp: !Ref SSHLocation diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/suse.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/suse.json new file mode 100644 index 0000000000000000000000000000000000000000..2b0debbbb5cfdf055aa039ec71919e5cb7a40961 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/suse.json @@ -0,0 +1,224 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "Template to install CloudWatchAgent on suse. It was validated on suse 12", + "Parameters": { + "SSMKey": { + "Description": "Name of parameter store which contains the json configuration of CWAgent.", + "Type": "String", + "Default": "AmazonCloudWatch-DefaultLinuxConfigCloudFormation" + }, + "KeyName": { + "Description": "Name of an existing EC2 KeyPair to enable SSH access to the instance", + "Type": "AWS::EC2::KeyPair::KeyName", + "ConstraintDescription": "must be the name of an existing EC2 KeyPair." + }, + "InstanceType": { + "Description": "EC2 instance type", + "Type": "String", + "Default": "t3.medium", + "ConstraintDescription": "must be a valid EC2 instance type." + }, + "SUSEVersion": { + "Type": "String", + "AllowedValues": [ + "SLES15SP5" + ], + "Default": "SLES15SP5", + "Description": "SUSE Linux Enterprise Server version to deploy" + }, + "IAMRole": { + "Description": "EC2 attached IAM role", + "Type": "String", + "Default": "CloudWatchAgentAdminRole", + "ConstraintDescription": "must be an existing IAM role which will be attached to EC2 instance." + }, + "SSHLocation": { + "Description": "The IP address range that can be used to SSH to the EC2 instances", + "Type": "String", + "Default": "0.0.0.0/0", + "MinLength": "9", + "MaxLength": "18", + "AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})", + "ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x." + }, + "SubnetId": { + "Type": "AWS::EC2::Subnet::Id" + } + }, + "Mappings": { + "RegionMap": { + "us-east-1": { + "SLES15SP5": "ami-0d62a8e6541a2d491" + }, + "us-east-2": { + "SLES15SP5": "ami-05d1f1c3db2b2eb0c" + }, + "us-west-1": { + "SLES15SP5": "ami-060034d187be82d31" + }, + "us-west-2": { + "SLES15SP5": "ami-066c85d277ae33d38" + }, + "eu-west-1": { + "SLES15SP5": "ami-028867095499bce4b" + }, + "eu-west-2": { + "RHEL9": "ami-03d783398e1e54eb1" + }, + "ap-northeast-1": { + "RHEL9": "ami-05ef8ea5a07946994" + }, + "ap-northeast-2": { + "RHEL9": "ami-0f8bf550807d8d01a" + }, + "ap-southeast-1": { + "RHEL9": "ami-0db03992e79210b9f" + }, + "ap-southeast-2": { + "RHEL9": "ami-084fd76702fabcf2c" + } + } + }, + "Resources": { + "EC2Instance": { + "CreationPolicy": { + "ResourceSignal": { + "Count": 1, + "Timeout": "PT15M" + } + }, + "Type": "AWS::EC2::Instance", + "Metadata": { + "AWS::CloudFormation::Init": { + "configSets": { + "default": [ + "01_setupCfnHup", + "02_config-amazon-cloudwatch-agent", + "03_restart_amazon-cloudwatch-agent" + ], + "UpdateEnvironment": [ + "02_config-amazon-cloudwatch-agent", + "03_restart_amazon-cloudwatch-agent" + ] + }, + "02_config-amazon-cloudwatch-agent": { + "files": { + "/opt/aws/amazon-cloudwatch-agent/etc/dummy.version": { + "content": "\"You can change the VERSION below to to simulate the update of metadata\"\n\"VERSION=1.0\"\n" + } + } + }, + "03_restart_amazon-cloudwatch-agent": { + "commands": { + "01_stop_service": { + "command": "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop" + }, + "02_start_service": { + "command": { + "Fn::Sub": [ + "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:${ssmkey} -s\n", + { + "ssmkey": { + "Ref": "SSMKey" + } + } + ] + } + } + } + }, + "01_setupCfnHup": { + "files": { + "/etc/cfn/cfn-hup.conf": { + "content": { + "Fn::Sub": "[main]\nstack=${AWS::StackId}\nregion=${AWS::Region}\ninterval=1\n" + }, + "mode": "000400", + "owner": "root", + "group": "root" + }, + "/etc/cfn/hooks.d/amazon-cloudwatch-agent-auto-reloader.conf": { + "content": { + "Fn::Sub": "[cfn-auto-reloader-hook]\ntriggers=post.update\npath=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init.02_config-amazon-cloudwatch-agent\naction=/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets UpdateEnvironment\nrunas=root\n" + }, + "mode": "000400", + "owner": "root", + "group": "root" + }, + "/lib/systemd/system/cfn-hup.service": { + "content": "[Unit]\nDescription=cfn-hup daemon\n[Service]\nType=simple\nExecStart=/opt/aws/bin/cfn-hup\nRestart=always\n[Install]\nWantedBy=multi-user.target\n" + } + }, + "commands": { + "01enable_cfn_hup": { + "command": "systemctl enable cfn-hup.service" + }, + "02start_cfn_hup": { + "command": "systemctl start cfn-hup.service" + } + } + } + } + }, + "Properties": { + "InstanceType": { + "Ref": "InstanceType" + }, + "IamInstanceProfile": { + "Ref": "IAMRole" + }, + "KeyName": { + "Ref": "KeyName" + }, + "ImageId": { + "Fn::FindInMap": [ + "RegionMap", + { + "Ref": "AWS::Region" + }, + { + "Ref": "SUSEVersion" + } + ] + }, + "SubnetId": { + "Ref": "SubnetId" + }, + "SecurityGroupIds": [ + { + + "Fn::GetAtt" : [ "InstanceSecurityGroup", "GroupId" ] + } + ], + "UserData": { + "Fn::Base64": { + "Fn::Sub": [ + "#!/bin/bash\nrpm -Uvh https://s3.amazonaws.com/amazoncloudwatch-agent/suse/amd64/latest/amazon-cloudwatch-agent.rpm\n/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:${ssmkey} -s\ncurl -O https://bootstrap.pypa.io/pip/3.6/get-pip.py\n# Install pip using python3\npython3 get-pip.py\nexport PATH=$PATH:/usr/local/bin\npip3 install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz\ncfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets default\ncfn-signal -e $? --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region}\n", + { + "ssmkey": { + "Ref": "SSMKey" + } + } + ] + } + } + } + }, + "InstanceSecurityGroup": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "Enable SSH access via port 22", + "SecurityGroupIngress": [ + { + "IpProtocol": "tcp", + "FromPort": "22", + "ToPort": "22", + "CidrIp": { + "Ref": "SSHLocation" + } + } + ] + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/suse.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/suse.yaml new file mode 100644 index 0000000000000000000000000000000000000000..85079412101e284dd750d45188ed2ea0a65c67fe --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/suse.yaml @@ -0,0 +1,180 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: Template to install CloudWatchAgent on suse. It was validated on suse 12 + +Parameters: + SSMKey: + Description: Name of parameter store which contains the json configuration of CWAgent. + Type: String + Default: AmazonCloudWatch-DefaultLinuxConfigCloudFormation + + KeyName: + Description: Name of an existing EC2 KeyPair to enable SSH access to the instance + Type: AWS::EC2::KeyPair::KeyName + ConstraintDescription: must be the name of an existing EC2 KeyPair. + + InstanceType: + Description: EC2 instance type + Type: String + Default: t3.medium + ConstraintDescription: must be a valid EC2 instance type. + + SUSEVersion: + Type: String + AllowedValues: + - SLES15SP5 + Default: SLES15SP5 + Description: SUSE Linux Enterprise Server version to deploy + + + IAMRole: + Description: EC2 attached IAM role + Type: String + Default: CloudWatchAgentAdminRole + ConstraintDescription: must be an existing IAM role which will be attached to EC2 instance. + + SSHLocation: + Description: The IP address range that can be used to SSH to the EC2 instances + Type: String + Default: 0.0.0.0/0 + MinLength: "9" + MaxLength: "18" + AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2}) + ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x. + + SubnetId: + Type: AWS::EC2::Subnet::Id + +Mappings: + RegionMap: + us-east-1: + SLES15SP5: ami-0d62a8e6541a2d491 + us-east-2: + SLES15SP5: ami-05d1f1c3db2b2eb0c + us-west-1: + SLES15SP5: ami-060034d187be82d31 + us-west-2: + SLES15SP5: ami-066c85d277ae33d38 + eu-west-1: + SLES15SP5: ami-028867095499bce4b + eu-west-2: + SLES15SP5: ami-03d783398e1e54eb1 + ap-northeast-1: + SLES15SP5: ami-05ef8ea5a07946994 + ap-northeast-2: + SLES15SP5: ami-0f8bf550807d8d01a + ap-southeast-1: + SLES15SP5: ami-0db03992e79210b9f + ap-southeast-2: + SLES15SP5: ami-084fd76702fabcf2c + +Resources: + EC2Instance: + CreationPolicy: + ResourceSignal: + Count: 1 + Timeout: PT15M + Type: AWS::EC2::Instance + Metadata: + AWS::CloudFormation::Init: + configSets: + default: + - 01_setupCfnHup + - 02_config-amazon-cloudwatch-agent + - 03_restart_amazon-cloudwatch-agent + UpdateEnvironment: + - 02_config-amazon-cloudwatch-agent + - 03_restart_amazon-cloudwatch-agent + + # Definition of a dummy file, that change the contents of the dummy file can trigger the agent to reload the configuration from SSM parameter store. + 02_config-amazon-cloudwatch-agent: + files: + /opt/aws/amazon-cloudwatch-agent/etc/dummy.version: + content: | + "You can change the VERSION below to to simulate the update of metadata" + "VERSION=1.0" + + # Invoke amazon-cloudwatch-agent-ctl to restart the AmazonCloudWatchAgent. + 03_restart_amazon-cloudwatch-agent: + commands: + 01_stop_service: + command: /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop + 02_start_service: + command: !Sub + - | + /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:${ssmkey} -s + - ssmkey: !Ref SSMKey + + # Cfn-hup setting, it is to monitor the change of metadata. + # When there is change in the contents of json file in the metadata section, cfn-hup will call cfn-init to restart the AmazonCloudWatchAgent. + 01_setupCfnHup: + files: + /etc/cfn/cfn-hup.conf: + content: !Sub | + [main] + stack=${AWS::StackId} + region=${AWS::Region} + interval=1 + mode: "000400" + owner: root + group: root + /etc/cfn/hooks.d/amazon-cloudwatch-agent-auto-reloader.conf: + content: !Sub | + [cfn-auto-reloader-hook] + triggers=post.update + path=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init.02_config-amazon-cloudwatch-agent + action=/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets UpdateEnvironment + runas=root + mode: "000400" + owner: root + group: root + /lib/systemd/system/cfn-hup.service: + content: | + [Unit] + Description=cfn-hup daemon + [Service] + Type=simple + ExecStart=/opt/aws/bin/cfn-hup + Restart=always + [Install] + WantedBy=multi-user.target + commands: + 01enable_cfn_hup: + command: systemctl enable cfn-hup.service + 02start_cfn_hup: + command: systemctl start cfn-hup.service + Properties: + InstanceType: !Ref InstanceType + IamInstanceProfile: !Ref IAMRole + KeyName: !Ref KeyName + ImageId: !FindInMap + - RegionMap + - !Ref 'AWS::Region' + - !Ref SUSEVersion + SubnetId: !Ref SubnetId + SecurityGroupIds: + - !GetAtt InstanceSecurityGroup.GroupId + UserData: !Base64 + Fn::Sub: + - | + #!/bin/bash + rpm -Uvh https://s3.amazonaws.com/amazoncloudwatch-agent/suse/amd64/latest/amazon-cloudwatch-agent.rpm + /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:${ssmkey} -s + curl -O https://bootstrap.pypa.io/pip/3.6/get-pip.py + # Install pip using python3 + python3 get-pip.py + export PATH=$PATH:/usr/local/bin + pip3 install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz + cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets default + cfn-signal -e $? --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} + - ssmkey: !Ref SSMKey + + InstanceSecurityGroup: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Enable SSH access via port 22 + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: "22" + ToPort: "22" + CidrIp: !Ref SSHLocation diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/ubuntu.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/ubuntu.json new file mode 100644 index 0000000000000000000000000000000000000000..80f133fb5920852d72e01199e7055b411f8e2fba --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/ubuntu.json @@ -0,0 +1,179 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "Template to install CloudWatchAgent on ubuntu. It was validated on ubuntu 22.04", + "Parameters": { + "SSMKey": { + "Description": "Name of parameter store which contains the json configuration of CWAgent.", + "Type": "String", + "Default": "AmazonCloudWatch-DefaultLinuxConfigCloudFormation" + }, + "KeyName": { + "Description": "Name of an existing EC2 KeyPair to enable SSH access to the instance", + "Type": "AWS::EC2::KeyPair::KeyName", + "ConstraintDescription": "must be the name of an existing EC2 KeyPair." + }, + "InstanceType": { + "Description": "EC2 instance type", + "Type": "String", + "Default": "t3.medium", + "ConstraintDescription": "must be a valid EC2 instance type." + }, + "InstanceAMI": { + "Description": "Managed AMI ID for EC2 Instance", + "Type": "AWS::SSM::Parameter::Value", + "Default": "/aws/service/canonical/ubuntu/eks-pro/22.04/1.29/stable/current/amd64/hvm/ebs-gp2/ami-id" + }, + "IAMRole": { + "Description": "EC2 attached IAM role", + "Type": "String", + "Default": "CloudWatchAgentAdminRole", + "ConstraintDescription": "must be an existing IAM role which will be attached to EC2 instance." + }, + "SSHLocation": { + "Description": "The IP address range that can be used to SSH to the EC2 instances", + "Type": "String", + "Default": "0.0.0.0/0", + "MinLength": "9", + "MaxLength": "18", + "AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})", + "ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x." + }, + "SubnetId": { + "Type": "AWS::EC2::Subnet::Id" + } + }, + "Resources": { + "EC2Instance": { + "CreationPolicy": { + "ResourceSignal": { + "Count": 1, + "Timeout": "PT15M" + } + }, + "Type": "AWS::EC2::Instance", + "Metadata": { + "AWS::CloudFormation::Init": { + "configSets": { + "default": [ + "01_setupCfnHup", + "02_config-amazon-cloudwatch-agent", + "03_restart_amazon-cloudwatch-agent" + ], + "UpdateEnvironment": [ + "02_config-amazon-cloudwatch-agent", + "03_restart_amazon-cloudwatch-agent" + ] + }, + "02_config-amazon-cloudwatch-agent": { + "files": { + "/opt/aws/amazon-cloudwatch-agent/etc/dummy.version": { + "content": "\"You can change the VERSION below to to simulate the update of metadata\"\n\"VERSION=1.0\"\n" + } + } + }, + "03_restart_amazon-cloudwatch-agent": { + "commands": { + "01_stop_service": { + "command": "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop" + }, + "02_start_service": { + "command": { + "Fn::Sub": [ + "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:${ssmkey} -s\n", + { + "ssmkey": { + "Ref": "SSMKey" + } + } + ] + } + } + } + }, + "01_setupCfnHup": { + "files": { + "/etc/cfn/cfn-hup.conf": { + "content": { + "Fn::Sub": "[main]\nstack=${AWS::StackId}\nregion=${AWS::Region}\ninterval=1\n" + }, + "mode": "000400", + "owner": "root", + "group": "root" + }, + "/etc/cfn/hooks.d/amazon-cloudwatch-agent-auto-reloader.conf": { + "content": { + "Fn::Sub": "[cfn-auto-reloader-hook]\ntriggers=post.update\npath=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init.02_config-amazon-cloudwatch-agent\naction=/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets UpdateEnvironment\nrunas=root\n" + }, + "mode": "000400", + "owner": "root", + "group": "root" + }, + "/lib/systemd/system/cfn-hup.service": { + "content": "[Unit]\nDescription=cfn-hup daemon\n[Service]\nType=simple\nExecStart=/opt/aws/bin/cfn-hup\nRestart=always\n[Install]\nWantedBy=multi-user.target\n" + } + }, + "commands": { + "01enable_cfn_hup": { + "command": "systemctl enable cfn-hup.service" + }, + "02start_cfn_hup": { + "command": "systemctl start cfn-hup.service" + } + } + } + } + }, + "Properties": { + "InstanceType": { + "Ref": "InstanceType" + }, + "IamInstanceProfile": { + "Ref": "IAMRole" + }, + "KeyName": { + "Ref": "KeyName" + }, + "ImageId": { + "Ref": "InstanceAMI" + }, + "SubnetId": { + "Ref": "SubnetId" + }, + "SecurityGroupIds": [ + { + + "Fn::GetAtt" : [ "InstanceSecurityGroup", "GroupId" ] + } + ], + "UserData": { + "Fn::Base64": { + "Fn::Sub": [ + "#!/bin/bash\nwget https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb -O /tmp/amazon-cloudwatch-agent.deb\ndpkg -i /tmp/amazon-cloudwatch-agent.deb\n/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:${ssmkey} -s\napt-get update -y\napt-get install -y python3 python3-pip\npip3 install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz\ncfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets default\ncfn-signal -e $? --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region}\n", + { + "ssmkey": { + "Ref": "SSMKey" + } + } + ] + } + } + } + }, + "InstanceSecurityGroup": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "Enable SSH access via port 22", + "SecurityGroupIngress": [ + { + "IpProtocol": "tcp", + "FromPort": "22", + "ToPort": "22", + "CidrIp": { + "Ref": "SSHLocation" + } + } + ] + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/ubuntu.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/ubuntu.yaml new file mode 100644 index 0000000000000000000000000000000000000000..bc1845647bbe7c1da9ee208271b88a7013ff194b --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/ubuntu.yaml @@ -0,0 +1,150 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: Template to install CloudWatchAgent on ubuntu. It was validated on ubuntu 22.04 + +Parameters: + SSMKey: + Description: Name of parameter store which contains the json configuration of CWAgent. + Type: String + Default: AmazonCloudWatch-DefaultLinuxConfigCloudFormation + + KeyName: + Description: Name of an existing EC2 KeyPair to enable SSH access to the instance + Type: AWS::EC2::KeyPair::KeyName + ConstraintDescription: must be the name of an existing EC2 KeyPair. + + InstanceType: + Description: EC2 instance type + Type: String + Default: t3.medium + ConstraintDescription: must be a valid EC2 instance type. + + InstanceAMI: + Description: Managed AMI ID for EC2 Instance + Type: AWS::SSM::Parameter::Value + Default: /aws/service/canonical/ubuntu/eks-pro/22.04/1.29/stable/current/amd64/hvm/ebs-gp2/ami-id + + IAMRole: + Description: EC2 attached IAM role + Type: String + Default: CloudWatchAgentAdminRole + ConstraintDescription: must be an existing IAM role which will be attached to EC2 instance. + + SSHLocation: + Description: The IP address range that can be used to SSH to the EC2 instances + Type: String + Default: 0.0.0.0/0 + MinLength: "9" + MaxLength: "18" + AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2}) + ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x. + + SubnetId: + Type: AWS::EC2::Subnet::Id + +Resources: + EC2Instance: + CreationPolicy: + ResourceSignal: + Count: 1 + Timeout: PT15M + Type: AWS::EC2::Instance + Metadata: + AWS::CloudFormation::Init: + configSets: + default: + - 01_setupCfnHup + - 02_config-amazon-cloudwatch-agent + - 03_restart_amazon-cloudwatch-agent + UpdateEnvironment: + - 02_config-amazon-cloudwatch-agent + - 03_restart_amazon-cloudwatch-agent + + # Definition of a dummy file, that change the contents of the dummy file can trigger the agent to reload the configuration from SSM parameter store. + 02_config-amazon-cloudwatch-agent: + files: + /opt/aws/amazon-cloudwatch-agent/etc/dummy.version: + content: | + "You can change the VERSION below to to simulate the update of metadata" + "VERSION=1.0" + + # Invoke amazon-cloudwatch-agent-ctl to restart the AmazonCloudWatchAgent. + 03_restart_amazon-cloudwatch-agent: + commands: + 01_stop_service: + command: /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop + 02_start_service: + command: !Sub + - | + /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:${ssmkey} -s + - ssmkey: !Ref SSMKey + + # Cfn-hup setting, it is to monitor the change of metadata. + # When there is change in the contents of json file in the metadata section, cfn-hup will call cfn-init to restart the AmazonCloudWatchAgent. + 01_setupCfnHup: + files: + /etc/cfn/cfn-hup.conf: + content: !Sub | + [main] + stack=${AWS::StackId} + region=${AWS::Region} + interval=1 + mode: "000400" + owner: root + group: root + /etc/cfn/hooks.d/amazon-cloudwatch-agent-auto-reloader.conf: + content: !Sub | + [cfn-auto-reloader-hook] + triggers=post.update + path=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init.02_config-amazon-cloudwatch-agent + action=/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets UpdateEnvironment + runas=root + mode: "000400" + owner: root + group: root + /lib/systemd/system/cfn-hup.service: + content: | + [Unit] + Description=cfn-hup daemon + [Service] + Type=simple + ExecStart=/opt/aws/bin/cfn-hup + Restart=always + [Install] + WantedBy=multi-user.target + commands: + 01enable_cfn_hup: + command: systemctl enable cfn-hup.service + 02start_cfn_hup: + command: systemctl start cfn-hup.service + Properties: + InstanceType: !Ref InstanceType + IamInstanceProfile: !Ref IAMRole + KeyName: !Ref KeyName + ImageId: !Ref InstanceAMI + SubnetId: !Ref SubnetId + SecurityGroupIds: + - !GetAtt InstanceSecurityGroup.GroupId + UserData: !Base64 + Fn::Sub: + - | + #!/bin/bash + wget https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb -O /tmp/amazon-cloudwatch-agent.deb + dpkg -i /tmp/amazon-cloudwatch-agent.deb + /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:${ssmkey} -s + apt-get update -y + apt-get install -y python3 python3-pip + pip3 install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz + cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets default + cfn-signal -e $? --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} + - ssmkey: !Ref SSMKey + + InstanceSecurityGroup: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Enable SSH access via port 22 + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: "22" + ToPort: "22" + CidrIp: !Ref SSHLocation diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/windows.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/windows.json new file mode 100644 index 0000000000000000000000000000000000000000..25aa64db1dc9a7a13c359f7128ba7446a1ce4e1b --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/windows.json @@ -0,0 +1,146 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "Template to install CloudWatchAgent on windows. It was validated on windows 2016", + "Parameters": { + "SSMKey": { + "Description": "Name of parameter store which contains the json configuration of CWAgent.", + "Type": "String", + "Default": "AmazonCloudWatch-DefaultWindowsConfigCloudFormation" + }, + "KeyName": { + "Description": "Name of an existing EC2 KeyPair to enable SSH access to the instance", + "Type": "AWS::EC2::KeyPair::KeyName", + "ConstraintDescription": "must be the name of an existing EC2 KeyPair." + }, + "InstanceType": { + "Description": "EC2 instance type", + "Type": "String", + "Default": "t3.medium", + "ConstraintDescription": "must be a valid EC2 instance type." + }, + "InstanceAMI": { + "Description": "Managed AMI ID for EC2 Instance", + "Type": "AWS::SSM::Parameter::Value", + "Default": "/aws/service/ami-windows-latest/Windows_Server-2022-English-Full-SQL_2022_Web" + }, + "IAMRole": { + "Description": "EC2 attached IAM role", + "Type": "String", + "Default": "CloudWatchAgentAdminRole", + "ConstraintDescription": "must be an existing IAM role which will be attached to EC2 instance." + }, + "SubnetId": { + "Type": "AWS::EC2::Subnet::Id" + } + }, + "Resources": { + "EC2Instance": { + "CreationPolicy": { + "ResourceSignal": { + "Count": 1, + "Timeout": "PT15M" + } + }, + "Type": "AWS::EC2::Instance", + "Metadata": { + "AWS::CloudFormation::Init": { + "configSets": { + "default": [ + "00_setupCfnHup", + "01_CfnHup_service", + "02_config-amazon-cloudwatch-agent", + "03_restart_amazon-cloudwatch-agent" + ], + "UpdateEnvironment": [ + "02_config-amazon-cloudwatch-agent", + "03_restart_amazon-cloudwatch-agent" + ] + }, + "00_setupCfnHup": { + "files": { + "c:\\cfn\\cfn-hup.conf": { + "content": { + "Fn::Sub": "[main]\nstack=${AWS::StackId}\nregion=${AWS::Region}\ninterval=1\n" + } + }, + "c:\\cfn\\hooks.d\\amazon-cloudwatch-agent-auto-reloader.conf": { + "content": { + "Fn::Sub": "[cfn-auto-reloader-hook]\ntriggers=post.update\npath=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init.02_config-amazon-cloudwatch-agent\naction=cfn-init.exe -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets UpdateEnvironment\n" + } + } + } + }, + "01_CfnHup_service": { + "services": { + "windows": { + "cfn-hup": { + "enabled": "true", + "ensureRunning": "true", + "files": [ + "c:\\cfn\\cfn-hup.conf", + "c:\\cfn\\hooks.d\\cfn-auto-reloader.conf" + ] + } + } + } + }, + "02_config-amazon-cloudwatch-agent": { + "files": { + "C:\\ProgramData\\Amazon\\AmazonCloudWatchAgent\\dummy.version": { + "content": "\"You can change the VERSION below to to simulate the update of metadata\"\n\"VERSION=1.0\"\n" + } + } + }, + "03_restart_amazon-cloudwatch-agent": { + "commands": { + "01_stop_service": { + "command": "powershell -Command \"C:\\\\'Program Files'\\\\Amazon\\\\AmazonCloudWatchAgent\\\\amazon-cloudwatch-agent-ctl.ps1 -a stop\"" + }, + "02_start_service": { + "command": { + "Fn::Sub": [ + "powershell -Command \"C:\\\\'Program Files'\\\\Amazon\\\\AmazonCloudWatchAgent\\\\amazon-cloudwatch-agent-ctl.ps1 -a fetch-config -m ec2 -c ssm:${ssmkey} -s\"\n", + { + "ssmkey": { + "Ref": "SSMKey" + } + } + ] + } + } + } + } + } + }, + "Properties": { + "InstanceType": { + "Ref": "InstanceType" + }, + "IamInstanceProfile": { + "Ref": "IAMRole" + }, + "KeyName": { + "Ref": "KeyName" + }, + "ImageId": { + "Ref": "InstanceAMI" + }, + "SubnetId": { + "Ref": "SubnetId" + }, + "UserData": { + "Fn::Base64": { + "Fn::Sub": [ + "\n", + { + "ssmkey": { + "Ref": "SSMKey" + } + } + ] + } + } + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/windows.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/windows.yaml new file mode 100644 index 0000000000000000000000000000000000000000..532b35751c67cafd7e06c4cdcb1655dd11f26638 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/AmazonCloudWatchAgent/ssm/windows.yaml @@ -0,0 +1,116 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: Template to install CloudWatchAgent on windows. It was validated on windows 2016 + +Parameters: + SSMKey: + Description: Name of parameter store which contains the json configuration of CWAgent. + Type: String + Default: AmazonCloudWatch-DefaultWindowsConfigCloudFormation + + KeyName: + Description: Name of an existing EC2 KeyPair to enable SSH access to the instance + Type: AWS::EC2::KeyPair::KeyName + ConstraintDescription: must be the name of an existing EC2 KeyPair. + + InstanceType: + Description: EC2 instance type + Type: String + Default: t3.medium + ConstraintDescription: must be a valid EC2 instance type. + + InstanceAMI: + Description: Managed AMI ID for EC2 Instance + Type: AWS::SSM::Parameter::Value + Default: /aws/service/ami-windows-latest/Windows_Server-2022-English-Full-SQL_2022_Web + + IAMRole: + Description: EC2 attached IAM role + Type: String + Default: CloudWatchAgentAdminRole + ConstraintDescription: must be an existing IAM role which will be attached to EC2 instance. + + SubnetId: + Type: AWS::EC2::Subnet::Id + +Resources: + EC2Instance: + CreationPolicy: + ResourceSignal: + Count: 1 + Timeout: PT15M + Type: AWS::EC2::Instance + Metadata: + AWS::CloudFormation::Init: + configSets: + default: + - 00_setupCfnHup + - 01_CfnHup_service + - 02_config-amazon-cloudwatch-agent + - 03_restart_amazon-cloudwatch-agent + UpdateEnvironment: + - 02_config-amazon-cloudwatch-agent + - 03_restart_amazon-cloudwatch-agent + + # Cfn-hup setting, it is to monitor the change of metadata. + # When there is change in the contents of json file in the metadata section, cfn-hup will call cfn-init to restart the AmazonCloudWatchAgent. + 00_setupCfnHup: + files: + c:\cfn\cfn-hup.conf: + content: !Sub | + [main] + stack=${AWS::StackId} + region=${AWS::Region} + interval=1 + c:\cfn\hooks.d\amazon-cloudwatch-agent-auto-reloader.conf: + content: !Sub | + [cfn-auto-reloader-hook] + triggers=post.update + path=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init.02_config-amazon-cloudwatch-agent + action=cfn-init.exe -v --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region} --configsets UpdateEnvironment + 01_CfnHup_service: + services: + windows: + cfn-hup: + enabled: "true" + ensureRunning: "true" + files: + - c:\cfn\cfn-hup.conf + - c:\cfn\hooks.d\cfn-auto-reloader.conf + + # Definition of a dummy file, that change the contents of the dummy file can trigger the agent to reload the configuration from SSM parameter store. + 02_config-amazon-cloudwatch-agent: + files: + C:\ProgramData\Amazon\AmazonCloudWatchAgent\dummy.version: + content: | + "You can change the VERSION below to to simulate the update of metadata" + "VERSION=1.0" + + # Invoke amazon-cloudwatch-agent-ctl to restart the AmazonCloudWatchAgent. + 03_restart_amazon-cloudwatch-agent: + commands: + 01_stop_service: + command: powershell -Command "C:\\'Program Files'\\Amazon\\AmazonCloudWatchAgent\\amazon-cloudwatch-agent-ctl.ps1 -a stop" + 02_start_service: + command: !Sub + - | + powershell -Command "C:\\'Program Files'\\Amazon\\AmazonCloudWatchAgent\\amazon-cloudwatch-agent-ctl.ps1 -a fetch-config -m ec2 -c ssm:${ssmkey} -s" + - ssmkey: !Ref SSMKey + Properties: + InstanceType: !Ref InstanceType + IamInstanceProfile: !Ref IAMRole + KeyName: !Ref KeyName + ImageId: !Ref InstanceAMI + SubnetId: !Ref SubnetId + UserData: !Base64 + Fn::Sub: + - | + + - ssmkey: !Ref SSMKey diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFormationEndpointSignals/README.md b/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFormationEndpointSignals/README.md new file mode 100644 index 0000000000000000000000000000000000000000..438e8106639259cf4101fbb59173680b7beb584f --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFormationEndpointSignals/README.md @@ -0,0 +1,35 @@ +# Using CloudFormation VPC endpoints with cfn-signal + +One of the most common use cases for the new CloudFormation VPC endpoints is to +allow resources within a VPC to signal back to CloudFormation `CreationPolicy` +and `WaitConditionHandles` without needing to route across the public internet. + +These example templates demonstrate the bare minimum resources required to use +`cfn-signal` from inside a private subnet in both cases. Resources using +`CreationPolicy` (usually EC2 instances and Auto Scaling Groups) can get their +signals across the CloudFormation endpoint directly, but `WaitConditions` and +`CustomResources` will also need an S3 endpoint in order to respond to the +self-signed URLs for those resources. + +This folder has versions with Internet Gateways and Bastions to allow the end user +to SSH onto the private EC2 and take a look at what's going on, as well as +fully self-contained VPCs with no external access other than the VPC endpoints. + +| Template | CreationPolicy | WaitCondition | IGW/Bastion | +| ----------------------------------------- | -------------- | ------------- | ----------- | +| `cfn-endpoint-creationpolicy-no-igw.yaml` | **yes** | no | no | +| `cfn-endpoint-creationpolicy.yaml` | **yes** | no | **yes** | +| `cfn-endpoint-waitcondition-no-igw.yaml` | no | **yes** | no | +| `cfn-endpoint-waitcondition.yaml` | no | **yes** | **yes** | + +**NOTE:** If you're signaling back from EC2/Auto Scaling, you really should be using `CreationPolicies`. They're easier to configure and have some cool additional features around auto scaling. Save `WaitCondition` for more complex workflow logic. + +For more information: + +- [Setting Up VPC Endpoints for AWS CloudFormation + ](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-vpce-bucketnames.html) +- [Interface VPC Endpoint (for CloudFormation)](https://docs.aws.amazon.com/vpc/latest/userguide/vpce-interface.html) +- [Gateway VPC Endpoints + (for S3)](https://docs.aws.amazon.com/vpc/latest/userguide/vpce-gateway.html) +- [AWS::EC2::VPCEndpoint](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-vpcendpoint.html) +- [Creating Wait Conditions in a Template](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-waitcondition.html) diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFormationEndpointSignals/cfn-endpoint-creationpolicy-no-igw.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFormationEndpointSignals/cfn-endpoint-creationpolicy-no-igw.json new file mode 100644 index 0000000000000000000000000000000000000000..7ba2bbe932cde6c95f5ea3dd374b5f355a564635 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFormationEndpointSignals/cfn-endpoint-creationpolicy-no-igw.json @@ -0,0 +1,309 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "This template deploys a VPC with a pair of private subnets spread across two Availabilty Zones. It deploys a VPC Endpoint for CloudFormation so an instance in the private subnet can use cfn-signal for its CreationPolicy. **WARNING** You will be billed for the AWS resources used if you create a stack from this template.", + "Parameters": { + "EnvironmentName": { + "Description": "An environment name that will be prefixed to resource names", + "Type": "String" + }, + "VpcCIDR": { + "Description": "Please enter the IP range (CIDR notation) for this VPC", + "Type": "String", + "Default": "10.192.0.0/16", + "AllowedPattern": "((\\d{1,3})\\.){3}\\d{1,3}/\\d{1,2}" + }, + "PrivateSubnet1CIDR": { + "Description": "Please enter the IP range (CIDR notation) for the private subnet in the first Availability Zone", + "Type": "String", + "Default": "10.192.20.0/24", + "AllowedPattern": "((\\d{1,3})\\.){3}\\d{1,3}/\\d{1,2}" + }, + "PrivateSubnet2CIDR": { + "Description": "Please enter the IP range (CIDR notation) for the private subnet in the second Availability Zone", + "Type": "String", + "Default": "10.192.21.0/24", + "AllowedPattern": "((\\d{1,3})\\.){3}\\d{1,3}/\\d{1,2}" + }, + "LinuxAMI": { + "Description": "Managed AMI ID for Amazon Linux", + "Type": "AWS::SSM::Parameter::Value", + "Default": "/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2" + } + }, + "Resources": { + "VPC": { + "Type": "AWS::EC2::VPC", + "Properties": { + "EnableDnsSupport": true, + "EnableDnsHostnames": true, + "CidrBlock": { + "Ref": "VpcCIDR" + }, + "Tags": [ + { + "Key": "Name", + "Value": { + "Ref": "EnvironmentName" + } + } + ] + } + }, + "CfnEndpoint": { + "Type": "AWS::EC2::VPCEndpoint", + "Properties": { + "VpcId": { + "Ref": "VPC" + }, + "ServiceName": { + "Fn::Sub": "com.amazonaws.${AWS::Region}.cloudformation" + }, + "VpcEndpointType": "Interface", + "PrivateDnsEnabled": true, + "SubnetIds": [ + { + "Ref": "PrivateSubnet1" + }, + { + "Ref": "PrivateSubnet2" + } + ], + "SecurityGroupIds": [ + { + "Ref": "EndpointSG" + } + ] + } + }, + "PrivateSubnet1": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "VpcId": { + "Ref": "VPC" + }, + "AvailabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": null + } + ] + }, + "CidrBlock": { + "Ref": "PrivateSubnet1CIDR" + }, + "MapPublicIpOnLaunch": false, + "Tags": [ + { + "Key": "Name", + "Value": { + "Fn::Sub": "${EnvironmentName} Private Subnet (AZ1)" + } + } + ] + } + }, + "PrivateSubnet2": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "VpcId": { + "Ref": "VPC" + }, + "AvailabilityZone": { + "Fn::Select": [ + 1, + { + "Fn::GetAZs": null + } + ] + }, + "CidrBlock": { + "Ref": "PrivateSubnet2CIDR" + }, + "MapPublicIpOnLaunch": false, + "Tags": [ + { + "Key": "Name", + "Value": { + "Fn::Sub": "${EnvironmentName} Private Subnet (AZ2)" + } + } + ] + } + }, + "PrivateRouteTable1": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "VPC" + }, + "Tags": [ + { + "Key": "Name", + "Value": { + "Fn::Sub": "${EnvironmentName} Private Routes (AZ1)" + } + } + ] + } + }, + "PrivateSubnet1RouteTableAssociation": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "PrivateRouteTable1" + }, + "SubnetId": { + "Ref": "PrivateSubnet1" + } + } + }, + "PrivateRouteTable2": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "VPC" + }, + "Tags": [ + { + "Key": "Name", + "Value": { + "Fn::Sub": "${EnvironmentName} Private Routes (AZ2)" + } + } + ] + } + }, + "PrivateSubnet2RouteTableAssociation": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "PrivateRouteTable2" + }, + "SubnetId": { + "Ref": "PrivateSubnet2" + } + } + }, + "PrivateInstance": { + "CreationPolicy": { + "ResourceSignal": { + "Count": 1, + "Timeout": "PT15M" + } + }, + "Type": "AWS::EC2::Instance", + "DependsOn": "CfnEndpoint", + "Properties": { + "InstanceType": "t3.micro", + "SecurityGroupIds": [ + { + "Ref": "PrivateSG" + } + ], + "SubnetId": { + "Ref": "PrivateSubnet1" + }, + "ImageId": { + "Ref": "LinuxAMI" + }, + "UserData": { + "Fn::Base64": { + "Fn::Sub": "#!/bin/bash -x\ndate > /tmp/datefile\ncat /tmp/datefile\n# Signal the status from instance\n/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource PrivateInstance --region ${AWS::Region}\n" + } + }, + "Tags": [ + { + "Key": "Name", + "Value": "Private" + } + ] + } + }, + "PrivateSG": { + "Type": "AWS::EC2::SecurityGroup", + "Metadata": { + "guard": { + "SuppressedRules": [ + "INCOMING_SSH_DISABLED" + ] + } + }, + "Properties": { + "GroupDescription": "Traffic from Bastion", + "SecurityGroupIngress": [ + { + "IpProtocol": "tcp", + "FromPort": 22, + "ToPort": 22, + "CidrIp": { + "Ref": "VpcCIDR" + } + } + ], + "VpcId": { + "Ref": "VPC" + }, + "Tags": [ + { + "Key": "Name", + "Value": "PrivateSG" + } + ] + } + }, + "EndpointSG": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "Traffic into CloudFormation Endpoint", + "SecurityGroupIngress": [ + { + "IpProtocol": "tcp", + "FromPort": 443, + "ToPort": 443, + "CidrIp": "0.0.0.0/0" + } + ], + "VpcId": { + "Ref": "VPC" + }, + "Tags": [ + { + "Key": "Name", + "Value": "EndpointSG" + } + ] + } + } + }, + "Outputs": { + "VPC": { + "Description": "A reference to the created VPC", + "Value": { + "Ref": "VPC" + } + }, + "PrivateSubnets": { + "Description": "A list of the private subnets", + "Value": { + "Fn::Join": [ + ",", + [ + { + "Ref": "PrivateSubnet1" + }, + { + "Ref": "PrivateSubnet2" + } + ] + ] + } + }, + "CfnEndpoint": { + "Description": "A reference to the CloudFormation Endpoint used for signaling from the private instance", + "Value": { + "Ref": "CfnEndpoint" + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFormationEndpointSignals/cfn-endpoint-creationpolicy-no-igw.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFormationEndpointSignals/cfn-endpoint-creationpolicy-no-igw.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7b2ede272687450c9608d3ecf627fcb59d87111b --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFormationEndpointSignals/cfn-endpoint-creationpolicy-no-igw.yaml @@ -0,0 +1,183 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: This template deploys a VPC with a pair of private subnets spread across two Availabilty Zones. It deploys a VPC Endpoint for CloudFormation so an instance in the private subnet can use cfn-signal for its CreationPolicy. **WARNING** You will be billed for the AWS resources used if you create a stack from this template. + +Parameters: + EnvironmentName: + Description: An environment name that will be prefixed to resource names + Type: String + + VpcCIDR: + Description: Please enter the IP range (CIDR notation) for this VPC + Type: String + Default: 10.192.0.0/16 + AllowedPattern: ((\d{1,3})\.){3}\d{1,3}/\d{1,2} + + PrivateSubnet1CIDR: + Description: Please enter the IP range (CIDR notation) for the private subnet in the first Availability Zone + Type: String + Default: 10.192.20.0/24 + AllowedPattern: ((\d{1,3})\.){3}\d{1,3}/\d{1,2} + + PrivateSubnet2CIDR: + Description: Please enter the IP range (CIDR notation) for the private subnet in the second Availability Zone + Type: String + Default: 10.192.21.0/24 + AllowedPattern: ((\d{1,3})\.){3}\d{1,3}/\d{1,2} + + LinuxAMI: + Description: Managed AMI ID for Amazon Linux + Type: AWS::SSM::Parameter::Value + Default: /aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2 + +Resources: + VPC: + Type: AWS::EC2::VPC + Properties: + EnableDnsSupport: true + EnableDnsHostnames: true + CidrBlock: !Ref VpcCIDR + Tags: + - Key: Name + Value: !Ref EnvironmentName + + # This is the interface endpoint for CloudFormation. You can only deploy this + # once per region since it will consume the unique DNS entry for the endpoint. + CfnEndpoint: + Type: AWS::EC2::VPCEndpoint + Properties: + VpcId: !Ref VPC + ServiceName: !Sub com.amazonaws.${AWS::Region}.cloudformation + VpcEndpointType: Interface + PrivateDnsEnabled: true + SubnetIds: + - !Ref PrivateSubnet1 + - !Ref PrivateSubnet2 + SecurityGroupIds: + - !Ref EndpointSG + + PrivateSubnet1: + Type: AWS::EC2::Subnet + Properties: + VpcId: !Ref VPC + AvailabilityZone: !Select + - 0 + - !GetAZs + CidrBlock: !Ref PrivateSubnet1CIDR + MapPublicIpOnLaunch: false + Tags: + - Key: Name + Value: !Sub ${EnvironmentName} Private Subnet (AZ1) + + PrivateSubnet2: + Type: AWS::EC2::Subnet + Properties: + VpcId: !Ref VPC + AvailabilityZone: !Select + - 1 + - !GetAZs + CidrBlock: !Ref PrivateSubnet2CIDR + MapPublicIpOnLaunch: false + Tags: + - Key: Name + Value: !Sub ${EnvironmentName} Private Subnet (AZ2) + + PrivateRouteTable1: + Type: AWS::EC2::RouteTable + Properties: + VpcId: !Ref VPC + Tags: + - Key: Name + Value: !Sub ${EnvironmentName} Private Routes (AZ1) + + PrivateSubnet1RouteTableAssociation: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + RouteTableId: !Ref PrivateRouteTable1 + SubnetId: !Ref PrivateSubnet1 + + PrivateRouteTable2: + Type: AWS::EC2::RouteTable + Properties: + VpcId: !Ref VPC + Tags: + - Key: Name + Value: !Sub ${EnvironmentName} Private Routes (AZ2) + + PrivateSubnet2RouteTableAssociation: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + RouteTableId: !Ref PrivateRouteTable2 + SubnetId: !Ref PrivateSubnet2 + + PrivateInstance: + CreationPolicy: + ResourceSignal: + Count: 1 + Timeout: PT15M + Type: AWS::EC2::Instance + DependsOn: CfnEndpoint + Properties: + InstanceType: t3.micro + SecurityGroupIds: + - !Ref PrivateSG + SubnetId: !Ref PrivateSubnet1 + ImageId: !Ref LinuxAMI + UserData: !Base64 + Fn::Sub: | + #!/bin/bash -x + date > /tmp/datefile + cat /tmp/datefile + # Signal the status from instance + /opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource PrivateInstance --region ${AWS::Region} + Tags: + - Key: Name + Value: Private + + PrivateSG: + Type: AWS::EC2::SecurityGroup + Metadata: + guard: + SuppressedRules: + - INCOMING_SSH_DISABLED + Properties: + GroupDescription: Traffic from Bastion + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: 22 + ToPort: 22 + CidrIp: !Ref VpcCIDR + VpcId: !Ref VPC + Tags: + - Key: Name + Value: PrivateSG + + EndpointSG: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Traffic into CloudFormation Endpoint + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: 443 + ToPort: 443 + CidrIp: 0.0.0.0/0 + VpcId: !Ref VPC + Tags: + - Key: Name + Value: EndpointSG + +Outputs: + VPC: + Description: A reference to the created VPC + Value: !Ref VPC + + PrivateSubnets: + Description: A list of the private subnets + Value: !Join + - ',' + - - !Ref PrivateSubnet1 + - !Ref PrivateSubnet2 + + CfnEndpoint: + Description: A reference to the CloudFormation Endpoint used for signaling from the private instance + Value: !Ref CfnEndpoint diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFormationEndpointSignals/cfn-endpoint-creationpolicy.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFormationEndpointSignals/cfn-endpoint-creationpolicy.json new file mode 100644 index 0000000000000000000000000000000000000000..bc881290a9beaf40b14acf502fb37eb57a2833a7 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFormationEndpointSignals/cfn-endpoint-creationpolicy.json @@ -0,0 +1,589 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "This template deploys a VPC with a pair of public and private subnets spread across two Availabilty Zones. It deploys an Internet Gateway, with a default route on the public subnets and a bastion server. It deploys a VPC Endpoint for CloudFormation so an instance in the private subnet can use cfn-signal for its CreationPolicy. **WARNING** You will be billed for the AWS resources used if you create a stack from this template.\n", + "Parameters": { + "EnvironmentName": { + "Description": "An environment name that will be prefixed to resource names", + "Type": "String" + }, + "VpcCIDR": { + "Description": "Please enter the IP range (CIDR notation) for this VPC", + "Type": "String", + "Default": "10.192.0.0/16", + "AllowedPattern": "((\\d{1,3})\\.){3}\\d{1,3}/\\d{1,2}" + }, + "PublicSubnet1CIDR": { + "Description": "Please enter the IP range (CIDR notation) for the public subnet in the first Availability Zone", + "Type": "String", + "Default": "10.192.10.0/24", + "AllowedPattern": "((\\d{1,3})\\.){3}\\d{1,3}/\\d{1,2}" + }, + "PublicSubnet2CIDR": { + "Description": "Please enter the IP range (CIDR notation) for the public subnet in the second Availability Zone", + "Type": "String", + "Default": "10.192.11.0/24", + "AllowedPattern": "((\\d{1,3})\\.){3}\\d{1,3}/\\d{1,2}" + }, + "PrivateSubnet1CIDR": { + "Description": "Please enter the IP range (CIDR notation) for the private subnet in the first Availability Zone", + "Type": "String", + "Default": "10.192.20.0/24", + "AllowedPattern": "((\\d{1,3})\\.){3}\\d{1,3}/\\d{1,2}" + }, + "PrivateSubnet2CIDR": { + "Description": "Please enter the IP range (CIDR notation) for the private subnet in the second Availability Zone", + "Type": "String", + "Default": "10.192.21.0/24", + "AllowedPattern": "((\\d{1,3})\\.){3}\\d{1,3}/\\d{1,2}" + }, + "KeyName": { + "Description": "Key pair for EC2 access", + "Type": "AWS::EC2::KeyPair::KeyName" + }, + "LinuxAMI": { + "Description": "Managed AMI ID for Amazon Linux", + "Type": "AWS::SSM::Parameter::Value", + "Default": "/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2" + } + }, + "Resources": { + "VPC": { + "Type": "AWS::EC2::VPC", + "Properties": { + "EnableDnsSupport": true, + "EnableDnsHostnames": true, + "CidrBlock": { + "Ref": "VpcCIDR" + }, + "Tags": [ + { + "Key": "Name", + "Value": { + "Ref": "EnvironmentName" + } + } + ] + } + }, + "InternetGateway": { + "Type": "AWS::EC2::InternetGateway", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": { + "Ref": "EnvironmentName" + } + } + ] + } + }, + "InternetGatewayAttachment": { + "Type": "AWS::EC2::VPCGatewayAttachment", + "Properties": { + "InternetGatewayId": { + "Ref": "InternetGateway" + }, + "VpcId": { + "Ref": "VPC" + } + } + }, + "CfnEndpoint": { + "Type": "AWS::EC2::VPCEndpoint", + "Properties": { + "VpcId": { + "Ref": "VPC" + }, + "ServiceName": { + "Fn::Sub": "com.amazonaws.${AWS::Region}.cloudformation" + }, + "VpcEndpointType": "Interface", + "PrivateDnsEnabled": true, + "SubnetIds": [ + { + "Ref": "PrivateSubnet1" + }, + { + "Ref": "PrivateSubnet2" + } + ], + "SecurityGroupIds": [ + { + "Ref": "EndpointSG" + } + ] + } + }, + "PublicSubnet1": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "VpcId": { + "Ref": "VPC" + }, + "AvailabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": null + } + ] + }, + "CidrBlock": { + "Ref": "PublicSubnet1CIDR" + }, + "MapPublicIpOnLaunch": true, + "Tags": [ + { + "Key": "Name", + "Value": { + "Fn::Sub": "${EnvironmentName} Public Subnet (AZ1)" + } + } + ] + } + }, + "PublicSubnet2": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "VpcId": { + "Ref": "VPC" + }, + "AvailabilityZone": { + "Fn::Select": [ + 1, + { + "Fn::GetAZs": null + } + ] + }, + "CidrBlock": { + "Ref": "PublicSubnet2CIDR" + }, + "MapPublicIpOnLaunch": true, + "Tags": [ + { + "Key": "Name", + "Value": { + "Fn::Sub": "${EnvironmentName} Public Subnet (AZ2)" + } + } + ] + } + }, + "PrivateSubnet1": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "VpcId": { + "Ref": "VPC" + }, + "AvailabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": null + } + ] + }, + "CidrBlock": { + "Ref": "PrivateSubnet1CIDR" + }, + "MapPublicIpOnLaunch": false, + "Tags": [ + { + "Key": "Name", + "Value": { + "Fn::Sub": "${EnvironmentName} Private Subnet (AZ1)" + } + } + ] + } + }, + "PrivateSubnet2": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "VpcId": { + "Ref": "VPC" + }, + "AvailabilityZone": { + "Fn::Select": [ + 1, + { + "Fn::GetAZs": null + } + ] + }, + "CidrBlock": { + "Ref": "PrivateSubnet2CIDR" + }, + "MapPublicIpOnLaunch": false, + "Tags": [ + { + "Key": "Name", + "Value": { + "Fn::Sub": "${EnvironmentName} Private Subnet (AZ2)" + } + } + ] + } + }, + "PublicRouteTable": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "VPC" + }, + "Tags": [ + { + "Key": "Name", + "Value": { + "Fn::Sub": "${EnvironmentName} Public Routes" + } + } + ] + } + }, + "DefaultPublicRoute": { + "Type": "AWS::EC2::Route", + "DependsOn": "InternetGatewayAttachment", + "Properties": { + "RouteTableId": { + "Ref": "PublicRouteTable" + }, + "DestinationCidrBlock": "0.0.0.0/0", + "GatewayId": { + "Ref": "InternetGateway" + } + } + }, + "PublicSubnet1RouteTableAssociation": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "PublicRouteTable" + }, + "SubnetId": { + "Ref": "PublicSubnet1" + } + } + }, + "PublicSubnet2RouteTableAssociation": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "PublicRouteTable" + }, + "SubnetId": { + "Ref": "PublicSubnet2" + } + } + }, + "PrivateRouteTable1": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "VPC" + }, + "Tags": [ + { + "Key": "Name", + "Value": { + "Fn::Sub": "${EnvironmentName} Private Routes (AZ1)" + } + } + ] + } + }, + "PrivateSubnet1RouteTableAssociation": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "PrivateRouteTable1" + }, + "SubnetId": { + "Ref": "PrivateSubnet1" + } + } + }, + "PrivateRouteTable2": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "VPC" + }, + "Tags": [ + { + "Key": "Name", + "Value": { + "Fn::Sub": "${EnvironmentName} Private Routes (AZ2)" + } + } + ] + } + }, + "PrivateSubnet2RouteTableAssociation": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "PrivateRouteTable2" + }, + "SubnetId": { + "Ref": "PrivateSubnet2" + } + } + }, + "RootRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Principal": { + "Service": [ + "ec2.amazonaws.com" + ] + }, + "Action": [ + "sts:AssumeRole" + ] + } + ] + }, + "Path": "/", + "Policies": [ + { + "PolicyName": "root", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": "cloudformation:*", + "Resource": "*" + } + ] + } + } + ] + } + }, + "BastionInstance": { + "Type": "AWS::EC2::Instance", + "Properties": { + "KeyName": { + "Ref": "KeyName" + }, + "InstanceType": "t2.micro", + "SecurityGroupIds": [ + { + "Ref": "BastionSG" + } + ], + "SubnetId": { + "Ref": "PublicSubnet1" + }, + "ImageId": { + "Ref": "LinuxAMI" + }, + "IamInstanceProfile": { + "Ref": "BastionProfile" + }, + "Tags": [ + { + "Key": "Name", + "Value": "Bastion" + } + ] + } + }, + "BastionSG": { + "Type": "AWS::EC2::SecurityGroup", + "Metadata": { + "guard": { + "SuppressedRules": [ + "INCOMING_SSH_DISABLED" + ] + } + }, + "Properties": { + "GroupDescription": "Inbound Bastion Traffic", + "SecurityGroupIngress": [ + { + "IpProtocol": "tcp", + "FromPort": 22, + "ToPort": 22, + "CidrIp": "0.0.0.0/0" + } + ], + "VpcId": { + "Ref": "VPC" + }, + "Tags": [ + { + "Key": "Name", + "Value": "BastionSG" + } + ] + } + }, + "BastionProfile": { + "Type": "AWS::IAM::InstanceProfile", + "Properties": { + "Path": "/", + "Roles": [ + { + "Ref": "RootRole" + } + ] + } + }, + "PrivateInstance": { + "CreationPolicy": { + "ResourceSignal": { + "Count": 1, + "Timeout": "PT15M" + } + }, + "Type": "AWS::EC2::Instance", + "DependsOn": "CfnEndpoint", + "Properties": { + "KeyName": { + "Ref": "KeyName" + }, + "InstanceType": "t2.micro", + "SecurityGroupIds": [ + { + "Ref": "PrivateSG" + } + ], + "SubnetId": { + "Ref": "PrivateSubnet1" + }, + "ImageId": { + "Ref": "LinuxAMI" + }, + "IamInstanceProfile": { + "Ref": "PrivateProfile" + }, + "UserData": { + "Fn::Base64": { + "Fn::Sub": "#!/bin/bash -x\ndate > /tmp/datefile\ncat /tmp/datefile\n# Signal the status from instance\n/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource PrivateInstance --region ${AWS::Region}\n" + } + }, + "Tags": [ + { + "Key": "Name", + "Value": "Private" + } + ] + } + }, + "PrivateSG": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "Traffic from Bastion", + "SecurityGroupIngress": [ + { + "IpProtocol": "tcp", + "FromPort": 22, + "ToPort": 22, + "SourceSecurityGroupId": { + "Ref": "BastionSG" + } + } + ], + "VpcId": { + "Ref": "VPC" + }, + "Tags": [ + { + "Key": "Name", + "Value": "PrivateSG" + } + ] + } + }, + "PrivateProfile": { + "Type": "AWS::IAM::InstanceProfile", + "Properties": { + "Path": "/", + "Roles": [ + { + "Ref": "RootRole" + } + ] + } + }, + "EndpointSG": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "Traffic into CloudFormation Endpoint", + "SecurityGroupIngress": [ + { + "IpProtocol": "tcp", + "FromPort": 443, + "ToPort": 443, + "CidrIp": "0.0.0.0/0" + } + ], + "VpcId": { + "Ref": "VPC" + }, + "Tags": [ + { + "Key": "Name", + "Value": "EndpointSG" + } + ] + } + } + }, + "Outputs": { + "VPC": { + "Description": "A reference to the created VPC", + "Value": { + "Ref": "VPC" + } + }, + "PublicSubnets": { + "Description": "A list of the public subnets", + "Value": { + "Fn::Join": [ + ",", + [ + { + "Ref": "PublicSubnet1" + }, + { + "Ref": "PublicSubnet2" + } + ] + ] + } + }, + "PrivateSubnets": { + "Description": "A list of the private subnets", + "Value": { + "Fn::Join": [ + ",", + [ + { + "Ref": "PrivateSubnet1" + }, + { + "Ref": "PrivateSubnet2" + } + ] + ] + } + }, + "CfnEndpoint": { + "Description": "A reference to the CloudFormation Endpoint used for signaling from the private instance", + "Value": { + "Ref": "CfnEndpoint" + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFormationEndpointSignals/cfn-endpoint-creationpolicy.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFormationEndpointSignals/cfn-endpoint-creationpolicy.yaml new file mode 100644 index 0000000000000000000000000000000000000000..5b315d67fdd4802783abdd12166f2be307047f4a --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFormationEndpointSignals/cfn-endpoint-creationpolicy.yaml @@ -0,0 +1,340 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: | + This template deploys a VPC with a pair of public and private subnets spread across two Availabilty Zones. It deploys an Internet Gateway, with a default route on the public subnets and a bastion server. It deploys a VPC Endpoint for CloudFormation so an instance in the private subnet can use cfn-signal for its CreationPolicy. **WARNING** You will be billed for the AWS resources used if you create a stack from this template. + +Parameters: + EnvironmentName: + Description: An environment name that will be prefixed to resource names + Type: String + + VpcCIDR: + Description: Please enter the IP range (CIDR notation) for this VPC + Type: String + Default: 10.192.0.0/16 + AllowedPattern: ((\d{1,3})\.){3}\d{1,3}/\d{1,2} + + PublicSubnet1CIDR: + Description: Please enter the IP range (CIDR notation) for the public subnet in the first Availability Zone + Type: String + Default: 10.192.10.0/24 + AllowedPattern: ((\d{1,3})\.){3}\d{1,3}/\d{1,2} + + PublicSubnet2CIDR: + Description: Please enter the IP range (CIDR notation) for the public subnet in the second Availability Zone + Type: String + Default: 10.192.11.0/24 + AllowedPattern: ((\d{1,3})\.){3}\d{1,3}/\d{1,2} + + PrivateSubnet1CIDR: + Description: Please enter the IP range (CIDR notation) for the private subnet in the first Availability Zone + Type: String + Default: 10.192.20.0/24 + AllowedPattern: ((\d{1,3})\.){3}\d{1,3}/\d{1,2} + + PrivateSubnet2CIDR: + Description: Please enter the IP range (CIDR notation) for the private subnet in the second Availability Zone + Type: String + Default: 10.192.21.0/24 + AllowedPattern: ((\d{1,3})\.){3}\d{1,3}/\d{1,2} + + KeyName: + Description: Key pair for EC2 access + Type: AWS::EC2::KeyPair::KeyName + + LinuxAMI: + Description: Managed AMI ID for Amazon Linux + Type: AWS::SSM::Parameter::Value + Default: /aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2 + +Resources: + VPC: + Type: AWS::EC2::VPC + Properties: + EnableDnsSupport: true + EnableDnsHostnames: true + CidrBlock: !Ref VpcCIDR + Tags: + - Key: Name + Value: !Ref EnvironmentName + + InternetGateway: + Type: AWS::EC2::InternetGateway + Properties: + Tags: + - Key: Name + Value: !Ref EnvironmentName + + InternetGatewayAttachment: + Type: AWS::EC2::VPCGatewayAttachment + Properties: + InternetGatewayId: !Ref InternetGateway + VpcId: !Ref VPC + + # This is the interface endpoint for CloudFormation. You can only deploy this + # once per region since it will consume the unique DNS entry for the endpoint. + CfnEndpoint: + Type: AWS::EC2::VPCEndpoint + Properties: + VpcId: !Ref VPC + ServiceName: !Sub com.amazonaws.${AWS::Region}.cloudformation + VpcEndpointType: Interface + PrivateDnsEnabled: true + SubnetIds: + - !Ref PrivateSubnet1 + - !Ref PrivateSubnet2 + SecurityGroupIds: + - !Ref EndpointSG + + PublicSubnet1: + Type: AWS::EC2::Subnet + Properties: + VpcId: !Ref VPC + AvailabilityZone: !Select + - 0 + - !GetAZs + CidrBlock: !Ref PublicSubnet1CIDR + MapPublicIpOnLaunch: true + Tags: + - Key: Name + Value: !Sub ${EnvironmentName} Public Subnet (AZ1) + + PublicSubnet2: + Type: AWS::EC2::Subnet + Properties: + VpcId: !Ref VPC + AvailabilityZone: !Select + - 1 + - !GetAZs + CidrBlock: !Ref PublicSubnet2CIDR + MapPublicIpOnLaunch: true + Tags: + - Key: Name + Value: !Sub ${EnvironmentName} Public Subnet (AZ2) + + PrivateSubnet1: + Type: AWS::EC2::Subnet + Properties: + VpcId: !Ref VPC + AvailabilityZone: !Select + - 0 + - !GetAZs + CidrBlock: !Ref PrivateSubnet1CIDR + MapPublicIpOnLaunch: false + Tags: + - Key: Name + Value: !Sub ${EnvironmentName} Private Subnet (AZ1) + + PrivateSubnet2: + Type: AWS::EC2::Subnet + Properties: + VpcId: !Ref VPC + AvailabilityZone: !Select + - 1 + - !GetAZs + CidrBlock: !Ref PrivateSubnet2CIDR + MapPublicIpOnLaunch: false + Tags: + - Key: Name + Value: !Sub ${EnvironmentName} Private Subnet (AZ2) + + PublicRouteTable: + Type: AWS::EC2::RouteTable + Properties: + VpcId: !Ref VPC + Tags: + - Key: Name + Value: !Sub ${EnvironmentName} Public Routes + + DefaultPublicRoute: + Type: AWS::EC2::Route + DependsOn: InternetGatewayAttachment + Properties: + RouteTableId: !Ref PublicRouteTable + DestinationCidrBlock: 0.0.0.0/0 + GatewayId: !Ref InternetGateway + + PublicSubnet1RouteTableAssociation: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + RouteTableId: !Ref PublicRouteTable + SubnetId: !Ref PublicSubnet1 + + PublicSubnet2RouteTableAssociation: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + RouteTableId: !Ref PublicRouteTable + SubnetId: !Ref PublicSubnet2 + + PrivateRouteTable1: + Type: AWS::EC2::RouteTable + Properties: + VpcId: !Ref VPC + Tags: + - Key: Name + Value: !Sub ${EnvironmentName} Private Routes (AZ1) + + PrivateSubnet1RouteTableAssociation: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + RouteTableId: !Ref PrivateRouteTable1 + SubnetId: !Ref PrivateSubnet1 + + PrivateRouteTable2: + Type: AWS::EC2::RouteTable + Properties: + VpcId: !Ref VPC + Tags: + - Key: Name + Value: !Sub ${EnvironmentName} Private Routes (AZ2) + + PrivateSubnet2RouteTableAssociation: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + RouteTableId: !Ref PrivateRouteTable2 + SubnetId: !Ref PrivateSubnet2 + + RootRole: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Principal: + Service: + - ec2.amazonaws.com + Action: + - sts:AssumeRole + Path: / + Policies: + - PolicyName: root + PolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: cloudformation:* + Resource: '*' + + BastionInstance: + Type: AWS::EC2::Instance + Properties: + KeyName: !Ref KeyName + InstanceType: t2.micro + SecurityGroupIds: + - !Ref BastionSG + SubnetId: !Ref PublicSubnet1 + ImageId: !Ref LinuxAMI + IamInstanceProfile: !Ref BastionProfile + Tags: + - Key: Name + Value: Bastion + + BastionSG: + Type: AWS::EC2::SecurityGroup + Metadata: + guard: + SuppressedRules: + - INCOMING_SSH_DISABLED + Properties: + GroupDescription: Inbound Bastion Traffic + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: 22 + ToPort: 22 + CidrIp: 0.0.0.0/0 + VpcId: !Ref VPC + Tags: + - Key: Name + Value: BastionSG + + BastionProfile: + Type: AWS::IAM::InstanceProfile + Properties: + Path: / + Roles: + - !Ref RootRole + + PrivateInstance: + CreationPolicy: + ResourceSignal: + Count: 1 + Timeout: PT15M + Type: AWS::EC2::Instance + DependsOn: CfnEndpoint + Properties: + KeyName: !Ref KeyName + InstanceType: t2.micro + SecurityGroupIds: + - !Ref PrivateSG + SubnetId: !Ref PrivateSubnet1 + ImageId: !Ref LinuxAMI + IamInstanceProfile: !Ref PrivateProfile + UserData: !Base64 + Fn::Sub: | + #!/bin/bash -x + date > /tmp/datefile + cat /tmp/datefile + # Signal the status from instance + /opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource PrivateInstance --region ${AWS::Region} + Tags: + - Key: Name + Value: Private + + PrivateSG: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Traffic from Bastion + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: 22 + ToPort: 22 + SourceSecurityGroupId: !Ref BastionSG + VpcId: !Ref VPC + Tags: + - Key: Name + Value: PrivateSG + + PrivateProfile: + Type: AWS::IAM::InstanceProfile + Properties: + Path: / + Roles: + - !Ref RootRole + + EndpointSG: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Traffic into CloudFormation Endpoint + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: 443 + ToPort: 443 + CidrIp: 0.0.0.0/0 + VpcId: !Ref VPC + Tags: + - Key: Name + Value: EndpointSG + +Outputs: + VPC: + Description: A reference to the created VPC + Value: !Ref VPC + + PublicSubnets: + Description: A list of the public subnets + Value: !Join + - ',' + - - !Ref PublicSubnet1 + - !Ref PublicSubnet2 + + PrivateSubnets: + Description: A list of the private subnets + Value: !Join + - ',' + - - !Ref PrivateSubnet1 + - !Ref PrivateSubnet2 + + CfnEndpoint: + Description: A reference to the CloudFormation Endpoint used for signaling from the private instance + Value: !Ref CfnEndpoint diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFormationEndpointSignals/cfn-endpoint-waitcondition-no-igw.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFormationEndpointSignals/cfn-endpoint-waitcondition-no-igw.json new file mode 100644 index 0000000000000000000000000000000000000000..6e5a30739418f2c91bbf418f368d1bf233acc4fa --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFormationEndpointSignals/cfn-endpoint-waitcondition-no-igw.json @@ -0,0 +1,360 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "This template deploys a VPC with a pair of private subnets spread across two Availabilty Zones. It deploys VPC Endpoints for CloudFormation and S3 so an instance in the private subnet can use cfn-signal for a WaitCondition. **WARNING** You will be billed for the AWS resources used if you create a stack from this template.\n", + "Parameters": { + "EnvironmentName": { + "Description": "An environment name that will be prefixed to resource names", + "Type": "String" + }, + "VpcCIDR": { + "Description": "Please enter the IP range (CIDR notation) for this VPC", + "Type": "String", + "Default": "10.192.0.0/16", + "AllowedPattern": "((\\d{1,3})\\.){3}\\d{1,3}/\\d{1,2}" + }, + "PrivateSubnet1CIDR": { + "Description": "Please enter the IP range (CIDR notation) for the private subnet in the first Availability Zone", + "Type": "String", + "Default": "10.192.20.0/24", + "AllowedPattern": "((\\d{1,3})\\.){3}\\d{1,3}/\\d{1,2}" + }, + "PrivateSubnet2CIDR": { + "Description": "Please enter the IP range (CIDR notation) for the private subnet in the second Availability Zone", + "Type": "String", + "Default": "10.192.21.0/24", + "AllowedPattern": "((\\d{1,3})\\.){3}\\d{1,3}/\\d{1,2}" + }, + "LinuxAMI": { + "Description": "Managed AMI ID for Amazon Linux", + "Type": "AWS::SSM::Parameter::Value", + "Default": "/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2" + } + }, + "Resources": { + "VPC": { + "Type": "AWS::EC2::VPC", + "Properties": { + "EnableDnsSupport": true, + "EnableDnsHostnames": true, + "CidrBlock": { + "Ref": "VpcCIDR" + }, + "Tags": [ + { + "Key": "Name", + "Value": { + "Ref": "EnvironmentName" + } + } + ] + } + }, + "CfnEndpoint": { + "Type": "AWS::EC2::VPCEndpoint", + "Properties": { + "VpcId": { + "Ref": "VPC" + }, + "ServiceName": { + "Fn::Sub": "com.amazonaws.${AWS::Region}.cloudformation" + }, + "VpcEndpointType": "Interface", + "PrivateDnsEnabled": true, + "SubnetIds": [ + { + "Ref": "PrivateSubnet1" + }, + { + "Ref": "PrivateSubnet2" + } + ], + "SecurityGroupIds": [ + { + "Ref": "EndpointSG" + } + ] + } + }, + "S3Endpoint": { + "Type": "AWS::EC2::VPCEndpoint", + "Properties": { + "VpcId": { + "Ref": "VPC" + }, + "ServiceName": { + "Fn::Sub": "com.amazonaws.${AWS::Region}.s3" + }, + "VpcEndpointType": "Gateway", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Principal": "*", + "Action": [ + "s3:PutObject" + ], + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::cloudformation-waitcondition-${AWS::Region}/*" + } + ] + } + ] + }, + "RouteTableIds": [ + { + "Ref": "PrivateRouteTable1" + }, + { + "Ref": "PrivateRouteTable2" + } + ] + } + }, + "PrivateSubnet1": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "VpcId": { + "Ref": "VPC" + }, + "AvailabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": null + } + ] + }, + "CidrBlock": { + "Ref": "PrivateSubnet1CIDR" + }, + "MapPublicIpOnLaunch": false, + "Tags": [ + { + "Key": "Name", + "Value": { + "Fn::Sub": "${EnvironmentName} Private Subnet (AZ1)" + } + } + ] + } + }, + "PrivateSubnet2": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "VpcId": { + "Ref": "VPC" + }, + "AvailabilityZone": { + "Fn::Select": [ + 1, + { + "Fn::GetAZs": null + } + ] + }, + "CidrBlock": { + "Ref": "PrivateSubnet2CIDR" + }, + "MapPublicIpOnLaunch": false, + "Tags": [ + { + "Key": "Name", + "Value": { + "Fn::Sub": "${EnvironmentName} Private Subnet (AZ2)" + } + } + ] + } + }, + "PrivateRouteTable1": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "VPC" + }, + "Tags": [ + { + "Key": "Name", + "Value": { + "Fn::Sub": "${EnvironmentName} Private Routes (AZ1)" + } + } + ] + } + }, + "PrivateSubnet1RouteTableAssociation": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "PrivateRouteTable1" + }, + "SubnetId": { + "Ref": "PrivateSubnet1" + } + } + }, + "PrivateRouteTable2": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "VPC" + }, + "Tags": [ + { + "Key": "Name", + "Value": { + "Fn::Sub": "${EnvironmentName} Private Routes (AZ2)" + } + } + ] + } + }, + "PrivateSubnet2RouteTableAssociation": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "PrivateRouteTable2" + }, + "SubnetId": { + "Ref": "PrivateSubnet2" + } + } + }, + "PrivateInstance": { + "Type": "AWS::EC2::Instance", + "DependsOn": "CfnEndpoint", + "Properties": { + "InstanceType": "t3.micro", + "SecurityGroupIds": [ + { + "Ref": "PrivateSG" + } + ], + "SubnetId": { + "Ref": "PrivateSubnet1" + }, + "ImageId": { + "Ref": "LinuxAMI" + }, + "UserData": { + "Fn::Base64": { + "Fn::Sub": "#!/bin/bash -x\ndate > /tmp/datefile\ncat /tmp/datefile\n# Signal the status from instance\n/opt/aws/bin/cfn-signal -e $? -d \"This was all private.\" -r \"Build Process Complete\" '${PrivateWaitHandle}'\n" + } + }, + "Tags": [ + { + "Key": "Name", + "Value": "Private" + } + ] + } + }, + "PrivateSG": { + "Type": "AWS::EC2::SecurityGroup", + "Metadata": { + "guard": { + "SuppressedRules": [ + "INCOMING_SSH_DISABLED" + ] + } + }, + "Properties": { + "GroupDescription": "Traffic from Bastion", + "SecurityGroupIngress": [ + { + "IpProtocol": "tcp", + "FromPort": 22, + "ToPort": 22, + "CidrIp": { + "Ref": "VpcCIDR" + } + } + ], + "VpcId": { + "Ref": "VPC" + }, + "Tags": [ + { + "Key": "Name", + "Value": "PrivateSG" + } + ] + } + }, + "EndpointSG": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "Traffic into CloudFormation Endpoint", + "SecurityGroupIngress": [ + { + "IpProtocol": "tcp", + "FromPort": 443, + "ToPort": 443, + "CidrIp": "0.0.0.0/0" + } + ], + "VpcId": { + "Ref": "VPC" + }, + "Tags": [ + { + "Key": "Name", + "Value": "EndpointSG" + } + ] + } + }, + "PrivateWaitHandle": { + "Type": "AWS::CloudFormation::WaitConditionHandle" + }, + "PrivateWaitCondition": { + "Type": "AWS::CloudFormation::WaitCondition", + "DependsOn": "PrivateInstance", + "Properties": { + "Handle": { + "Ref": "PrivateWaitHandle" + }, + "Timeout": "3600", + "Count": 1 + } + } + }, + "Outputs": { + "VPC": { + "Description": "A reference to the created VPC", + "Value": { + "Ref": "VPC" + } + }, + "PrivateSubnets": { + "Description": "A list of the private subnets", + "Value": { + "Fn::Join": [ + ",", + [ + { + "Ref": "PrivateSubnet1" + }, + { + "Ref": "PrivateSubnet2" + } + ] + ] + } + }, + "CfnEndpoint": { + "Description": "A reference to the CloudFormation Endpoint used for signaling from the private instance", + "Value": { + "Ref": "CfnEndpoint" + } + }, + "S3Endpoint": { + "Description": "A reference to the S3 Endpoint used for signaling from the private instance", + "Value": { + "Ref": "S3Endpoint" + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFormationEndpointSignals/cfn-endpoint-waitcondition-no-igw.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFormationEndpointSignals/cfn-endpoint-waitcondition-no-igw.yaml new file mode 100644 index 0000000000000000000000000000000000000000..249b9bb4fc72b08f0cda21eb7525cf1c9439adbc --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFormationEndpointSignals/cfn-endpoint-waitcondition-no-igw.yaml @@ -0,0 +1,217 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: | + This template deploys a VPC with a pair of private subnets spread across two Availabilty Zones. It deploys VPC Endpoints for CloudFormation and S3 so an instance in the private subnet can use cfn-signal for a WaitCondition. **WARNING** You will be billed for the AWS resources used if you create a stack from this template. + +Parameters: + EnvironmentName: + Description: An environment name that will be prefixed to resource names + Type: String + + VpcCIDR: + Description: Please enter the IP range (CIDR notation) for this VPC + Type: String + Default: 10.192.0.0/16 + AllowedPattern: ((\d{1,3})\.){3}\d{1,3}/\d{1,2} + + PrivateSubnet1CIDR: + Description: Please enter the IP range (CIDR notation) for the private subnet in the first Availability Zone + Type: String + Default: 10.192.20.0/24 + AllowedPattern: ((\d{1,3})\.){3}\d{1,3}/\d{1,2} + + PrivateSubnet2CIDR: + Description: Please enter the IP range (CIDR notation) for the private subnet in the second Availability Zone + Type: String + Default: 10.192.21.0/24 + AllowedPattern: ((\d{1,3})\.){3}\d{1,3}/\d{1,2} + + LinuxAMI: + Description: Managed AMI ID for Amazon Linux + Type: AWS::SSM::Parameter::Value + Default: /aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2 + +Resources: + VPC: + Type: AWS::EC2::VPC + Properties: + EnableDnsSupport: true + EnableDnsHostnames: true + CidrBlock: !Ref VpcCIDR + Tags: + - Key: Name + Value: !Ref EnvironmentName + + # This is the interface endpoint for CloudFormation. You can only deploy this + # once per region since it will consume the unique DNS entry for the endpoint. + CfnEndpoint: + Type: AWS::EC2::VPCEndpoint + Properties: + VpcId: !Ref VPC + ServiceName: !Sub com.amazonaws.${AWS::Region}.cloudformation + VpcEndpointType: Interface + PrivateDnsEnabled: true + SubnetIds: + - !Ref PrivateSubnet1 + - !Ref PrivateSubnet2 + SecurityGroupIds: + - !Ref EndpointSG + + # This is the gateway endpoint for S3. WaitConditions and CustomResources + # need to access self-signed URLs in the following buckets to signal back + # to the stack. + S3Endpoint: + Type: AWS::EC2::VPCEndpoint + Properties: + VpcId: !Ref VPC + ServiceName: !Sub com.amazonaws.${AWS::Region}.s3 + VpcEndpointType: Gateway + PolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Principal: '*' + Action: + - s3:PutObject + Resource: + - !Sub arn:${AWS::Partition}:s3:::cloudformation-waitcondition-${AWS::Region}/* + RouteTableIds: + - !Ref PrivateRouteTable1 + - !Ref PrivateRouteTable2 + + PrivateSubnet1: + Type: AWS::EC2::Subnet + Properties: + VpcId: !Ref VPC + AvailabilityZone: !Select + - 0 + - !GetAZs + CidrBlock: !Ref PrivateSubnet1CIDR + MapPublicIpOnLaunch: false + Tags: + - Key: Name + Value: !Sub ${EnvironmentName} Private Subnet (AZ1) + + PrivateSubnet2: + Type: AWS::EC2::Subnet + Properties: + VpcId: !Ref VPC + AvailabilityZone: !Select + - 1 + - !GetAZs + CidrBlock: !Ref PrivateSubnet2CIDR + MapPublicIpOnLaunch: false + Tags: + - Key: Name + Value: !Sub ${EnvironmentName} Private Subnet (AZ2) + + PrivateRouteTable1: + Type: AWS::EC2::RouteTable + Properties: + VpcId: !Ref VPC + Tags: + - Key: Name + Value: !Sub ${EnvironmentName} Private Routes (AZ1) + + PrivateSubnet1RouteTableAssociation: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + RouteTableId: !Ref PrivateRouteTable1 + SubnetId: !Ref PrivateSubnet1 + + PrivateRouteTable2: + Type: AWS::EC2::RouteTable + Properties: + VpcId: !Ref VPC + Tags: + - Key: Name + Value: !Sub ${EnvironmentName} Private Routes (AZ2) + + PrivateSubnet2RouteTableAssociation: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + RouteTableId: !Ref PrivateRouteTable2 + SubnetId: !Ref PrivateSubnet2 + + PrivateInstance: + Type: AWS::EC2::Instance + DependsOn: CfnEndpoint + Properties: + InstanceType: t3.micro + SecurityGroupIds: + - !Ref PrivateSG + SubnetId: !Ref PrivateSubnet1 + ImageId: !Ref LinuxAMI + UserData: !Base64 + Fn::Sub: | + #!/bin/bash -x + date > /tmp/datefile + cat /tmp/datefile + # Signal the status from instance + /opt/aws/bin/cfn-signal -e $? -d "This was all private." -r "Build Process Complete" '${PrivateWaitHandle}' + Tags: + - Key: Name + Value: Private + + PrivateSG: + Type: AWS::EC2::SecurityGroup + Metadata: + guard: + SuppressedRules: + - INCOMING_SSH_DISABLED + Properties: + GroupDescription: Traffic from Bastion + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: 22 + ToPort: 22 + CidrIp: !Ref VpcCIDR + VpcId: !Ref VPC + Tags: + - Key: Name + Value: PrivateSG + + EndpointSG: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Traffic into CloudFormation Endpoint + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: 443 + ToPort: 443 + CidrIp: 0.0.0.0/0 + VpcId: !Ref VPC + Tags: + - Key: Name + Value: EndpointSG + + PrivateWaitHandle: + Type: AWS::CloudFormation::WaitConditionHandle + + PrivateWaitCondition: + Type: AWS::CloudFormation::WaitCondition + DependsOn: PrivateInstance + Properties: + Handle: !Ref PrivateWaitHandle + Timeout: "3600" + Count: 1 + +Outputs: + VPC: + Description: A reference to the created VPC + Value: !Ref VPC + + PrivateSubnets: + Description: A list of the private subnets + Value: !Join + - ',' + - - !Ref PrivateSubnet1 + - !Ref PrivateSubnet2 + + CfnEndpoint: + Description: A reference to the CloudFormation Endpoint used for signaling from the private instance + Value: !Ref CfnEndpoint + + S3Endpoint: + Description: A reference to the S3 Endpoint used for signaling from the private instance + Value: !Ref S3Endpoint diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFormationEndpointSignals/cfn-endpoint-waitcondition.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFormationEndpointSignals/cfn-endpoint-waitcondition.json new file mode 100644 index 0000000000000000000000000000000000000000..a43d7e33f7f6298e1f00c7397f81fe02f7a692be --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFormationEndpointSignals/cfn-endpoint-waitcondition.json @@ -0,0 +1,640 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "This template deploys a VPC with a pair of public and private subnets spread across two Availabilty Zones. It deploys an Internet Gateway, with a default route on the public subnets and a bastion server. It deploys VPC Endpoints for CloudFormation and S3 so an instance in the private subnet can use cfn-signal for a WaitCondition. **WARNING** You will be billed for the AWS resources used if you create a stack from this template.\n", + "Parameters": { + "EnvironmentName": { + "Description": "An environment name that will be prefixed to resource names", + "Type": "String" + }, + "VpcCIDR": { + "Description": "Please enter the IP range (CIDR notation) for this VPC", + "Type": "String", + "Default": "10.192.0.0/16", + "AllowedPattern": "((\\d{1,3})\\.){3}\\d{1,3}/\\d{1,2}" + }, + "PublicSubnet1CIDR": { + "Description": "Please enter the IP range (CIDR notation) for the public subnet in the first Availability Zone", + "Type": "String", + "Default": "10.192.10.0/24", + "AllowedPattern": "((\\d{1,3})\\.){3}\\d{1,3}/\\d{1,2}" + }, + "PublicSubnet2CIDR": { + "Description": "Please enter the IP range (CIDR notation) for the public subnet in the second Availability Zone", + "Type": "String", + "Default": "10.192.11.0/24", + "AllowedPattern": "((\\d{1,3})\\.){3}\\d{1,3}/\\d{1,2}" + }, + "PrivateSubnet1CIDR": { + "Description": "Please enter the IP range (CIDR notation) for the private subnet in the first Availability Zone", + "Type": "String", + "Default": "10.192.20.0/24", + "AllowedPattern": "((\\d{1,3})\\.){3}\\d{1,3}/\\d{1,2}" + }, + "PrivateSubnet2CIDR": { + "Description": "Please enter the IP range (CIDR notation) for the private subnet in the second Availability Zone", + "Type": "String", + "Default": "10.192.21.0/24", + "AllowedPattern": "((\\d{1,3})\\.){3}\\d{1,3}/\\d{1,2}" + }, + "KeyName": { + "Description": "Key pair for EC2 access", + "Type": "AWS::EC2::KeyPair::KeyName" + }, + "LinuxAMI": { + "Description": "Managed AMI ID for Amazon Linux", + "Type": "AWS::SSM::Parameter::Value", + "Default": "/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2" + } + }, + "Resources": { + "VPC": { + "Type": "AWS::EC2::VPC", + "Properties": { + "EnableDnsSupport": true, + "EnableDnsHostnames": true, + "CidrBlock": { + "Ref": "VpcCIDR" + }, + "Tags": [ + { + "Key": "Name", + "Value": { + "Ref": "EnvironmentName" + } + } + ] + } + }, + "InternetGateway": { + "Type": "AWS::EC2::InternetGateway", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": { + "Ref": "EnvironmentName" + } + } + ] + } + }, + "InternetGatewayAttachment": { + "Type": "AWS::EC2::VPCGatewayAttachment", + "Properties": { + "InternetGatewayId": { + "Ref": "InternetGateway" + }, + "VpcId": { + "Ref": "VPC" + } + } + }, + "CfnEndpoint": { + "Type": "AWS::EC2::VPCEndpoint", + "Properties": { + "VpcId": { + "Ref": "VPC" + }, + "ServiceName": { + "Fn::Sub": "com.amazonaws.${AWS::Region}.cloudformation" + }, + "VpcEndpointType": "Interface", + "PrivateDnsEnabled": true, + "SubnetIds": [ + { + "Ref": "PrivateSubnet1" + }, + { + "Ref": "PrivateSubnet2" + } + ], + "SecurityGroupIds": [ + { + "Ref": "EndpointSG" + } + ] + } + }, + "S3Endpoint": { + "Type": "AWS::EC2::VPCEndpoint", + "Properties": { + "VpcId": { + "Ref": "VPC" + }, + "ServiceName": { + "Fn::Sub": "com.amazonaws.${AWS::Region}.s3" + }, + "VpcEndpointType": "Gateway", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Principal": "*", + "Action": [ + "s3:PutObject" + ], + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::cloudformation-waitcondition-${AWS::Region}/*" + } + ] + } + ] + }, + "RouteTableIds": [ + { + "Ref": "PrivateRouteTable1" + }, + { + "Ref": "PrivateRouteTable2" + } + ] + } + }, + "PublicSubnet1": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "VpcId": { + "Ref": "VPC" + }, + "AvailabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": null + } + ] + }, + "CidrBlock": { + "Ref": "PublicSubnet1CIDR" + }, + "MapPublicIpOnLaunch": true, + "Tags": [ + { + "Key": "Name", + "Value": { + "Fn::Sub": "${EnvironmentName} Public Subnet (AZ1)" + } + } + ] + } + }, + "PublicSubnet2": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "VpcId": { + "Ref": "VPC" + }, + "AvailabilityZone": { + "Fn::Select": [ + 1, + { + "Fn::GetAZs": null + } + ] + }, + "CidrBlock": { + "Ref": "PublicSubnet2CIDR" + }, + "MapPublicIpOnLaunch": true, + "Tags": [ + { + "Key": "Name", + "Value": { + "Fn::Sub": "${EnvironmentName} Public Subnet (AZ2)" + } + } + ] + } + }, + "PrivateSubnet1": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "VpcId": { + "Ref": "VPC" + }, + "AvailabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": null + } + ] + }, + "CidrBlock": { + "Ref": "PrivateSubnet1CIDR" + }, + "MapPublicIpOnLaunch": false, + "Tags": [ + { + "Key": "Name", + "Value": { + "Fn::Sub": "${EnvironmentName} Private Subnet (AZ1)" + } + } + ] + } + }, + "PrivateSubnet2": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "VpcId": { + "Ref": "VPC" + }, + "AvailabilityZone": { + "Fn::Select": [ + 1, + { + "Fn::GetAZs": null + } + ] + }, + "CidrBlock": { + "Ref": "PrivateSubnet2CIDR" + }, + "MapPublicIpOnLaunch": false, + "Tags": [ + { + "Key": "Name", + "Value": { + "Fn::Sub": "${EnvironmentName} Private Subnet (AZ2)" + } + } + ] + } + }, + "PublicRouteTable": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "VPC" + }, + "Tags": [ + { + "Key": "Name", + "Value": { + "Fn::Sub": "${EnvironmentName} Public Routes" + } + } + ] + } + }, + "DefaultPublicRoute": { + "Type": "AWS::EC2::Route", + "DependsOn": "InternetGatewayAttachment", + "Properties": { + "RouteTableId": { + "Ref": "PublicRouteTable" + }, + "DestinationCidrBlock": "0.0.0.0/0", + "GatewayId": { + "Ref": "InternetGateway" + } + } + }, + "PublicSubnet1RouteTableAssociation": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "PublicRouteTable" + }, + "SubnetId": { + "Ref": "PublicSubnet1" + } + } + }, + "PublicSubnet2RouteTableAssociation": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "PublicRouteTable" + }, + "SubnetId": { + "Ref": "PublicSubnet2" + } + } + }, + "PrivateRouteTable1": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "VPC" + }, + "Tags": [ + { + "Key": "Name", + "Value": { + "Fn::Sub": "${EnvironmentName} Private Routes (AZ1)" + } + } + ] + } + }, + "PrivateSubnet1RouteTableAssociation": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "PrivateRouteTable1" + }, + "SubnetId": { + "Ref": "PrivateSubnet1" + } + } + }, + "PrivateRouteTable2": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "VPC" + }, + "Tags": [ + { + "Key": "Name", + "Value": { + "Fn::Sub": "${EnvironmentName} Private Routes (AZ2)" + } + } + ] + } + }, + "PrivateSubnet2RouteTableAssociation": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "PrivateRouteTable2" + }, + "SubnetId": { + "Ref": "PrivateSubnet2" + } + } + }, + "RootRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Principal": { + "Service": [ + "ec2.amazonaws.com" + ] + }, + "Action": [ + "sts:AssumeRole" + ] + } + ] + }, + "Path": "/", + "Policies": [ + { + "PolicyName": "root", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": "cloudformation:*", + "Resource": "*" + } + ] + } + } + ] + } + }, + "BastionInstance": { + "Type": "AWS::EC2::Instance", + "Properties": { + "KeyName": { + "Ref": "KeyName" + }, + "InstanceType": "t2.micro", + "SecurityGroupIds": [ + { + "Ref": "BastionSG" + } + ], + "SubnetId": { + "Ref": "PublicSubnet1" + }, + "ImageId": { + "Ref": "LinuxAMI" + }, + "IamInstanceProfile": { + "Ref": "BastionProfile" + }, + "Tags": [ + { + "Key": "Name", + "Value": "Bastion" + } + ] + } + }, + "BastionSG": { + "Type": "AWS::EC2::SecurityGroup", + "Metadata": { + "guard": { + "SuppressedRules": [ + "INCOMING_SSH_DISABLED" + ] + } + }, + "Properties": { + "GroupDescription": "Inbound Bastion Traffic", + "SecurityGroupIngress": [ + { + "IpProtocol": "tcp", + "FromPort": 22, + "ToPort": 22, + "CidrIp": "0.0.0.0/0" + } + ], + "VpcId": { + "Ref": "VPC" + }, + "Tags": [ + { + "Key": "Name", + "Value": "BastionSG" + } + ] + } + }, + "BastionProfile": { + "Type": "AWS::IAM::InstanceProfile", + "Properties": { + "Path": "/", + "Roles": [ + { + "Ref": "RootRole" + } + ] + } + }, + "PrivateInstance": { + "Type": "AWS::EC2::Instance", + "DependsOn": "CfnEndpoint", + "Properties": { + "KeyName": { + "Ref": "KeyName" + }, + "InstanceType": "t2.micro", + "SecurityGroupIds": [ + { + "Ref": "PrivateSG" + } + ], + "SubnetId": { + "Ref": "PrivateSubnet1" + }, + "ImageId": { + "Ref": "LinuxAMI" + }, + "IamInstanceProfile": { + "Ref": "PrivateProfile" + }, + "UserData": { + "Fn::Base64": { + "Fn::Sub": "#!/bin/bash -x\ndate > /tmp/datefile\ncat /tmp/datefile\n# Signal the status from instance\n/opt/aws/bin/cfn-signal -e $? -d \"This was all private.\" -r \"Build Process Complete\" '${PrivateWaitHandle}'\n" + } + }, + "Tags": [ + { + "Key": "Name", + "Value": "Private" + } + ] + } + }, + "PrivateSG": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "Traffic from Bastion", + "SecurityGroupIngress": [ + { + "IpProtocol": "tcp", + "FromPort": 22, + "ToPort": 22, + "SourceSecurityGroupId": { + "Ref": "BastionSG" + } + } + ], + "VpcId": { + "Ref": "VPC" + }, + "Tags": [ + { + "Key": "Name", + "Value": "PrivateSG" + } + ] + } + }, + "PrivateProfile": { + "Type": "AWS::IAM::InstanceProfile", + "Properties": { + "Path": "/", + "Roles": [ + { + "Ref": "RootRole" + } + ] + } + }, + "EndpointSG": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "Traffic into CloudFormation Endpoint", + "SecurityGroupIngress": [ + { + "IpProtocol": "tcp", + "FromPort": 443, + "ToPort": 443, + "CidrIp": "0.0.0.0/0" + } + ], + "VpcId": { + "Ref": "VPC" + }, + "Tags": [ + { + "Key": "Name", + "Value": "EndpointSG" + } + ] + } + }, + "PrivateWaitHandle": { + "Type": "AWS::CloudFormation::WaitConditionHandle" + }, + "PrivateWaitCondition": { + "Type": "AWS::CloudFormation::WaitCondition", + "DependsOn": "PrivateInstance", + "Properties": { + "Handle": { + "Ref": "PrivateWaitHandle" + }, + "Timeout": "3600", + "Count": 1 + } + } + }, + "Outputs": { + "VPC": { + "Description": "A reference to the created VPC", + "Value": { + "Ref": "VPC" + } + }, + "PublicSubnets": { + "Description": "A list of the public subnets", + "Value": { + "Fn::Join": [ + ",", + [ + { + "Ref": "PublicSubnet1" + }, + { + "Ref": "PublicSubnet2" + } + ] + ] + } + }, + "PrivateSubnets": { + "Description": "A list of the private subnets", + "Value": { + "Fn::Join": [ + ",", + [ + { + "Ref": "PrivateSubnet1" + }, + { + "Ref": "PrivateSubnet2" + } + ] + ] + } + }, + "CfnEndpoint": { + "Description": "A reference to the CloudFormation Endpoint used for signaling from the private instance", + "Value": { + "Ref": "CfnEndpoint" + } + }, + "S3Endpoint": { + "Description": "A reference to the S3 Endpoint used for signaling from the private instance", + "Value": { + "Ref": "S3Endpoint" + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFormationEndpointSignals/cfn-endpoint-waitcondition.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFormationEndpointSignals/cfn-endpoint-waitcondition.yaml new file mode 100644 index 0000000000000000000000000000000000000000..fa9cb3ef8aa401de6f4e79a41370c4b6bc41bbb3 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFormationEndpointSignals/cfn-endpoint-waitcondition.yaml @@ -0,0 +1,373 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: | + This template deploys a VPC with a pair of public and private subnets spread across two Availabilty Zones. It deploys an Internet Gateway, with a default route on the public subnets and a bastion server. It deploys VPC Endpoints for CloudFormation and S3 so an instance in the private subnet can use cfn-signal for a WaitCondition. **WARNING** You will be billed for the AWS resources used if you create a stack from this template. + +Parameters: + EnvironmentName: + Description: An environment name that will be prefixed to resource names + Type: String + + VpcCIDR: + Description: Please enter the IP range (CIDR notation) for this VPC + Type: String + Default: 10.192.0.0/16 + AllowedPattern: ((\d{1,3})\.){3}\d{1,3}/\d{1,2} + + PublicSubnet1CIDR: + Description: Please enter the IP range (CIDR notation) for the public subnet in the first Availability Zone + Type: String + Default: 10.192.10.0/24 + AllowedPattern: ((\d{1,3})\.){3}\d{1,3}/\d{1,2} + + PublicSubnet2CIDR: + Description: Please enter the IP range (CIDR notation) for the public subnet in the second Availability Zone + Type: String + Default: 10.192.11.0/24 + AllowedPattern: ((\d{1,3})\.){3}\d{1,3}/\d{1,2} + + PrivateSubnet1CIDR: + Description: Please enter the IP range (CIDR notation) for the private subnet in the first Availability Zone + Type: String + Default: 10.192.20.0/24 + AllowedPattern: ((\d{1,3})\.){3}\d{1,3}/\d{1,2} + + PrivateSubnet2CIDR: + Description: Please enter the IP range (CIDR notation) for the private subnet in the second Availability Zone + Type: String + Default: 10.192.21.0/24 + AllowedPattern: ((\d{1,3})\.){3}\d{1,3}/\d{1,2} + + KeyName: + Description: Key pair for EC2 access + Type: AWS::EC2::KeyPair::KeyName + + LinuxAMI: + Description: Managed AMI ID for Amazon Linux + Type: AWS::SSM::Parameter::Value + Default: /aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2 + +Resources: + VPC: + Type: AWS::EC2::VPC + Properties: + EnableDnsSupport: true + EnableDnsHostnames: true + CidrBlock: !Ref VpcCIDR + Tags: + - Key: Name + Value: !Ref EnvironmentName + + InternetGateway: + Type: AWS::EC2::InternetGateway + Properties: + Tags: + - Key: Name + Value: !Ref EnvironmentName + + InternetGatewayAttachment: + Type: AWS::EC2::VPCGatewayAttachment + Properties: + InternetGatewayId: !Ref InternetGateway + VpcId: !Ref VPC + + # This is the interface endpoint for CloudFormation. You can only deploy this + # once per region since it will consume the unique DNS entry for the endpoint. + CfnEndpoint: + Type: AWS::EC2::VPCEndpoint + Properties: + VpcId: !Ref VPC + ServiceName: !Sub com.amazonaws.${AWS::Region}.cloudformation + VpcEndpointType: Interface + PrivateDnsEnabled: true + SubnetIds: + - !Ref PrivateSubnet1 + - !Ref PrivateSubnet2 + SecurityGroupIds: + - !Ref EndpointSG + + # This is the gateway endpoint for S3. WaitConditions and CustomResources + # need to access self-signed URLs in the following buckets to signal back + # to the stack. + S3Endpoint: + Type: AWS::EC2::VPCEndpoint + Properties: + VpcId: !Ref VPC + ServiceName: !Sub com.amazonaws.${AWS::Region}.s3 + VpcEndpointType: Gateway + PolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Principal: '*' + Action: + - s3:PutObject + Resource: + - !Sub arn:${AWS::Partition}:s3:::cloudformation-waitcondition-${AWS::Region}/* + RouteTableIds: + - !Ref PrivateRouteTable1 + - !Ref PrivateRouteTable2 + + PublicSubnet1: + Type: AWS::EC2::Subnet + Properties: + VpcId: !Ref VPC + AvailabilityZone: !Select + - 0 + - !GetAZs + CidrBlock: !Ref PublicSubnet1CIDR + MapPublicIpOnLaunch: true + Tags: + - Key: Name + Value: !Sub ${EnvironmentName} Public Subnet (AZ1) + + PublicSubnet2: + Type: AWS::EC2::Subnet + Properties: + VpcId: !Ref VPC + AvailabilityZone: !Select + - 1 + - !GetAZs + CidrBlock: !Ref PublicSubnet2CIDR + MapPublicIpOnLaunch: true + Tags: + - Key: Name + Value: !Sub ${EnvironmentName} Public Subnet (AZ2) + + PrivateSubnet1: + Type: AWS::EC2::Subnet + Properties: + VpcId: !Ref VPC + AvailabilityZone: !Select + - 0 + - !GetAZs + CidrBlock: !Ref PrivateSubnet1CIDR + MapPublicIpOnLaunch: false + Tags: + - Key: Name + Value: !Sub ${EnvironmentName} Private Subnet (AZ1) + + PrivateSubnet2: + Type: AWS::EC2::Subnet + Properties: + VpcId: !Ref VPC + AvailabilityZone: !Select + - 1 + - !GetAZs + CidrBlock: !Ref PrivateSubnet2CIDR + MapPublicIpOnLaunch: false + Tags: + - Key: Name + Value: !Sub ${EnvironmentName} Private Subnet (AZ2) + + PublicRouteTable: + Type: AWS::EC2::RouteTable + Properties: + VpcId: !Ref VPC + Tags: + - Key: Name + Value: !Sub ${EnvironmentName} Public Routes + + DefaultPublicRoute: + Type: AWS::EC2::Route + DependsOn: InternetGatewayAttachment + Properties: + RouteTableId: !Ref PublicRouteTable + DestinationCidrBlock: 0.0.0.0/0 + GatewayId: !Ref InternetGateway + + PublicSubnet1RouteTableAssociation: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + RouteTableId: !Ref PublicRouteTable + SubnetId: !Ref PublicSubnet1 + + PublicSubnet2RouteTableAssociation: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + RouteTableId: !Ref PublicRouteTable + SubnetId: !Ref PublicSubnet2 + + PrivateRouteTable1: + Type: AWS::EC2::RouteTable + Properties: + VpcId: !Ref VPC + Tags: + - Key: Name + Value: !Sub ${EnvironmentName} Private Routes (AZ1) + + PrivateSubnet1RouteTableAssociation: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + RouteTableId: !Ref PrivateRouteTable1 + SubnetId: !Ref PrivateSubnet1 + + PrivateRouteTable2: + Type: AWS::EC2::RouteTable + Properties: + VpcId: !Ref VPC + Tags: + - Key: Name + Value: !Sub ${EnvironmentName} Private Routes (AZ2) + + PrivateSubnet2RouteTableAssociation: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + RouteTableId: !Ref PrivateRouteTable2 + SubnetId: !Ref PrivateSubnet2 + + RootRole: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Principal: + Service: + - ec2.amazonaws.com + Action: + - sts:AssumeRole + Path: / + Policies: + - PolicyName: root + PolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: cloudformation:* + Resource: '*' + + BastionInstance: + Type: AWS::EC2::Instance + Properties: + KeyName: !Ref KeyName + InstanceType: t2.micro + SecurityGroupIds: + - !Ref BastionSG + SubnetId: !Ref PublicSubnet1 + ImageId: !Ref LinuxAMI + IamInstanceProfile: !Ref BastionProfile + Tags: + - Key: Name + Value: Bastion + + BastionSG: + Type: AWS::EC2::SecurityGroup + Metadata: + guard: + SuppressedRules: + - INCOMING_SSH_DISABLED + Properties: + GroupDescription: Inbound Bastion Traffic + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: 22 + ToPort: 22 + CidrIp: 0.0.0.0/0 + VpcId: !Ref VPC + Tags: + - Key: Name + Value: BastionSG + + BastionProfile: + Type: AWS::IAM::InstanceProfile + Properties: + Path: / + Roles: + - !Ref RootRole + + PrivateInstance: + Type: AWS::EC2::Instance + DependsOn: CfnEndpoint + Properties: + KeyName: !Ref KeyName + InstanceType: t2.micro + SecurityGroupIds: + - !Ref PrivateSG + SubnetId: !Ref PrivateSubnet1 + ImageId: !Ref LinuxAMI + IamInstanceProfile: !Ref PrivateProfile + UserData: !Base64 + Fn::Sub: | + #!/bin/bash -x + date > /tmp/datefile + cat /tmp/datefile + # Signal the status from instance + /opt/aws/bin/cfn-signal -e $? -d "This was all private." -r "Build Process Complete" '${PrivateWaitHandle}' + Tags: + - Key: Name + Value: Private + + PrivateSG: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Traffic from Bastion + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: 22 + ToPort: 22 + SourceSecurityGroupId: !Ref BastionSG + VpcId: !Ref VPC + Tags: + - Key: Name + Value: PrivateSG + + PrivateProfile: + Type: AWS::IAM::InstanceProfile + Properties: + Path: / + Roles: + - !Ref RootRole + + EndpointSG: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Traffic into CloudFormation Endpoint + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: 443 + ToPort: 443 + CidrIp: 0.0.0.0/0 + VpcId: !Ref VPC + Tags: + - Key: Name + Value: EndpointSG + + PrivateWaitHandle: + Type: AWS::CloudFormation::WaitConditionHandle + + PrivateWaitCondition: + Type: AWS::CloudFormation::WaitCondition + DependsOn: PrivateInstance + Properties: + Handle: !Ref PrivateWaitHandle + Timeout: "3600" + Count: 1 + +Outputs: + VPC: + Description: A reference to the created VPC + Value: !Ref VPC + + PublicSubnets: + Description: A list of the public subnets + Value: !Join + - ',' + - - !Ref PublicSubnet1 + - !Ref PublicSubnet2 + + PrivateSubnets: + Description: A list of the private subnets + Value: !Join + - ',' + - - !Ref PrivateSubnet1 + - !Ref PrivateSubnet2 + + CfnEndpoint: + Description: A reference to the CloudFormation Endpoint used for signaling from the private instance + Value: !Ref CfnEndpoint + + S3Endpoint: + Description: A reference to the S3 Endpoint used for signaling from the private instance + Value: !Ref S3Endpoint diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFrontCustomOriginLambda@Edge/CloudFront.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFrontCustomOriginLambda@Edge/CloudFront.json new file mode 100644 index 0000000000000000000000000000000000000000..3e8bdea746d3b80b0cc73cad09ead36c404aa251 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFrontCustomOriginLambda@Edge/CloudFront.json @@ -0,0 +1,1227 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "CI/CD optimized AWS CloudFormation Sample Template for AWS CloudFront Distribution with Custom Origin with an example of using the AWS Application Load Balancer (ALB) and a basic Amazon EC2 Instance. AWS CloudFront Distribution is associated with Lambda@Edge for Security Headers inspection. In addition, AWS CloudFormation Template will provision an Examples of necessary IAM, S3, KMS and Security Groups resources. ### Before deployment please make sure that all parameters are reviewed and updated according the specific use case. ### **WARNING** This template creates one Amazon EC2 instance and an Application Load Balancer, KMS Keys, S3 bucket, CloudFront Distribution resources. You will be billed for the AWS resources used if you create a stack from this template.", + "Metadata": { + "cfn-lint": { + "config": { + "regions": [ + "us-east-1", + "us-west-2" + ] + } + } + }, + "Parameters": { + "Environment": { + "Description": "Please specify the target environment.", + "Type": "String", + "AllowedValues": [ + "prod", + "staging", + "dev", + "qa" + ], + "Default": "dev" + }, + "VpcId": { + "Description": "Please specify the VPC ID.", + "Type": "AWS::EC2::VPC::Id", + "ConstraintDescription": "Must be a valid VPC ID" + }, + "PublicSubnetId1": { + "Description": "Please specify first public subnet ID.", + "Type": "AWS::EC2::Subnet::Id", + "ConstraintDescription": "Must be a valid subnet ID in the selected VPC" + }, + "PublicSubnetId2": { + "Description": "Please specify second public subnet ID.", + "Type": "AWS::EC2::Subnet::Id", + "ConstraintDescription": "Must be a valid subnet ID in the selected VPC" + }, + "AppName": { + "Description": "Application environment name.", + "Type": "String", + "Default": "example" + }, + "AlternateDomainNames": { + "Description": "CNAMEs (alternate domain names), if any, for the distribution. Example. mydomain.com", + "Type": "String", + "Default": "name.domain.com" + }, + "ACMCertificateIdentifier": { + "Description": "The AWS Certificate Manager (ACM) certificate identifier.", + "Type": "String", + "Default": "1234567890abcdefgh" + }, + "LambdaEventType": { + "Description": "Please specify the event type that triggers a Lambda function invocation.", + "Type": "String", + "AllowedValues": [ + "viewer-request", + "origin-request", + "origin-response", + "viewer-response" + ], + "Default": "viewer-response" + }, + "IPV6Enabled": { + "Description": "Should CloudFront to respond to IPv6 DNS requests with an IPv6 address for your distribution.", + "Type": "String", + "AllowedValues": [ + "true", + "false" + ], + "Default": "true" + }, + "EC2ImageId": { + "Description": "EC2 AMI Id", + "Type": "AWS::EC2::Image::Id", + "Default": "ami-0d85a662720db9789" + }, + "EC2InstanceType": { + "Description": "Amazon EC2 instance type.", + "Type": "String", + "AllowedValues": [ + "t2.small", + "t2.medium", + "t2.large", + "t2.xlarge", + "t2.2xlarge", + "m4.large", + "m4.xlarge", + "m4.2xlarge", + "m4.4xlarge", + "m4.10xlarge", + "m4.16xlarge", + "m5.large", + "m5.xlarge", + "m5.2xlarge", + "m5.4xlarge", + "m5.12xlarge", + "m5.24xlarge", + "m5d.large", + "m5d.xlarge", + "m5d.2xlarge", + "m5d.4xlarge", + "m5d.12xlarge", + "m5d.24xlarge" + ], + "Default": "t2.small" + }, + "KeyPairName": { + "Description": "EC2 KeyPair.", + "Type": "AWS::EC2::KeyPair::KeyName", + "ConstraintDescription": "Must be the name of an existing EC2 KeyPair" + }, + "BootVolSize": { + "Description": "EC2 Instance Boot volume size.", + "Type": "String", + "Default": "100" + }, + "BootVolType": { + "Description": "EC2 Instance Boot volume type.", + "Type": "String", + "AllowedValues": [ + "gp2", + "io1", + "sc1", + "st1" + ], + "Default": "gp2" + }, + "ALBType": { + "Description": "AWS Load Balancer Type.", + "Type": "String", + "AllowedValues": [ + "application", + "network" + ], + "Default": "application" + }, + "OriginALBTGPort": { + "Description": "Port number the application is running on, for Origin ALB Target Group and Health Check port.", + "Type": "String", + "Default": "8080" + }, + "OriginProtocolPolicy": { + "Description": "CloudFront Origin Protocol Policy to apply to your origin.", + "Type": "String", + "AllowedValues": [ + "http-only", + "match-viewer", + "https-only" + ], + "Default": "http-only" + }, + "Compress": { + "Description": "CloudFront should support gzip compression requests: Accept-Encoding: gzip.", + "Type": "String", + "AllowedValues": [ + "true", + "false" + ], + "Default": "false" + }, + "DefaultTTL": { + "Description": "The default time in seconds that objects stay in CloudFront caches before CloudFront forwards another request to your custom origin. By default, AWS CloudFormation specifies 86400 seconds (one day).", + "Type": "String", + "Default": "0" + }, + "MaxTTL": { + "Description": "The maximum time in seconds that objects stay in CloudFront caches before CloudFront forwards another request to your custom origin. By default, AWS CloudFormation specifies 31536000 seconds (one year).", + "Type": "String", + "Default": "0" + }, + "MinTTL": { + "Description": "The minimum amount of time that you want objects to stay in the cache before CloudFront queries your origin to see whether the object has been updated.", + "Type": "String", + "Default": "0" + }, + "QueryString": { + "Description": "CIndicates whether you want CloudFront to forward query strings to the origin that is associated with this cache behavior.", + "Type": "String", + "AllowedValues": [ + "true", + "false" + ], + "Default": "true" + }, + "ForwardCookies": { + "Description": "Forwards specified cookies to the origin of the cache behavior.", + "Type": "String", + "AllowedValues": [ + "all", + "whitelist", + "none" + ], + "Default": "all" + }, + "ViewerProtocolPolicy": { + "Description": "The protocol that users can use to access the files in the origin that you specified in the TargetOriginId property when the default cache behavior is applied to a request.", + "Type": "String", + "AllowedValues": [ + "redirect-to-https", + "allow-all", + "https-only" + ], + "Default": "redirect-to-https" + }, + "PriceClass": { + "Description": "The price class that corresponds with the maximum price that you want to pay for CloudFront service. If you specify PriceClass_All, CloudFront responds to requests for your objects from all CloudFront edge locations.", + "Type": "String", + "AllowedValues": [ + "PriceClass_All", + "PriceClass_100", + "PriceClass_200" + ], + "Default": "PriceClass_All" + }, + "SslSupportMethod": { + "Description": "Specifies how CloudFront serves HTTPS requests.", + "Type": "String", + "AllowedValues": [ + "sni-only", + "vip" + ], + "Default": "sni-only" + }, + "MinimumProtocolVersion": { + "Description": "The minimum version of the SSL protocol that you want CloudFront to use for HTTPS connections.", + "Type": "String", + "AllowedValues": [ + "TLSv1", + "TLSv1.2_2018", + "TLSv1.1_2016", + "TLSv1_2016", + "SSLv3" + ], + "Default": "TLSv1" + }, + "OriginKeepaliveTimeout": { + "Description": "You can create a custom keep-alive timeout. All timeout units are in seconds. The default keep-alive timeout is 5 seconds, but you can configure custom timeout lengths. The minimum timeout length is 1 second; the maximum is 60 seconds.", + "Type": "String", + "Default": "60" + }, + "OriginReadTimeout": { + "Description": "You can create a custom origin read timeout. All timeout units are in seconds. The default origin read timeout is 30 seconds, but you can configure custom timeout lengths. The minimum timeout length is 4 seconds; the maximum is 60 seconds.", + "Type": "String", + "Default": "30" + }, + "ALBScheme": { + "Description": "Origin ALB scheme.", + "Type": "String", + "AllowedValues": [ + "internet-facing", + "internal" + ], + "Default": "internet-facing" + }, + "ALBTargetGroupHealthCheckIntervalSeconds": { + "Description": "Origin ALB Target Group Health Check Interval in Seconds.", + "Type": "String", + "Default": "30" + }, + "ALBTargetGroupHealthCheckTimeoutSeconds": { + "Description": "Origin ALB Target Group Health Check Timeout in Seconds.", + "Type": "String", + "Default": "5" + }, + "ALBTargetGroupHealthyThresholdCount": { + "Description": "Origin ALB Target Group Healthy Threshold Count.", + "Type": "String", + "Default": "5" + }, + "ALBTargetGroupUnhealthyThresholdCount": { + "Description": "Origin ALB Target Group Unhealthy Threshold Count.", + "Type": "String", + "Default": "2" + }, + "ALBAttributeIdleTimeOut": { + "Description": "Origin ALB Target Group Unhealthy Threshold Count.", + "Type": "String", + "Default": "60" + }, + "ALBAttributeDeletionProtection": { + "Description": "Origin ALB Target Group Unhealthy Threshold Count.", + "Type": "String", + "AllowedValues": [ + "true", + "false" + ], + "Default": "false" + }, + "ALBAttributeRoutingHttp2": { + "Description": "Origin ALB Target Group Unhealthy Threshold Count.", + "Type": "String", + "AllowedValues": [ + "true", + "false" + ], + "Default": "true" + }, + "ALBTargetGroupAttributeDeregistration": { + "Description": "Origin ALB Target Group Deregistration Timeout.", + "Type": "String", + "Default": "300" + }, + "HealthCheckProtocol": { + "Description": "Origin ALB Target Group Health Check Protocol.", + "Type": "String", + "AllowedValues": [ + "HTTPS", + "HTTP" + ], + "Default": "HTTP" + }, + "HealthCheckPath": { + "Description": "Origin ALB Target Group Health Check Path.", + "Type": "String", + "Default": "/health.html" + }, + "LoggingBucketVersioning": { + "Description": "The versioning state of an Amazon S3 bucket. If you enable versioning, you must suspend versioning to disable it.", + "Type": "String", + "AllowedValues": [ + "Enabled", + "Suspended" + ], + "Default": "Suspended" + } + }, + "Resources": { + "AdministratorAccessIAMRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "RoleName": { + "Fn::Sub": "AdministratorAccess-${AppName}" + }, + "ManagedPolicyArns": [ + { + "Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/AdministratorAccess" + } + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Principal": { + "Service": [ + "ec2.amazonaws.com" + ] + }, + "Action": [ + "sts:AssumeRole" + ] + } + ] + }, + "Path": "/" + } + }, + "LambdaEdgeIAMRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "RoleName": { + "Fn::Sub": "${AppName}-iam-lambda-edge-role-${Environment}" + }, + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Sid": "AllowLambdaServiceToAssumeRole", + "Effect": "Allow", + "Principal": { + "Service": [ + "edgelambda.amazonaws.com", + "lambda.amazonaws.com" + ] + }, + "Action": [ + "sts:AssumeRole" + ] + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess" + ], + "Path": "/", + "Policies": [ + { + "PolicyName": "PublishNewLambdaEdgeVersion", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "lambda:PublishVersion" + ], + "Resource": "*" + } + ] + } + } + ] + } + }, + "LoggingBucketKMSKey": { + "Type": "AWS::KMS::Key", + "DependsOn": "AdministratorAccessIAMRole", + "Properties": { + "Description": "Logging S3 Bucket KMS Key", + "Enabled": true, + "EnableKeyRotation": true, + "KeyPolicy": { + "Version": "2012-10-17", + "Statement": [ + { + "Sid": "Enable IAM policies to allow access to the Key", + "Effect": "Allow", + "Principal": { + "AWS": { + "Fn::Sub": "arn:${AWS::Partition}:iam::${AWS::AccountId}:root" + } + }, + "Action": [ + "kms:*" + ], + "Resource": "*" + }, + { + "Sid": "Allow administration of the key", + "Effect": "Allow", + "Principal": { + "AWS": [ + { + "Fn::Sub": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/AdministratorAccess-${AppName}" + } + ] + }, + "Action": [ + "kms:Put*", + "kms:ScheduleKeyDeletion", + "kms:CancelKeyDeletion", + "kms:Describe*", + "kms:Revoke*", + "kms:Disable*", + "kms:Enable*", + "kms:Delete*", + "kms:List*", + "kms:Update*", + "kms:Create*" + ], + "Resource": "*" + } + ] + } + } + }, + "LoggingBucketKMSKeyAlias": { + "Type": "AWS::KMS::Alias", + "Properties": { + "AliasName": { + "Fn::Sub": "alias/${AppName}/${Environment}/s3-logging-kms" + }, + "TargetKeyId": { + "Fn::Sub": "${LoggingBucketKMSKey}" + } + } + }, + "LoggingBucket": { + "DeletionPolicy": "Retain", + "UpdateReplacePolicy": "Retain", + "Type": "AWS::S3::Bucket", + "DependsOn": "LoggingBucketKMSKey", + "Metadata": { + "guard": { + "SuppressedRules": [ + "S3_BUCKET_DEFAULT_LOCK_ENABLED", + "S3_BUCKET_VERSIONING_ENABLED", + "S3_BUCKET_REPLICATION_ENABLED", + "S3_BUCKET_LOGGING_ENABLED" + ] + } + }, + "Properties": { + "BucketName": { + "Fn::Sub": "${AppName}-logging-${Environment}-${AWS::AccountId}-${AWS::Region}" + }, + "OwnershipControls": { + "Rules": [ + { + "ObjectOwnership": "ObjectWriter" + } + ] + }, + "PublicAccessBlockConfiguration": { + "BlockPublicAcls": true, + "BlockPublicPolicy": true, + "IgnorePublicAcls": true, + "RestrictPublicBuckets": true + }, + "AccessControl": "LogDeliveryWrite", + "BucketEncryption": { + "ServerSideEncryptionConfiguration": [ + { + "ServerSideEncryptionByDefault": { + "KMSMasterKeyID": { + "Fn::GetAtt": [ + "LoggingBucketKMSKey", + "Arn" + ] + }, + "SSEAlgorithm": "aws:kms" + } + } + ] + }, + "VersioningConfiguration": { + "Status": { + "Ref": "LoggingBucketVersioning" + } + } + } + }, + "LoggingBucketPolicy": { + "Type": "AWS::S3::BucketPolicy", + "Properties": { + "Bucket": { + "Ref": "LoggingBucket" + }, + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Sid": "LoggingBucketPermissions", + "Effect": "Allow", + "Principal": { + "AWS": { + "Fn::Sub": "arn:${AWS::Partition}:iam::${AWS::AccountId}:root" + } + }, + "Action": "s3:PutObject", + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${LoggingBucket}/AWSLogs/${AWS::AccountId}/*" + } + ] + }, + { + "Action": "s3:*", + "Condition": { + "Bool": { + "aws:SecureTransport": false + } + }, + "Effect": "Deny", + "Principal": { + "AWS": "*" + }, + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${LoggingBucket}/AWSLogs/${AWS::AccountId}/*" + } + ] + } + ] + } + } + }, + "EC2Instance": { + "Type": "AWS::EC2::Instance", + "Properties": { + "ImageId": { + "Ref": "EC2ImageId" + }, + "InstanceType": { + "Ref": "EC2InstanceType" + }, + "SubnetId": { + "Ref": "PublicSubnetId1" + }, + "BlockDeviceMappings": [ + { + "DeviceName": "/dev/sda1", + "Ebs": { + "VolumeSize": { + "Ref": "BootVolSize" + }, + "VolumeType": { + "Ref": "BootVolType" + } + } + } + ], + "SecurityGroupIds": [ + { + "Ref": "EC2InstanceSG" + }, + { + "Ref": "ALBExternalAccessSG" + } + ], + "KeyName": { + "Ref": "KeyPairName" + }, + "Tags": [ + { + "Key": "Name", + "Value": { + "Fn::Sub": "${AppName}-${Environment}-ec2-instance" + } + }, + { + "Key": "Environment", + "Value": { + "Ref": "Environment" + } + } + ] + } + }, + "EC2InstanceSG": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "EC2 Instance Security Group", + "VpcId": { + "Ref": "VpcId" + }, + "Tags": [ + { + "Key": "Name", + "Value": { + "Fn::Sub": "${AppName}-${Environment}-ec2-instance-SG" + } + }, + { + "Key": "Environment", + "Value": { + "Ref": "Environment" + } + } + ] + } + }, + "Tcp8080In": { + "Type": "AWS::EC2::SecurityGroupIngress", + "Properties": { + "GroupId": { + "Ref": "EC2InstanceSG" + }, + "ToPort": "8080", + "IpProtocol": "tcp", + "FromPort": "8080", + "SourceSecurityGroupId": { + "Ref": "ALBExternalAccessSG" + } + } + }, + "OriginALB": { + "Type": "AWS::ElasticLoadBalancingV2::LoadBalancer", + "Properties": { + "Name": { + "Fn::Sub": "${AppName}-${Environment}-alb" + }, + "Scheme": { + "Ref": "ALBScheme" + }, + "Type": { + "Ref": "ALBType" + }, + "LoadBalancerAttributes": [ + { + "Key": "idle_timeout.timeout_seconds", + "Value": { + "Ref": "ALBAttributeIdleTimeOut" + } + }, + { + "Key": "deletion_protection.enabled", + "Value": { + "Ref": "ALBAttributeDeletionProtection" + } + }, + { + "Key": "routing.http2.enabled", + "Value": { + "Ref": "ALBAttributeRoutingHttp2" + } + } + ], + "Subnets": [ + { + "Ref": "PublicSubnetId1" + }, + { + "Ref": "PublicSubnetId2" + } + ], + "SecurityGroups": [ + { + "Ref": "ALBExternalAccessSG" + } + ], + "Tags": [ + { + "Key": "Name", + "Value": { + "Fn::Sub": "${AppName}-${Environment}-alb" + } + }, + { + "Key": "Environment", + "Value": { + "Ref": "Environment" + } + } + ] + } + }, + "OriginALBTG": { + "Type": "AWS::ElasticLoadBalancingV2::TargetGroup", + "DependsOn": "OriginALB", + "Properties": { + "Name": { + "Fn::Sub": "${AppName}-${Environment}-alb-tg" + }, + "HealthCheckProtocol": { + "Ref": "HealthCheckProtocol" + }, + "HealthCheckPath": { + "Ref": "HealthCheckPath" + }, + "HealthCheckPort": { + "Fn::Sub": "${OriginALBTGPort}" + }, + "HealthCheckIntervalSeconds": { + "Ref": "ALBTargetGroupHealthCheckIntervalSeconds" + }, + "HealthCheckTimeoutSeconds": { + "Ref": "ALBTargetGroupHealthCheckTimeoutSeconds" + }, + "HealthyThresholdCount": { + "Ref": "ALBTargetGroupHealthyThresholdCount" + }, + "UnhealthyThresholdCount": { + "Ref": "ALBTargetGroupUnhealthyThresholdCount" + }, + "TargetGroupAttributes": [ + { + "Key": "deregistration_delay.timeout_seconds", + "Value": { + "Ref": "ALBTargetGroupAttributeDeregistration" + } + } + ], + "TargetType": "instance", + "Targets": [ + { + "Id": { + "Ref": "EC2Instance" + }, + "Port": { + "Ref": "OriginALBTGPort" + } + } + ], + "Port": { + "Ref": "OriginALBTGPort" + }, + "Protocol": "HTTP", + "VpcId": { + "Ref": "VpcId" + }, + "Tags": [ + { + "Key": "Name", + "Value": { + "Fn::Sub": "${AppName}-${Environment}-alb-tg" + } + }, + { + "Key": "Environment", + "Value": { + "Ref": "Environment" + } + } + ] + } + }, + "OriginALBHttpsListener": { + "Type": "AWS::ElasticLoadBalancingV2::Listener", + "DependsOn": "OriginALBTG", + "Properties": { + "DefaultActions": [ + { + "TargetGroupArn": { + "Ref": "OriginALBTG" + }, + "Type": "forward" + } + ], + "LoadBalancerArn": { + "Ref": "OriginALB" + }, + "Port": 443, + "Protocol": "HTTPS", + "Certificates": [ + { + "CertificateArn": { + "Fn::Sub": "arn:${AWS::Partition}:acm:${AWS::Region}:${AWS::AccountId}:certificate/${ACMCertificateIdentifier}" + } + } + ], + "SslPolicy": "ELBSecurityPolicy-FS-2018-06" + } + }, + "OriginALBHttpsListenerRule": { + "Type": "AWS::ElasticLoadBalancingV2::ListenerRule", + "DependsOn": "OriginALBHttpsListener", + "Properties": { + "Actions": [ + { + "Type": "forward", + "TargetGroupArn": { + "Ref": "OriginALBTG" + } + } + ], + "Conditions": [ + { + "Field": "path-pattern", + "Values": [ + "/*" + ] + } + ], + "ListenerArn": { + "Ref": "OriginALBHttpsListener" + }, + "Priority": 1 + } + }, + "ALBExternalAccessSG": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "Allow external access to ALB", + "VpcId": { + "Ref": "VpcId" + }, + "Tags": [ + { + "Key": "Name", + "Value": { + "Fn::Sub": "${AppName}-${Environment}-alb-external-access-ingrees-SG" + } + }, + { + "Key": "Environment", + "Value": { + "Ref": "Environment" + } + } + ] + } + }, + "HTTPSTcpIn": { + "Type": "AWS::EC2::SecurityGroupIngress", + "Properties": { + "GroupId": { + "Ref": "ALBExternalAccessSG" + }, + "ToPort": 443, + "IpProtocol": "tcp", + "FromPort": 443, + "CidrIp": "0.0.0.0/0" + } + }, + "HTTPTcpIn": { + "Type": "AWS::EC2::SecurityGroupIngress", + "Properties": { + "GroupId": { + "Ref": "ALBExternalAccessSG" + }, + "ToPort": 80, + "IpProtocol": "tcp", + "FromPort": 80, + "CidrIp": "0.0.0.0/0" + } + }, + "Tcp8080Out": { + "Type": "AWS::EC2::SecurityGroupEgress", + "Properties": { + "GroupId": { + "Ref": "ALBExternalAccessSG" + }, + "ToPort": 8080, + "IpProtocol": "tcp", + "FromPort": 8080, + "DestinationSecurityGroupId": { + "Ref": "EC2InstanceSG" + } + } + }, + "CloudFrontDistribution": { + "Type": "AWS::CloudFront::Distribution", + "DependsOn": [ + "LoggingBucket", + "LambdaEdgeFunction" + ], + "Properties": { + "DistributionConfig": { + "Comment": "Cloudfront Distribution pointing ALB Origin", + "Origins": [ + { + "DomainName": { + "Fn::GetAtt": [ + "OriginALB", + "DNSName" + ] + }, + "Id": { + "Ref": "OriginALB" + }, + "CustomOriginConfig": { + "HTTPPort": 80, + "HTTPSPort": 443, + "OriginProtocolPolicy": { + "Ref": "OriginProtocolPolicy" + }, + "OriginKeepaliveTimeout": { + "Ref": "OriginKeepaliveTimeout" + }, + "OriginReadTimeout": { + "Ref": "OriginReadTimeout" + }, + "OriginSSLProtocols": [ + "TLSv1", + "TLSv1.1", + "TLSv1.2", + "SSLv3" + ] + } + } + ], + "Enabled": true, + "HttpVersion": "http2", + "Aliases": [ + { + "Ref": "AlternateDomainNames" + } + ], + "DefaultCacheBehavior": { + "AllowedMethods": [ + "GET", + "HEAD", + "DELETE", + "OPTIONS", + "PATCH", + "POST", + "PUT" + ], + "Compress": { + "Ref": "Compress" + }, + "DefaultTTL": { + "Ref": "DefaultTTL" + }, + "MaxTTL": { + "Ref": "MaxTTL" + }, + "MinTTL": { + "Ref": "MinTTL" + }, + "SmoothStreaming": "false", + "TargetOriginId": { + "Ref": "OriginALB" + }, + "ForwardedValues": { + "QueryString": { + "Ref": "QueryString" + }, + "Cookies": { + "Forward": { + "Ref": "ForwardCookies" + } + } + }, + "ViewerProtocolPolicy": { + "Ref": "ViewerProtocolPolicy" + }, + "LambdaFunctionAssociations": [ + { + "EventType": { + "Ref": "LambdaEventType" + }, + "LambdaFunctionARN": { + "Ref": "LambdaEdgeVersion" + } + } + ] + }, + "PriceClass": { + "Ref": "PriceClass" + }, + "ViewerCertificate": { + "AcmCertificateArn": { + "Fn::Sub": "arn:${AWS::Partition}:acm:${AWS::Region}:${AWS::AccountId}:certificate/${ACMCertificateIdentifier}" + }, + "SslSupportMethod": { + "Ref": "SslSupportMethod" + }, + "MinimumProtocolVersion": { + "Ref": "MinimumProtocolVersion" + } + }, + "IPV6Enabled": { + "Ref": "IPV6Enabled" + }, + "Logging": { + "Bucket": { + "Fn::Sub": "${LoggingBucket}.s3.amazonaws.com" + } + } + } + } + }, + "LambdaEdgeFunction": { + "Type": "AWS::Lambda::Function", + "Metadata": { + "guard": { + "SuppressedRules": [ + "LAMBDA_INSIDE_VPC" + ] + } + }, + "Properties": { + "Description": "A custom Lambda@Edge function for serving custom headers from CloudFront Distribution", + "FunctionName": { + "Fn::Sub": "${AppName}-lambda-edge-${Environment}" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "LambdaEdgeIAMRole", + "Arn" + ] + }, + "MemorySize": 128, + "Timeout": 5, + "Code": { + "ZipFile": "'use strict';\n\n exports.handler = (event, context, callback) => {\n console.log('Adding additional headers to CloudFront response.');\n\n const response = event.Records[0].cf.response;\n response.headers['strict-transport-security'] = [{\n key: 'Strict-Transport-Security',\n value: 'max-age=86400; includeSubdomains; preload',\n }];\n response.headers['x-content-type-options'] = [{\n key: 'X-Content-Type-Options',\n value: 'nosniff',\n }];\n response.headers['x-frame-options'] = [{\n key: 'X-Frame-Options',\n value: \"DENY\"\n }];\n response.headers['content-security-policy'] = [{\n key: 'Content-Security-Policy',\n value: \"default-src 'none'; img-src 'self'; script-src 'self'; style-src 'self'; object-src 'none'\"\n }];\n response.headers['x-xss-protection'] = [{\n key: 'X-XSS-Protection',\n value: \"1; mode=block\"\n }];\n response.headers['referrer-policy'] = [{\n key: 'Referrer-Policy',\n value: \"same-origin\"\n }];\n callback(null, response);\n };\n" + }, + "Runtime": "nodejs20.x" + } + }, + "LambdaEdgeVersion": { + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "LambdaEdgeFunction" + } + } + } + }, + "Outputs": { + "AdministratorAccessIAMRole": { + "Description": "Administrator Access IAM Role", + "Value": { + "Ref": "AdministratorAccessIAMRole" + }, + "Export": { + "Name": { + "Fn::Sub": "${AppName}-iam-${Environment}-administrator-access-role" + } + } + }, + "LoggingBucket": { + "Description": "Name of S3 Logging bucket", + "Value": { + "Ref": "LoggingBucket" + }, + "Export": { + "Name": { + "Fn::Sub": "${AppName}-logging-${Environment}-${AWS::AccountId}-${AWS::Region}" + } + } + }, + "LoggingBucketKMSKey": { + "Description": "Logging Bucket KMS Key", + "Value": { + "Ref": "LoggingBucketKMSKey" + }, + "Export": { + "Name": { + "Fn::Sub": "${AppName}-${Environment}-s3-logging-kms" + } + } + }, + "OriginALB": { + "Description": "The URL of the Origin ALB", + "Value": { + "Fn::GetAtt": [ + "OriginALB", + "DNSName" + ] + }, + "Export": { + "Name": { + "Fn::Sub": "${AppName}-${Environment}-origin-alb-dns" + } + } + }, + "ALBExternalAccessSGID": { + "Description": "ALB External Access Security Group ID", + "Value": { + "Ref": "ALBExternalAccessSG" + }, + "Export": { + "Name": { + "Fn::Sub": "${AppName}-${Environment}-alb-external-access-ingrees-sg" + } + } + }, + "EC2InstanceSGID": { + "Description": "EC2 Instance Security Group ID", + "Value": { + "Ref": "EC2InstanceSG" + }, + "Export": { + "Name": { + "Fn::Sub": "${AppName}-${Environment}-ec2-instance-sg" + } + } + }, + "EC2InstanceDNS": { + "Description": "EC2 Instance DNS Name", + "Value": { + "Fn::GetAtt": [ + "EC2Instance", + "PrivateDnsName" + ] + }, + "Export": { + "Name": { + "Fn::Sub": "${AppName}-${Environment}-ec2-instance-dns" + } + } + }, + "EC2InstanceIP": { + "Description": "EC2 Instance IP Address", + "Value": { + "Fn::GetAtt": [ + "EC2Instance", + "PrivateIp" + ] + }, + "Export": { + "Name": { + "Fn::Sub": "${AppName}-${Environment}-ec2-instance-ip-address" + } + } + }, + "EC2InstanceID": { + "Description": "EC2 Instance Instance ID", + "Value": { + "Ref": "EC2Instance" + }, + "Export": { + "Name": { + "Fn::Sub": "${AppName}-${Environment}-ec2-instance-id" + } + } + }, + "CloudFrontEndpoint": { + "Description": "Endpoint for Cloudfront Distribution", + "Value": { + "Ref": "CloudFrontDistribution" + }, + "Export": { + "Name": { + "Fn::Sub": "${AppName}-${Environment}-cloudfront-distribution" + } + } + }, + "AlternateDomainNames": { + "Description": "Alternate Domain Names (CNAME)", + "Value": { + "Ref": "AlternateDomainNames" + } + }, + "LambdaEdgeFunction": { + "Description": "The Name of the Lambda@Edge Function", + "Value": "LambdaEdgeFunction", + "Export": { + "Name": { + "Fn::Sub": "${AppName}-${Environment}-lambda-edge-function-3" + } + } + }, + "LambdaEdgeFunctionARN": { + "Description": "The ARN of the Lambda@Edge Function", + "Value": { + "Fn::GetAtt": [ + "LambdaEdgeFunction", + "Arn" + ] + }, + "Export": { + "Name": { + "Fn::Sub": "${AppName}-${Environment}-lambda-edge-function-arn-3" + } + } + }, + "LambdaEdgeVersion": { + "Description": "Lambda@Edge Version Function", + "Value": { + "Fn::GetAtt": [ + "LambdaEdgeVersion", + "Version" + ] + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFrontCustomOriginLambda@Edge/CloudFront.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFrontCustomOriginLambda@Edge/CloudFront.yaml new file mode 100644 index 0000000000000000000000000000000000000000..38917eb0951d3f9d4eb7d8b0e74a87b432b24fb9 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFrontCustomOriginLambda@Edge/CloudFront.yaml @@ -0,0 +1,823 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: 'CI/CD optimized AWS CloudFormation Sample Template for AWS CloudFront Distribution with Custom Origin with an example of using the AWS Application Load Balancer (ALB) and a basic Amazon EC2 Instance. AWS CloudFront Distribution is associated with Lambda@Edge for Security Headers inspection. In addition, AWS CloudFormation Template will provision an Examples of necessary IAM, S3, KMS and Security Groups resources. ### Before deployment please make sure that all parameters are reviewed and updated according the specific use case. ### **WARNING** This template creates one Amazon EC2 instance and an Application Load Balancer, KMS Keys, S3 bucket, CloudFront Distribution resources. You will be billed for the AWS resources used if you create a stack from this template.' + +Metadata: + cfn-lint: + config: + regions: + - us-east-1 + - us-west-2 + +Parameters: + Environment: + Description: Please specify the target environment. + Type: String + AllowedValues: + - prod + - staging + - dev + - qa + Default: dev + + VpcId: + Description: Please specify the VPC ID. + Type: AWS::EC2::VPC::Id + ConstraintDescription: "Must be a valid VPC ID" + + PublicSubnetId1: + Description: Please specify first public subnet ID. + Type: AWS::EC2::Subnet::Id + ConstraintDescription: "Must be a valid subnet ID in the selected VPC" + + PublicSubnetId2: + Description: Please specify second public subnet ID. + Type: AWS::EC2::Subnet::Id + ConstraintDescription: "Must be a valid subnet ID in the selected VPC" + + + AppName: + Description: Application environment name. + Type: String + Default: example + + AlternateDomainNames: + Description: CNAMEs (alternate domain names), if any, for the distribution. Example. mydomain.com + Type: String + Default: name.domain.com + + ACMCertificateIdentifier: + Description: The AWS Certificate Manager (ACM) certificate identifier. + Type: String + Default: 1234567890abcdefgh + + LambdaEventType: + Description: Please specify the event type that triggers a Lambda function invocation. + Type: String + AllowedValues: + - viewer-request + - origin-request + - origin-response + - viewer-response + Default: viewer-response + + IPV6Enabled: + Description: Should CloudFront to respond to IPv6 DNS requests with an IPv6 address for your distribution. + Type: String + AllowedValues: + - "true" + - "false" + Default: "true" + + EC2ImageId: + Description: EC2 AMI Id + Type: AWS::EC2::Image::Id + Default: ami-0d85a662720db9789 + + EC2InstanceType: + Description: Amazon EC2 instance type. + Type: String + AllowedValues: + - t2.small + - t2.medium + - t2.large + - t2.xlarge + - t2.2xlarge + - m4.large + - m4.xlarge + - m4.2xlarge + - m4.4xlarge + - m4.10xlarge + - m4.16xlarge + - m5.large + - m5.xlarge + - m5.2xlarge + - m5.4xlarge + - m5.12xlarge + - m5.24xlarge + - m5d.large + - m5d.xlarge + - m5d.2xlarge + - m5d.4xlarge + - m5d.12xlarge + - m5d.24xlarge + Default: t2.small + + KeyPairName: + Description: EC2 KeyPair. + Type: AWS::EC2::KeyPair::KeyName + ConstraintDescription: "Must be the name of an existing EC2 KeyPair" + + BootVolSize: + Description: EC2 Instance Boot volume size. + Type: String + Default: "100" + + BootVolType: + Description: EC2 Instance Boot volume type. + Type: String + AllowedValues: + - gp2 + - io1 + - sc1 + - st1 + Default: gp2 + + ALBType: + Description: AWS Load Balancer Type. + Type: String + AllowedValues: + - application + - network + Default: application + + OriginALBTGPort: + Description: Port number the application is running on, for Origin ALB Target Group and Health Check port. + Type: String + Default: "8080" + + OriginProtocolPolicy: + Description: CloudFront Origin Protocol Policy to apply to your origin. + Type: String + AllowedValues: + - http-only + - match-viewer + - https-only + Default: http-only + + Compress: + Description: 'CloudFront should support gzip compression requests: Accept-Encoding: gzip.' + Type: String + AllowedValues: + - "true" + - "false" + Default: "false" + + DefaultTTL: + Description: The default time in seconds that objects stay in CloudFront caches before CloudFront forwards another request to your custom origin. By default, AWS CloudFormation specifies 86400 seconds (one day). + Type: String + Default: "0" + + MaxTTL: + Description: The maximum time in seconds that objects stay in CloudFront caches before CloudFront forwards another request to your custom origin. By default, AWS CloudFormation specifies 31536000 seconds (one year). + Type: String + Default: "0" + + MinTTL: + Description: The minimum amount of time that you want objects to stay in the cache before CloudFront queries your origin to see whether the object has been updated. + Type: String + Default: "0" + + QueryString: + Description: CIndicates whether you want CloudFront to forward query strings to the origin that is associated with this cache behavior. + Type: String + AllowedValues: + - "true" + - "false" + Default: "true" + + ForwardCookies: + Description: Forwards specified cookies to the origin of the cache behavior. + Type: String + AllowedValues: + - all + - whitelist + - none + Default: all + + ViewerProtocolPolicy: + Description: The protocol that users can use to access the files in the origin that you specified in the TargetOriginId property when the default cache behavior is applied to a request. + Type: String + AllowedValues: + - redirect-to-https + - allow-all + - https-only + Default: redirect-to-https + + PriceClass: + Description: The price class that corresponds with the maximum price that you want to pay for CloudFront service. If you specify PriceClass_All, CloudFront responds to requests for your objects from all CloudFront edge locations. + Type: String + AllowedValues: + - PriceClass_All + - PriceClass_100 + - PriceClass_200 + Default: PriceClass_All + + SslSupportMethod: + Description: Specifies how CloudFront serves HTTPS requests. + Type: String + AllowedValues: + - sni-only + - vip + Default: sni-only + + MinimumProtocolVersion: + Description: The minimum version of the SSL protocol that you want CloudFront to use for HTTPS connections. + Type: String + AllowedValues: + - TLSv1 + - TLSv1.2_2018 + - TLSv1.1_2016 + - TLSv1_2016 + - SSLv3 + Default: TLSv1 + + OriginKeepaliveTimeout: + Description: You can create a custom keep-alive timeout. All timeout units are in seconds. The default keep-alive timeout is 5 seconds, but you can configure custom timeout lengths. The minimum timeout length is 1 second; the maximum is 60 seconds. + Type: String + Default: "60" + + OriginReadTimeout: + Description: You can create a custom origin read timeout. All timeout units are in seconds. The default origin read timeout is 30 seconds, but you can configure custom timeout lengths. The minimum timeout length is 4 seconds; the maximum is 60 seconds. + Type: String + Default: "30" + + ALBScheme: + Description: Origin ALB scheme. + Type: String + AllowedValues: + - internet-facing + - internal + Default: internet-facing + + ALBTargetGroupHealthCheckIntervalSeconds: + Description: Origin ALB Target Group Health Check Interval in Seconds. + Type: String + Default: "30" + + ALBTargetGroupHealthCheckTimeoutSeconds: + Description: Origin ALB Target Group Health Check Timeout in Seconds. + Type: String + Default: "5" + + ALBTargetGroupHealthyThresholdCount: + Description: Origin ALB Target Group Healthy Threshold Count. + Type: String + Default: "5" + + ALBTargetGroupUnhealthyThresholdCount: + Description: Origin ALB Target Group Unhealthy Threshold Count. + Type: String + Default: "2" + + ALBAttributeIdleTimeOut: + Description: Origin ALB Target Group Unhealthy Threshold Count. + Type: String + Default: "60" + + ALBAttributeDeletionProtection: + Description: Origin ALB Target Group Unhealthy Threshold Count. + Type: String + AllowedValues: + - "true" + - "false" + Default: "false" + + ALBAttributeRoutingHttp2: + Description: Origin ALB Target Group Unhealthy Threshold Count. + Type: String + AllowedValues: + - "true" + - "false" + Default: "true" + + ALBTargetGroupAttributeDeregistration: + Description: Origin ALB Target Group Deregistration Timeout. + Type: String + Default: "300" + + HealthCheckProtocol: + Description: Origin ALB Target Group Health Check Protocol. + Type: String + AllowedValues: + - HTTPS + - HTTP + Default: HTTP + + HealthCheckPath: + Description: Origin ALB Target Group Health Check Path. + Type: String + Default: /health.html + + LoggingBucketVersioning: + Description: The versioning state of an Amazon S3 bucket. If you enable versioning, you must suspend versioning to disable it. + Type: String + AllowedValues: + - Enabled + - Suspended + Default: Suspended + +Resources: + + # IAM ROLE USED FOR LOGGING KMS KEY ACCESS + AdministratorAccessIAMRole: + Type: AWS::IAM::Role + Properties: + RoleName: !Sub AdministratorAccess-${AppName} + ManagedPolicyArns: + - !Sub arn:${AWS::Partition}:iam::aws:policy/AdministratorAccess + AssumeRolePolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Principal: + Service: + - ec2.amazonaws.com + Action: + - sts:AssumeRole + Path: / + + # IAM ROLE USED FOR LAMBDA EDGE + LambdaEdgeIAMRole: + Type: AWS::IAM::Role + Properties: + RoleName: !Sub ${AppName}-iam-lambda-edge-role-${Environment} + AssumeRolePolicyDocument: + Version: "2012-10-17" + Statement: + - Sid: AllowLambdaServiceToAssumeRole + Effect: Allow + Principal: + Service: + - edgelambda.amazonaws.com + - lambda.amazonaws.com + Action: + - sts:AssumeRole + ManagedPolicyArns: + - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole + - arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess + Path: / + Policies: + - PolicyName: PublishNewLambdaEdgeVersion + PolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: + - lambda:PublishVersion + Resource: '*' + + # KMS KEY USED FOR LOGGING S3 BUCKET + LoggingBucketKMSKey: + Type: AWS::KMS::Key + DependsOn: AdministratorAccessIAMRole + Properties: + Description: Logging S3 Bucket KMS Key + Enabled: true + EnableKeyRotation: true + KeyPolicy: + Version: "2012-10-17" + Statement: + - Sid: Enable IAM policies to allow access to the Key + Effect: Allow + Principal: + AWS: !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:root + Action: + - kms:* + Resource: '*' + - Sid: Allow administration of the key + Effect: Allow + Principal: + AWS: + - !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:role/AdministratorAccess-${AppName} + Action: + - kms:Put* + - kms:ScheduleKeyDeletion + - kms:CancelKeyDeletion + - kms:Describe* + - kms:Revoke* + - kms:Disable* + - kms:Enable* + - kms:Delete* + - kms:List* + - kms:Update* + - kms:Create* + Resource: '*' + + # KMS KEY ALIAS USED FOR LOGGING BUCKET + LoggingBucketKMSKeyAlias: + Type: AWS::KMS::Alias + Properties: + AliasName: !Sub alias/${AppName}/${Environment}/s3-logging-kms + TargetKeyId: !Sub ${LoggingBucketKMSKey} + + # LOGGING S3 BUCKET + LoggingBucket: + DeletionPolicy: Retain + UpdateReplacePolicy: Retain + Type: AWS::S3::Bucket + DependsOn: LoggingBucketKMSKey + Metadata: + guard: + SuppressedRules: + - S3_BUCKET_DEFAULT_LOCK_ENABLED + - S3_BUCKET_VERSIONING_ENABLED + - S3_BUCKET_REPLICATION_ENABLED + - S3_BUCKET_LOGGING_ENABLED + Properties: + BucketName: !Sub ${AppName}-logging-${Environment}-${AWS::AccountId}-${AWS::Region} + OwnershipControls: + Rules: + - ObjectOwnership: ObjectWriter + PublicAccessBlockConfiguration: + BlockPublicAcls: true + BlockPublicPolicy: true + IgnorePublicAcls: true + RestrictPublicBuckets: true + AccessControl: LogDeliveryWrite + BucketEncryption: + ServerSideEncryptionConfiguration: + - ServerSideEncryptionByDefault: + KMSMasterKeyID: !GetAtt LoggingBucketKMSKey.Arn + SSEAlgorithm: aws:kms + VersioningConfiguration: + Status: !Ref LoggingBucketVersioning + + # LOGGING S3 BUCKET POLICY + LoggingBucketPolicy: + Type: AWS::S3::BucketPolicy + Properties: + Bucket: !Ref LoggingBucket + PolicyDocument: + Version: "2012-10-17" + Statement: + - Sid: LoggingBucketPermissions + Effect: Allow + Principal: + AWS: !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:root + Action: s3:PutObject + Resource: + - !Sub arn:${AWS::Partition}:s3:::${LoggingBucket}/AWSLogs/${AWS::AccountId}/* + - Action: s3:* + Condition: + Bool: + aws:SecureTransport: false + Effect: Deny + Principal: + AWS: '*' + Resource: + - !Sub arn:${AWS::Partition}:s3:::${LoggingBucket}/AWSLogs/${AWS::AccountId}/* + + # EC2 INSTANCE + EC2Instance: + Type: AWS::EC2::Instance + Properties: + ImageId: !Ref EC2ImageId + InstanceType: !Ref EC2InstanceType + SubnetId: !Ref PublicSubnetId1 + BlockDeviceMappings: + - DeviceName: /dev/sda1 + Ebs: + VolumeSize: !Ref BootVolSize + VolumeType: !Ref BootVolType + SecurityGroupIds: + - !Ref EC2InstanceSG + - !Ref ALBExternalAccessSG + KeyName: !Ref KeyPairName + Tags: + - Key: Name + Value: !Sub ${AppName}-${Environment}-ec2-instance + - Key: Environment + Value: !Ref Environment + + # EC2 INSTANCE SECURITY GROUP + EC2InstanceSG: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: EC2 Instance Security Group + VpcId: !Ref VpcId + Tags: + - Key: Name + Value: !Sub ${AppName}-${Environment}-ec2-instance-SG + - Key: Environment + Value: !Ref Environment + + # SECURITY GROUP INGRESS + Tcp8080In: + Type: AWS::EC2::SecurityGroupIngress + Properties: + GroupId: !Ref EC2InstanceSG + ToPort: "8080" + IpProtocol: tcp + FromPort: "8080" + SourceSecurityGroupId: !Ref ALBExternalAccessSG + + # ORIGIN ALB + OriginALB: + Type: AWS::ElasticLoadBalancingV2::LoadBalancer + Properties: + Name: !Sub ${AppName}-${Environment}-alb + Scheme: !Ref ALBScheme + Type: !Ref ALBType + LoadBalancerAttributes: + - Key: idle_timeout.timeout_seconds + Value: !Ref ALBAttributeIdleTimeOut + - Key: deletion_protection.enabled + Value: !Ref ALBAttributeDeletionProtection + - Key: routing.http2.enabled + Value: !Ref ALBAttributeRoutingHttp2 + Subnets: + - !Ref PublicSubnetId1 + - !Ref PublicSubnetId2 + SecurityGroups: + - !Ref ALBExternalAccessSG + Tags: + - Key: Name + Value: !Sub ${AppName}-${Environment}-alb + - Key: Environment + Value: !Ref Environment + + # ORIGIN ALB TARGET GROUP + OriginALBTG: + Type: AWS::ElasticLoadBalancingV2::TargetGroup + DependsOn: OriginALB + Properties: + Name: !Sub ${AppName}-${Environment}-alb-tg + HealthCheckProtocol: !Ref HealthCheckProtocol + HealthCheckPath: !Ref HealthCheckPath + HealthCheckPort: !Sub ${OriginALBTGPort} + HealthCheckIntervalSeconds: !Ref ALBTargetGroupHealthCheckIntervalSeconds + HealthCheckTimeoutSeconds: !Ref ALBTargetGroupHealthCheckTimeoutSeconds + HealthyThresholdCount: !Ref ALBTargetGroupHealthyThresholdCount + UnhealthyThresholdCount: !Ref ALBTargetGroupUnhealthyThresholdCount + TargetGroupAttributes: + - Key: deregistration_delay.timeout_seconds + Value: !Ref ALBTargetGroupAttributeDeregistration + TargetType: instance + Targets: + - Id: !Ref EC2Instance + Port: !Ref OriginALBTGPort + Port: !Ref OriginALBTGPort + Protocol: HTTP + VpcId: !Ref VpcId + Tags: + - Key: Name + Value: !Sub ${AppName}-${Environment}-alb-tg + - Key: Environment + Value: !Ref Environment + + # ORIGIN ALB HTTPS LISTENER + OriginALBHttpsListener: + Type: AWS::ElasticLoadBalancingV2::Listener + DependsOn: OriginALBTG + Properties: + DefaultActions: + - TargetGroupArn: !Ref OriginALBTG + Type: forward + LoadBalancerArn: !Ref OriginALB + Port: 443 + Protocol: HTTPS + Certificates: + - CertificateArn: !Sub arn:${AWS::Partition}:acm:${AWS::Region}:${AWS::AccountId}:certificate/${ACMCertificateIdentifier} + SslPolicy: ELBSecurityPolicy-FS-2018-06 + + # ORIGIN ALB HTTPS LISTENER RULE + OriginALBHttpsListenerRule: + Type: AWS::ElasticLoadBalancingV2::ListenerRule + DependsOn: OriginALBHttpsListener + Properties: + Actions: + - Type: forward + TargetGroupArn: !Ref OriginALBTG + Conditions: + - Field: path-pattern + Values: + - /* + ListenerArn: !Ref OriginALBHttpsListener + Priority: 1 + + # ALB EXTERNAL ACCESS SECURITY GROUP + ALBExternalAccessSG: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Allow external access to ALB + VpcId: !Ref VpcId + Tags: + - Key: Name + Value: !Sub ${AppName}-${Environment}-alb-external-access-ingrees-SG + - Key: Environment + Value: !Ref Environment + + # SECURITY GROUP INGRESS + HTTPSTcpIn: + Type: AWS::EC2::SecurityGroupIngress + Properties: + GroupId: !Ref ALBExternalAccessSG + ToPort: 443 + IpProtocol: tcp + FromPort: 443 + CidrIp: 0.0.0.0/0 + + HTTPTcpIn: + Type: AWS::EC2::SecurityGroupIngress + Properties: + GroupId: !Ref ALBExternalAccessSG + ToPort: 80 + IpProtocol: tcp + FromPort: 80 + CidrIp: 0.0.0.0/0 + + # SECURITY GROUP EGRESS + Tcp8080Out: + Type: AWS::EC2::SecurityGroupEgress + Properties: + GroupId: !Ref ALBExternalAccessSG + ToPort: 8080 + IpProtocol: tcp + FromPort: 8080 + DestinationSecurityGroupId: !Ref EC2InstanceSG + + # CLOUDFRONT DISTRIBUTION + CloudFrontDistribution: + Type: AWS::CloudFront::Distribution + DependsOn: + - LoggingBucket + - LambdaEdgeFunction + Properties: + DistributionConfig: + Comment: Cloudfront Distribution pointing ALB Origin + Origins: + - DomainName: !GetAtt OriginALB.DNSName + Id: !Ref OriginALB + CustomOriginConfig: + HTTPPort: 80 + HTTPSPort: 443 + OriginProtocolPolicy: !Ref OriginProtocolPolicy + OriginKeepaliveTimeout: !Ref OriginKeepaliveTimeout + OriginReadTimeout: !Ref OriginReadTimeout + OriginSSLProtocols: + - TLSv1 + - TLSv1.1 + - TLSv1.2 + - SSLv3 + Enabled: true + HttpVersion: http2 + Aliases: + - !Ref AlternateDomainNames + DefaultCacheBehavior: + AllowedMethods: + - GET + - HEAD + - DELETE + - OPTIONS + - PATCH + - POST + - PUT + Compress: !Ref Compress + DefaultTTL: !Ref DefaultTTL + MaxTTL: !Ref MaxTTL + MinTTL: !Ref MinTTL + SmoothStreaming: "false" + TargetOriginId: !Ref OriginALB + ForwardedValues: + QueryString: !Ref QueryString + Cookies: + Forward: !Ref ForwardCookies + ViewerProtocolPolicy: !Ref ViewerProtocolPolicy + LambdaFunctionAssociations: + - EventType: !Ref LambdaEventType + LambdaFunctionARN: !Ref LambdaEdgeVersion + PriceClass: !Ref PriceClass + ViewerCertificate: + AcmCertificateArn: !Sub arn:${AWS::Partition}:acm:${AWS::Region}:${AWS::AccountId}:certificate/${ACMCertificateIdentifier} + SslSupportMethod: !Ref SslSupportMethod + MinimumProtocolVersion: !Ref MinimumProtocolVersion + IPV6Enabled: !Ref IPV6Enabled + Logging: + Bucket: !Sub ${LoggingBucket}.s3.amazonaws.com + + # LAMBDA@EDGE FUNCTION + LambdaEdgeFunction: + Type: AWS::Lambda::Function + Metadata: + guard: + SuppressedRules: + - LAMBDA_INSIDE_VPC + Properties: + Description: A custom Lambda@Edge function for serving custom headers from CloudFront Distribution + FunctionName: !Sub ${AppName}-lambda-edge-${Environment} + Handler: index.handler + Role: !GetAtt LambdaEdgeIAMRole.Arn + MemorySize: 128 + Timeout: 5 + Code: + ZipFile: | + 'use strict'; + + exports.handler = (event, context, callback) => { + console.log('Adding additional headers to CloudFront response.'); + + const response = event.Records[0].cf.response; + response.headers['strict-transport-security'] = [{ + key: 'Strict-Transport-Security', + value: 'max-age=86400; includeSubdomains; preload', + }]; + response.headers['x-content-type-options'] = [{ + key: 'X-Content-Type-Options', + value: 'nosniff', + }]; + response.headers['x-frame-options'] = [{ + key: 'X-Frame-Options', + value: "DENY" + }]; + response.headers['content-security-policy'] = [{ + key: 'Content-Security-Policy', + value: "default-src 'none'; img-src 'self'; script-src 'self'; style-src 'self'; object-src 'none'" + }]; + response.headers['x-xss-protection'] = [{ + key: 'X-XSS-Protection', + value: "1; mode=block" + }]; + response.headers['referrer-policy'] = [{ + key: 'Referrer-Policy', + value: "same-origin" + }]; + callback(null, response); + }; + Runtime: nodejs20.x + + LambdaEdgeVersion: + Type: AWS::Lambda::Version + Properties: + FunctionName: !Ref LambdaEdgeFunction + +Outputs: + AdministratorAccessIAMRole: + Description: Administrator Access IAM Role + Value: !Ref AdministratorAccessIAMRole + Export: + Name: !Sub ${AppName}-iam-${Environment}-administrator-access-role + + LoggingBucket: + Description: Name of S3 Logging bucket + Value: !Ref LoggingBucket + Export: + Name: !Sub ${AppName}-logging-${Environment}-${AWS::AccountId}-${AWS::Region} + + LoggingBucketKMSKey: + Description: Logging Bucket KMS Key + Value: !Ref LoggingBucketKMSKey + Export: + Name: !Sub ${AppName}-${Environment}-s3-logging-kms + + OriginALB: + Description: The URL of the Origin ALB + Value: !GetAtt OriginALB.DNSName + Export: + Name: !Sub ${AppName}-${Environment}-origin-alb-dns + + ALBExternalAccessSGID: + Description: ALB External Access Security Group ID + Value: !Ref ALBExternalAccessSG + Export: + Name: !Sub ${AppName}-${Environment}-alb-external-access-ingrees-sg + + EC2InstanceSGID: + Description: EC2 Instance Security Group ID + Value: !Ref EC2InstanceSG + Export: + Name: !Sub ${AppName}-${Environment}-ec2-instance-sg + + EC2InstanceDNS: + Description: EC2 Instance DNS Name + Value: !GetAtt EC2Instance.PrivateDnsName + Export: + Name: !Sub ${AppName}-${Environment}-ec2-instance-dns + + EC2InstanceIP: + Description: EC2 Instance IP Address + Value: !GetAtt EC2Instance.PrivateIp + Export: + Name: !Sub ${AppName}-${Environment}-ec2-instance-ip-address + + EC2InstanceID: + Description: EC2 Instance Instance ID + Value: !Ref EC2Instance + Export: + Name: !Sub ${AppName}-${Environment}-ec2-instance-id + + CloudFrontEndpoint: + Description: Endpoint for Cloudfront Distribution + Value: !Ref CloudFrontDistribution + Export: + Name: !Sub ${AppName}-${Environment}-cloudfront-distribution + + AlternateDomainNames: + Description: Alternate Domain Names (CNAME) + Value: !Ref AlternateDomainNames + + LambdaEdgeFunction: + Description: The Name of the Lambda@Edge Function + Value: LambdaEdgeFunction + Export: + Name: !Sub ${AppName}-${Environment}-lambda-edge-function-3 + + LambdaEdgeFunctionARN: + Description: The ARN of the Lambda@Edge Function + Value: !GetAtt LambdaEdgeFunction.Arn + Export: + Name: !Sub ${AppName}-${Environment}-lambda-edge-function-arn-3 + + LambdaEdgeVersion: + Description: Lambda@Edge Version Function + Value: !GetAtt LambdaEdgeVersion.Version diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFrontCustomOriginLambda@Edge/LICENSE.txt b/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFrontCustomOriginLambda@Edge/LICENSE.txt new file mode 100644 index 0000000000000000000000000000000000000000..fc06cc4fe49b44e11bec7337390c85c509bfb4d7 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFrontCustomOriginLambda@Edge/LICENSE.txt @@ -0,0 +1,14 @@ +MIT No Attribution + +Permission is hereby granted, free of charge, to any person obtaining a copy of this +software and associated documentation files (the "Software"), to deal in the Software +without restriction, including without limitation the rights to use, copy, modify, +merge, publish, distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFrontCustomOriginLambda@Edge/README.md b/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFrontCustomOriginLambda@Edge/README.md new file mode 100644 index 0000000000000000000000000000000000000000..9bf010ecc4b089aad2513abbb91d925e0ed244a1 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/CloudFrontCustomOriginLambda@Edge/README.md @@ -0,0 +1,30 @@ +# Create an AWS CloudFront Distribution with Custom Origin (ALB) and Lambda@Edge Example + +## Issue +AWS CloudFront distribution with custom origin with AWS Lambda@Edge provisioning requires a lot of manual steps. + +## Short Description +CI/CD optimized AWS CloudFormation Sample Template for AWS CloudFront Distribution with Custom Origin with an example of using the AWS Application Load Balancer (ALB) and a basic Amazon EC2 Instance. AWS CloudFront Distribution is associated with Lambda@Edge for Security Headers inspection. In addition, AWS CloudFormation Template will provision an Examples of necessary IAM, S3, KMS and Security Groups resources. + +## Resolution +Using this AWS CloudFormation Template Example enables CI/CD optimized and automated deployment of all necessary components while provides the flexibility with variety of defined variables. + +## Instructions + +The following steps provide a brief overview of this process: + * Upload certificate to AWS Amazon Certificate Manager (ACM) in N.Virginia Region. + * Review provided Parameters and set values that match your use case. + * While creating the CloudFormation stack, please make sure to select the following networking parameter values from the dropdown in Parameters section: + + - **VpcId:** Select a VPC ID + - **PublicSubnetId1:** Select the first public subnet from the above VPC + - **PublicSubnetId2:** Select the second public subnet from the above VPC + - **KeyPairName:** Select an EC2 Key Pair + + * Expand solution with additional resources as AutoScaling, etc. that match your use case + +## Builders + +# Nikola Bravo: @NikolaBravo +# Rohit Rangnekar: @rrangnekar +# Anubha Singhal: @anubha16 diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/CodeBuildAndCodePipeline/cloudformation-codebuild-template.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/CodeBuildAndCodePipeline/cloudformation-codebuild-template.json new file mode 100644 index 0000000000000000000000000000000000000000..65703c73a58166e43fe7ac476f8c1a960f5fb59b --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/CodeBuildAndCodePipeline/cloudformation-codebuild-template.json @@ -0,0 +1,348 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "Deploys the prequisites for creating required code pipelines this includes \n", + "Parameters": { + "DockerImage": { + "Description": "Docker image to use for the build phase", + "Type": "String", + "Default": "aws/codebuild/standard:7.0" + } + }, + "Resources": { + "CodeCommitRepo": { + "Type": "AWS::CodeCommit::Repository", + "Properties": { + "RepositoryName": { + "Fn::Sub": "${AWS::StackName}-repo" + }, + "RepositoryDescription": { + "Fn::Sub": "This is a repository for the ${AWS::StackName} project." + } + } + }, + "PipelineS3Bucket": { + "Type": "AWS::S3::Bucket", + "Metadata": { + "guard": { + "SuppressedRules": [ + "S3_BUCKET_DEFAULT_LOCK_ENABLED", + "S3_BUCKET_REPLICATION_ENABLED", + "S3_BUCKET_VERSIONING_ENABLED", + "S3_BUCKET_LOGGING_ENABLED" + ] + } + }, + "Properties": { + "BucketName": { + "Fn::Sub": "${AWS::StackName}-bucket" + }, + "BucketEncryption": { + "ServerSideEncryptionConfiguration": [ + { + "ServerSideEncryptionByDefault": { + "SSEAlgorithm": "AES256" + } + } + ] + }, + "PublicAccessBlockConfiguration": { + "BlockPublicAcls": true, + "BlockPublicPolicy": true, + "IgnorePublicAcls": true, + "RestrictPublicBuckets": true + } + } + }, + "CodeBuildRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Effect": "Allow", + "Action": "sts:AssumeRole", + "Principal": { + "Service": "codebuild.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyName": "CanLog", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "logs:CreateLogStream", + "logs:CreateLogGroup", + "logs:PutLogEvents" + ], + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/codebuild/${AWS::StackName}*:log-stream:*" + } + ] + }, + { + "Effect": "Allow", + "Action": [ + "s3:GetObject", + "s3:PutObject" + ], + "Resource": [ + { + "Fn::GetAtt": [ + "PipelineS3Bucket", + "Arn" + ] + }, + { + "Fn::Sub": "${PipelineS3Bucket.Arn}/*" + } + ] + } + ] + } + }, + { + "PolicyName": "CanAccessS3", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "s3:GetObject" + ], + "Resource": [ + { + "Fn::GetAtt": [ + "PipelineS3Bucket", + "Arn" + ] + } + ] + } + ] + } + }, + { + "PolicyName": "CanCreateReports", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "codebuild:*" + ], + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:codebuild:${AWS::Region}:${AWS::AccountId}:report-group/${AWS::StackName}*" + } + ] + } + ] + } + } + ] + } + }, + "AppBuild": { + "Type": "AWS::CodeBuild::Project", + "Properties": { + "Name": { + "Fn::Sub": "${AWS::StackName}-app-build" + }, + "Artifacts": { + "Type": "CODEPIPELINE", + "EncryptionDisabled": true + }, + "Environment": { + "ComputeType": "BUILD_GENERAL1_SMALL", + "EnvironmentVariables": [ + { + "Name": "SAMPLEENVVAR", + "Type": "PLAINTEXT", + "Value": "test" + } + ], + "Image": { + "Ref": "DockerImage" + }, + "Type": "LINUX_CONTAINER" + }, + "ServiceRole": { + "Ref": "CodeBuildRole" + }, + "Source": { + "Type": "CODEPIPELINE", + "BuildSpec": "codebuild-app-build.yml" + } + } + }, + "AppDeploy": { + "Type": "AWS::CodeBuild::Project", + "Properties": { + "Name": { + "Fn::Sub": "${AWS::StackName}-app-deploy" + }, + "Artifacts": { + "Type": "CODEPIPELINE", + "EncryptionDisabled": true + }, + "Environment": { + "ComputeType": "BUILD_GENERAL1_SMALL", + "EnvironmentVariables": [ + { + "Name": "SAMPLEENVVAR", + "Type": "PLAINTEXT", + "Value": "test" + } + ], + "Image": { + "Ref": "DockerImage" + }, + "Type": "LINUX_CONTAINER" + }, + "ServiceRole": { + "Ref": "CodeBuildRole" + }, + "Source": { + "Type": "CODEPIPELINE", + "BuildSpec": "codebuild-app-deploy.yml" + } + } + } + }, + "Outputs": { + "CodeCommitName": { + "Description": "The code commit repository name", + "Value": { + "Fn::GetAtt": [ + "CodeCommitRepo", + "Name" + ] + }, + "Export": { + "Name": { + "Fn::Sub": "${AWS::StackName}-CodeCommitName" + } + } + }, + "CodeCommitArn": { + "Description": "The code commit repository arn", + "Value": { + "Fn::GetAtt": [ + "CodeCommitRepo", + "Arn" + ] + }, + "Export": { + "Name": { + "Fn::Sub": "${AWS::StackName}-CodeCommitArn" + } + } + }, + "PipelineS3Bucket": { + "Description": "The s3 bucket used by the deployment codepipelines", + "Value": { + "Ref": "PipelineS3Bucket" + }, + "Export": { + "Name": { + "Fn::Sub": "${AWS::StackName}-PipelineS3Bucket" + } + } + }, + "PipelineS3BucketArn": { + "Description": "The s3 bucket used by the deployment codepipelines", + "Value": { + "Fn::GetAtt": [ + "PipelineS3Bucket", + "Arn" + ] + }, + "Export": { + "Name": { + "Fn::Sub": "${AWS::StackName}-PipelineS3BucketArn" + } + } + }, + "CodeBuildRole": { + "Description": "IAM Role ARN associated with CodeBuild projects", + "Value": { + "Ref": "CodeBuildRole" + }, + "Export": { + "Name": { + "Fn::Sub": "${AWS::StackName}-CodeBuildRole" + } + } + }, + "CodeBuildRoleArn": { + "Description": "IAM Role ARN associated with CodeBuild projects", + "Value": { + "Fn::GetAtt": [ + "CodeBuildRole", + "Arn" + ] + }, + "Export": { + "Name": { + "Fn::Sub": "${AWS::StackName}-CodeBuildRoleArn" + } + } + }, + "AppDeploy": { + "Value": { + "Ref": "AppDeploy" + }, + "Export": { + "Name": { + "Fn::Sub": "${AWS::StackName}-AppDeploy" + } + } + }, + "AppDeploydArn": { + "Value": { + "Fn::GetAtt": [ + "AppDeploy", + "Arn" + ] + }, + "Export": { + "Name": { + "Fn::Sub": "${AWS::StackName}-AppDeployArn" + } + } + }, + "AppBuild": { + "Value": { + "Ref": "AppBuild" + }, + "Export": { + "Name": { + "Fn::Sub": "${AWS::StackName}-AppBuild" + } + } + }, + "AppBuildArn": { + "Value": { + "Fn::GetAtt": [ + "AppBuild", + "Arn" + ] + }, + "Export": { + "Name": { + "Fn::Sub": "${AWS::StackName}-AppBuildArn" + } + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/CodeBuildAndCodePipeline/cloudformation-codebuild-template.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/CodeBuildAndCodePipeline/cloudformation-codebuild-template.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1ee89f99b46d2b94ae3618d4f19194143b4de654 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/CodeBuildAndCodePipeline/cloudformation-codebuild-template.yaml @@ -0,0 +1,182 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: "Deploys the prequisites for creating required code pipelines this includes \n" + +Parameters: + DockerImage: + Description: Docker image to use for the build phase + Type: String + Default: aws/codebuild/standard:7.0 + +Resources: + CodeCommitRepo: + Type: AWS::CodeCommit::Repository + Properties: + RepositoryName: !Sub ${AWS::StackName}-repo + RepositoryDescription: !Sub This is a repository for the ${AWS::StackName} project. + + PipelineS3Bucket: + Type: AWS::S3::Bucket + Metadata: + guard: + SuppressedRules: + - S3_BUCKET_DEFAULT_LOCK_ENABLED + - S3_BUCKET_REPLICATION_ENABLED + - S3_BUCKET_VERSIONING_ENABLED + - S3_BUCKET_LOGGING_ENABLED + Properties: + BucketName: !Sub ${AWS::StackName}-bucket + BucketEncryption: + ServerSideEncryptionConfiguration: + - ServerSideEncryptionByDefault: + SSEAlgorithm: AES256 + PublicAccessBlockConfiguration: + BlockPublicAcls: true + BlockPublicPolicy: true + IgnorePublicAcls: true + RestrictPublicBuckets: true + + CodeBuildRole: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Statement: + - Effect: Allow + Action: sts:AssumeRole + Principal: + Service: codebuild.amazonaws.com + Version: "2012-10-17" + Policies: + - PolicyName: CanLog + PolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: + - logs:CreateLogStream + - logs:CreateLogGroup + - logs:PutLogEvents + Resource: + - !Sub arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/codebuild/${AWS::StackName}*:log-stream:* + - Effect: Allow + Action: + - s3:GetObject + - s3:PutObject + Resource: + - !GetAtt PipelineS3Bucket.Arn + - !Sub ${PipelineS3Bucket.Arn}/* + - PolicyName: CanAccessS3 + PolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: + - s3:GetObject + Resource: + - !GetAtt PipelineS3Bucket.Arn + - PolicyName: CanCreateReports + PolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: + - codebuild:* + Resource: + - !Sub arn:${AWS::Partition}:codebuild:${AWS::Region}:${AWS::AccountId}:report-group/${AWS::StackName}* + + AppBuild: + Type: AWS::CodeBuild::Project + Properties: + Name: !Sub ${AWS::StackName}-app-build + Artifacts: + Type: CODEPIPELINE + EncryptionDisabled: true + Environment: + ComputeType: BUILD_GENERAL1_SMALL + EnvironmentVariables: + - Name: SAMPLEENVVAR + Type: PLAINTEXT + Value: test + Image: !Ref DockerImage + Type: LINUX_CONTAINER + ServiceRole: !Ref CodeBuildRole + Source: + Type: CODEPIPELINE + BuildSpec: codebuild-app-build.yml + + AppDeploy: + Type: AWS::CodeBuild::Project + Properties: + Name: !Sub ${AWS::StackName}-app-deploy + Artifacts: + Type: CODEPIPELINE + EncryptionDisabled: true + Environment: + ComputeType: BUILD_GENERAL1_SMALL + EnvironmentVariables: + - Name: SAMPLEENVVAR + Type: PLAINTEXT + Value: test + Image: !Ref DockerImage + Type: LINUX_CONTAINER + ServiceRole: !Ref CodeBuildRole + Source: + Type: CODEPIPELINE + BuildSpec: codebuild-app-deploy.yml + +Outputs: + CodeCommitName: + Description: The code commit repository name + Value: !GetAtt CodeCommitRepo.Name + Export: + Name: !Sub ${AWS::StackName}-CodeCommitName + + CodeCommitArn: + Description: The code commit repository arn + Value: !GetAtt CodeCommitRepo.Arn + Export: + Name: !Sub ${AWS::StackName}-CodeCommitArn + + PipelineS3Bucket: + Description: The s3 bucket used by the deployment codepipelines + Value: !Ref PipelineS3Bucket + Export: + Name: !Sub ${AWS::StackName}-PipelineS3Bucket + + PipelineS3BucketArn: + Description: The s3 bucket used by the deployment codepipelines + Value: !GetAtt PipelineS3Bucket.Arn + Export: + Name: !Sub ${AWS::StackName}-PipelineS3BucketArn + + CodeBuildRole: + Description: IAM Role ARN associated with CodeBuild projects + Value: !Ref CodeBuildRole + Export: + Name: !Sub ${AWS::StackName}-CodeBuildRole + + CodeBuildRoleArn: + Description: IAM Role ARN associated with CodeBuild projects + Value: !GetAtt CodeBuildRole.Arn + Export: + Name: !Sub ${AWS::StackName}-CodeBuildRoleArn + + AppDeploy: + Value: !Ref AppDeploy + Export: + Name: !Sub ${AWS::StackName}-AppDeploy + + AppDeploydArn: + Value: !GetAtt AppDeploy.Arn + Export: + Name: !Sub ${AWS::StackName}-AppDeployArn + + AppBuild: + Value: !Ref AppBuild + Export: + Name: !Sub ${AWS::StackName}-AppBuild + + AppBuildArn: + Value: !GetAtt AppBuild.Arn + Export: + Name: !Sub ${AWS::StackName}-AppBuildArn diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/CodeBuildAndCodePipeline/cloudformation-codepipeline-template.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/CodeBuildAndCodePipeline/cloudformation-codepipeline-template.json new file mode 100644 index 0000000000000000000000000000000000000000..ea6243400a3fa7a1e63182adc6202beaa75958e6 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/CodeBuildAndCodePipeline/cloudformation-codepipeline-template.json @@ -0,0 +1,376 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "CodePipeline for continuous integration build and continuous deployment", + "Parameters": { + "CodeBuildStack": { + "Description": "Name of the code build stack which should have been deployed before this stack", + "Type": "String" + } + }, + "Resources": { + "PipelineRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Principal": { + "Service": [ + "codepipeline.amazonaws.com" + ] + }, + "Action": [ + "sts:AssumeRole" + ] + } + ] + }, + "Policies": [ + { + "PolicyName": "CanAccessCodeCommit", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "codecommit:GetBranch", + "codecommit:GetCommit", + "codecommit:UploadArchive", + "codecommit:GetUploadArchiveStatus" + ], + "Resource": [ + { + "Fn::ImportValue": { + "Fn::Sub": "${CodeBuildStack}-CodeCommitArn" + } + } + ] + } + ] + } + }, + { + "PolicyName": "CanAccessS3", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": "s3:ListBucket", + "Resource": "*" + }, + { + "Effect": "Allow", + "Action": [ + "s3:GetObject", + "s3:GetObjectVersion", + "s3:GetBucketVersioning", + "s3:PutObject", + "s3:GetBucketPolicy", + "s3:GetObjectAcl", + "s3:PutObjectAcl", + "s3:DeleteObject" + ], + "Resource": [ + { + "Fn::ImportValue": { + "Fn::Sub": "${CodeBuildStack}-PipelineS3BucketArn" + } + }, + { + "Fn::Sub": [ + "${filename}/*", + { + "filename": { + "Fn::ImportValue": { + "Fn::Sub": "${CodeBuildStack}-PipelineS3BucketArn" + } + } + } + ] + } + ] + } + ] + } + }, + { + "PolicyName": "CanStartCodeBuild", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "codebuild:BatchGetBuilds", + "codebuild:StartBuild" + ], + "Resource": [ + { + "Fn::ImportValue": { + "Fn::Sub": "${CodeBuildStack}-AppBuildArn" + } + }, + { + "Fn::ImportValue": { + "Fn::Sub": "${CodeBuildStack}-AppDeployArn" + } + } + ] + } + ] + } + } + ] + } + }, + "EventRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Principal": { + "Service": [ + "events.amazonaws.com" + ] + }, + "Action": "sts:AssumeRole" + } + ] + }, + "Path": "/", + "Policies": [ + { + "PolicyName": "eb-pipeline-execution", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": "codepipeline:StartPipelineExecution", + "Resource": { + "Fn::Join": [ + "", + [ + "arn:aws:codepipeline:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":", + { + "Ref": "Pipeline" + } + ] + ] + } + } + ] + } + } + ] + } + }, + "EventRule": { + "Type": "AWS::Events::Rule", + "Properties": { + "EventPattern": { + "source": [ + "aws.codecommit" + ], + "detail-type": [ + "CodeCommit Repository State Change" + ], + "resources": [ + { + "Fn::ImportValue": { + "Fn::Sub": "${CodeBuildStack}-CodeCommitArn" + } + } + ], + "detail": { + "event": [ + "referenceCreated", + "referenceUpdated" + ], + "referenceType": [ + "branch" + ], + "referenceName": [ + "main" + ] + } + }, + "Targets": [ + { + "Arn": { + "Fn::Join": [ + "", + [ + "arn:aws:codepipeline:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":", + { + "Ref": "Pipeline" + } + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "EventRole", + "Arn" + ] + }, + "Id": "codepipeline-Pipeline" + } + ] + } + }, + "Pipeline": { + "Type": "AWS::CodePipeline::Pipeline", + "Properties": { + "Name": { + "Fn::Sub": "${AWS::StackName}-Code-Pipeline" + }, + "ArtifactStore": { + "Type": "S3", + "Location": { + "Fn::ImportValue": { + "Fn::Sub": "${CodeBuildStack}-PipelineS3Bucket" + } + } + }, + "RestartExecutionOnUpdate": false, + "RoleArn": { + "Fn::GetAtt": [ + "PipelineRole", + "Arn" + ] + }, + "Stages": [ + { + "Name": "Source", + "Actions": [ + { + "Name": "Source", + "ActionTypeId": { + "Category": "Source", + "Owner": "AWS", + "Provider": "CodeCommit", + "Version": 1 + }, + "Configuration": { + "RepositoryName": { + "Fn::ImportValue": { + "Fn::Sub": "${CodeBuildStack}-CodeCommitName" + } + }, + "BranchName": "main", + "PollForSourceChanges": false + }, + "OutputArtifacts": [ + { + "Name": "Source" + } + ] + } + ] + }, + { + "Name": "Build-AppBuild", + "Actions": [ + { + "Name": "App-Build", + "ActionTypeId": { + "Category": "Build", + "Owner": "AWS", + "Provider": "CodeBuild", + "Version": 1 + }, + "Configuration": { + "ProjectName": { + "Fn::ImportValue": { + "Fn::Sub": "${CodeBuildStack}-AppBuild" + } + } + }, + "InputArtifacts": [ + { + "Name": "Source" + } + ], + "OutputArtifacts": [ + { + "Name": "FullZip" + } + ], + "RunOrder": 1 + } + ] + }, + { + "Name": "Deploy-App", + "Actions": [ + { + "Name": "Approval", + "ActionTypeId": { + "Category": "Approval", + "Owner": "AWS", + "Provider": "Manual", + "Version": 1 + }, + "Configuration": { + "CustomData": "Review the build output and approve to deploy" + }, + "RunOrder": 2 + }, + { + "Name": "App-Deploy", + "ActionTypeId": { + "Category": "Build", + "Owner": "AWS", + "Provider": "CodeBuild", + "Version": 1 + }, + "Configuration": { + "ProjectName": { + "Fn::ImportValue": { + "Fn::Sub": "${CodeBuildStack}-AppDeploy" + } + }, + "PrimarySource": "Source", + "EnvironmentVariables": "[{\"name\":\"ENVIRONMENT\",\"value\":\"SampleEnv\",\"type\":\"PLAINTEXT\"}]" + }, + "InputArtifacts": [ + { + "Name": "Source" + }, + { + "Name": "FullZip" + } + ], + "RunOrder": 3 + } + ] + } + ] + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/CodeBuildAndCodePipeline/cloudformation-codepipeline-template.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/CodeBuildAndCodePipeline/cloudformation-codepipeline-template.yaml new file mode 100644 index 0000000000000000000000000000000000000000..70b67eea18c8fb1e419a29090ce1fb3219d35713 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/CodeBuildAndCodePipeline/cloudformation-codepipeline-template.yaml @@ -0,0 +1,192 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: CodePipeline for continuous integration build and continuous deployment + +Parameters: + CodeBuildStack: + Description: Name of the code build stack which should have been deployed before this stack + Type: String + +Resources: + PipelineRole: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Principal: + Service: + - codepipeline.amazonaws.com + Action: + - sts:AssumeRole + Policies: + - PolicyName: CanAccessCodeCommit + PolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: + - codecommit:GetBranch + - codecommit:GetCommit + - codecommit:UploadArchive + - codecommit:GetUploadArchiveStatus + Resource: + - !ImportValue + Fn::Sub: ${CodeBuildStack}-CodeCommitArn + + # - !Sub "arn:aws:codecommit:${AWS::Region}:${AWS::AccountId}:${RepositoryName}/*" + - PolicyName: CanAccessS3 + PolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: s3:ListBucket + Resource: '*' + - Effect: Allow + Action: + - s3:GetObject + - s3:GetObjectVersion + - s3:GetBucketVersioning + - s3:PutObject + - s3:GetBucketPolicy + - s3:GetObjectAcl + - s3:PutObjectAcl + - s3:DeleteObject + Resource: + - !ImportValue + Fn::Sub: ${CodeBuildStack}-PipelineS3BucketArn + - !Sub + - ${filename}/* + - filename: !ImportValue + Fn::Sub: ${CodeBuildStack}-PipelineS3BucketArn + - PolicyName: CanStartCodeBuild + PolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: + - codebuild:BatchGetBuilds + - codebuild:StartBuild + Resource: + - !ImportValue + Fn::Sub: ${CodeBuildStack}-AppBuildArn + - !ImportValue + Fn::Sub: ${CodeBuildStack}-AppDeployArn + + EventRole: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Version: 2012-10-17 + Statement: + - + Effect: Allow + Principal: + Service: + - events.amazonaws.com + Action: sts:AssumeRole + Path: / + Policies: + - + PolicyName: eb-pipeline-execution + PolicyDocument: + Version: 2012-10-17 + Statement: + - + Effect: Allow + Action: codepipeline:StartPipelineExecution + Resource: !Join [ '', [ 'arn:aws:codepipeline:', !Ref 'AWS::Region', ':', !Ref 'AWS::AccountId', ':', !Ref Pipeline ] ] + EventRule: + Type: AWS::Events::Rule + Properties: + EventPattern: + source: + - aws.codecommit + detail-type: + - 'CodeCommit Repository State Change' + resources: + - !ImportValue + Fn::Sub: ${CodeBuildStack}-CodeCommitArn + detail: + event: + - referenceCreated + - referenceUpdated + referenceType: + - branch + referenceName: + - main + Targets: + - + Arn: + !Join [ '', [ 'arn:aws:codepipeline:', !Ref 'AWS::Region', ':', !Ref 'AWS::AccountId', ':', !Ref Pipeline ] ] + RoleArn: !GetAtt EventRole.Arn + Id: codepipeline-Pipeline + Pipeline: + Type: AWS::CodePipeline::Pipeline + Properties: + Name: !Sub ${AWS::StackName}-Code-Pipeline + ArtifactStore: + Type: S3 + Location: !ImportValue + Fn::Sub: ${CodeBuildStack}-PipelineS3Bucket + RestartExecutionOnUpdate: false + RoleArn: !GetAtt PipelineRole.Arn + Stages: + - Name: Source + Actions: + - Name: Source + ActionTypeId: + Category: Source + Owner: AWS + Provider: CodeCommit + Version: 1 + Configuration: + RepositoryName: !ImportValue + Fn::Sub: ${CodeBuildStack}-CodeCommitName + BranchName: main + PollForSourceChanges: false + OutputArtifacts: + - Name: Source + - Name: Build-AppBuild + Actions: + - Name: App-Build + ActionTypeId: + Category: Build + Owner: AWS + Provider: CodeBuild + Version: 1 + Configuration: + ProjectName: !ImportValue + Fn::Sub: ${CodeBuildStack}-AppBuild + InputArtifacts: + - Name: Source + OutputArtifacts: + - Name: FullZip + RunOrder: 1 + - Name: Deploy-App + Actions: + - Name: Approval + ActionTypeId: + Category: Approval + Owner: AWS + Provider: Manual + Version: 1 + Configuration: + CustomData: Review the build output and approve to deploy + RunOrder: 2 + - Name: App-Deploy + ActionTypeId: + Category: Build + Owner: AWS + Provider: CodeBuild + Version: 1 + Configuration: + ProjectName: !ImportValue + Fn::Sub: ${CodeBuildStack}-AppDeploy + PrimarySource: Source + EnvironmentVariables: '[{"name":"ENVIRONMENT","value":"SampleEnv","type":"PLAINTEXT"}]' + InputArtifacts: + - Name: Source + - Name: FullZip + RunOrder: 3 diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/CodeBuildAndCodePipeline/codebuild-app-build.yml b/human_reference_dataset/aws-cloudformation-templates/Solutions/CodeBuildAndCodePipeline/codebuild-app-build.yml new file mode 100644 index 0000000000000000000000000000000000000000..e51daa911bbb0a727b22e4f4b73bd65cb74a259f --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/CodeBuildAndCodePipeline/codebuild-app-build.yml @@ -0,0 +1,38 @@ +version: 0.2 + +env: + variables: + SampleRepository: https://github.com/aws-samples/serverless-test-samples.git + RelativePathToProject: "serverless-test-samples/dotnet-test-samples/apigw-lambda-ddb/src/GetProduct/GetProduct.csproj" + RelativePathToTestProject: "serverless-test-samples/dotnet-test-samples/apigw-lambda-ddb/tests/ApiTests.UnitTest" + OutputLocation: "output/src/lambda/sample-lambda-code.zip" +phases: + install: + runtime-versions: + dotnet: 8.0 + + pre_build: + commands: + - git clone $SampleRepository + - dotnet restore $RelativePathToProject + build: + commands: + - dotnet publish $RelativePathToProject -c Release -r linux-x64 -o ./publish_output + - dotnet test $RelativePathToTestProject -c Release --logger trx --results-directory ./testresults + post_build: + commands: + - cd publish_output + - zip -q -r $CODEBUILD_SRC_DIR/app.zip . + +artifacts: + files: + - $CODEBUILD_SRC_DIR/app.zip + name: $AWS_REGION-$(date +%Y-%m-%d)/$CODEBUILD_BUILD_NUMBER + discard-paths: no + +reports: + MiltonTests: + file-format: VisualStudioTrx + files: + - "**/*" + base-directory: "./testresults" diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/CodeBuildAndCodePipeline/codebuild-app-deploy.yml b/human_reference_dataset/aws-cloudformation-templates/Solutions/CodeBuildAndCodePipeline/codebuild-app-deploy.yml new file mode 100644 index 0000000000000000000000000000000000000000..8f428119d644555aed69da3b2a7abfb54b0963c9 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/CodeBuildAndCodePipeline/codebuild-app-deploy.yml @@ -0,0 +1,14 @@ +version: 0.2 + +env: + variables: + ENVIRONMENT: "Locally_Set_Environment" + +phases: + pre_build: + commands: + - echo $ENVIRONMENT + - echo $SAMPLEENVVAR + build: + commands: + - echo "Put build commands here" diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/CodeBuildAndCodePipeline/readme.md b/human_reference_dataset/aws-cloudformation-templates/Solutions/CodeBuildAndCodePipeline/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..8f3e42aeb0d20abfd3035854ff3ca8136bce39bd --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/CodeBuildAndCodePipeline/readme.md @@ -0,0 +1,130 @@ +# Deploying CodeBuild and CodePipeline with CloudFormation + +Managing the AWS developer tools with cloud formation helps speed up initial +environment and deployment setup processes. This example deploys a CodeCommit +Repository, two CodeBuild jobs, and then creates a CodePipeline which uses +continuous integration to run any time changes are pushed to the code commit +repository. The templates provided can be expanded to create multiple CodeBuild +jobs or add additional environments to the CodePipeline stages. Using these +CloudFormation templates will be considerably faster than working through the +required menus to deploy the jobs and pipelines through the AWS console. + +## Cloud Formation Templates + +This example contains two CloudFormation templates. + +### codebuild-template.yaml + +This template must be deployed first as the cloudformation-codepipeline-template +has dependencies on the output of this template. This template deploys the +following resources + +- An S3 storage account for holding build artifacts +- App-build CodeBuild project for running scripts and commands to build the + application +- App-deploy CodeBuild Project for running scripts and commands to deploy the + application +- Required IAM roles for the codebuild to create logs in cloudwatch and s3, + create objects in s3, and create reports + +## fullcd-codepipeline-template.yml + +This template deploys the pipeline which is triggered on a commit to main. It +has 3 stages + +1. app-build stage - executes the app-build CodeBuild job +2. Manual approval stage - requires manual approval +3. app-deploy stage - executes the app-deploy CodeBuild job + +## Deploying and Testing + +The following steps will use the +[AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html) +to deploy the cloud formation templates. If you are unfamiliar with using the +AWS CLI, you can execute the steps using the AWS console CloudFormation +deployment. + +1. Set required variables + +``` +codebuild_stackname="cf-sample-codebuild" +codepipeline_stackName="cf-sample-codepipeline" +codebuild_template="cloudformation-codebuild-template.yaml" +codepipeline_template="cloudformation-codepipeline-template.yaml" +``` + +2. Deploy the CodeBuild cloud formation template + `aws cloudformation create-stack --stack-name $codebuild_stackname --template-body file://$codebuild_template --capabilities CAPABILITY_NAMED_IAM` + 1. Clone the newly created code commit repository to a local folder. Replace + repositoryCloneUrl with the HTTPs URL provided through CodeCommit + `git clone ` + 2. Add these files from this sample to the new repository (Copy and paste into + the clone repository directory). This is required because CodeBuild needs to + have a path to the CodeBuild spec files before it can run them + 3. Deploy the codepipeline + `aws cloudformation create-stack --stack-name $codepipeline_stackName --template-body file://$codepipeline_template --parameters ParameterKey=CodeBuildStack,ParameterValue=$codebuild_stackname --capabilities CAPABILITY_NAMED_IAM` + 4. Update the readme or add a new file and push the changes to the main branch + to trigger a pipeline execution + +The cloud formation templates can also be deployed using the AWS console. + +## Cleanup + +Execute the following cloud formation commands to remove the created resources. +These resoources can also be removed through the AWS console + +1. Empty the created S3 bucket + `aws s3 rm s3://${codebuild_stackname}-bucket --recursive` +2. Execute the following AWS CLI commands to remove the created resources + +``` +aws cloudformation delete-stack --stack-name $codepipeline_stackName +aws cloudformation delete-stack --stack-name $codebuild_stackname +``` + +## Usage + +- Leverage these templates as a starting point for creating CodePipelines with + CodeBuild stages +- Create additional CodeBuild jobs for new environments in your application +- Use the sample reporting to see how test metrics are reported in CodeBuild + jobs + +## Authors + +[Austin Mleziva](https://github.com/mleziva) - AWS Professional Services Cloud +Application Architect + +## Appendix + +### Command Reference + +#### Setting Names + +``` +codebuild_stackname="cf-sample-codebuild" +codepipeline_stackName="cf-sample-codepipeline" +codebuild_template="cloudformation-codebuild-template.yaml" +codepipeline_template="cloudformation-codepipeline-template.yaml" +``` + +#### Creating Deployment Resources + +``` +aws cloudformation create-stack --stack-name $codebuild_stackname --template-body file://$codebuild_template --capabilities CAPABILITY_NAMED_IAM +aws cloudformation create-stack --stack-name $codepipeline_stackName --template-body file://$codepipeline_template --parameters ParameterKey=CodeBuildStack,ParameterValue=$codebuild_stackname --capabilities CAPABILITY_NAMED_IAM +``` + +#### Updating Deployment Resources + +``` +aws cloudformation update-stack --stack-name $codebuild_stackname --template-body file://$codebuild_template --capabilities CAPABILITY_NAMED_IAM +aws cloudformation update-stack --stack-name $codepipeline_stackName --template-body file://$codepipeline_template --parameters ParameterKey=CodeBuildStack,ParameterValue=$codebuild_stackname --capabilities CAPABILITY_NAMED_IAM +``` + +#### Deleting Deployment Resources + +``` +aws cloudformation delete-stack --stack-name $codepipeline_stackName +aws cloudformation delete-stack --stack-name $codebuild_stackname +``` diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/DirectoryADClients/DIRECTORY-AD-CLIENTS.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/DirectoryADClients/DIRECTORY-AD-CLIENTS.json new file mode 100644 index 0000000000000000000000000000000000000000..3fa14c22b3f712809aa846394827ac985f8457ba --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/DirectoryADClients/DIRECTORY-AD-CLIENTS.json @@ -0,0 +1,864 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "This template creates (1) Linux and (3) Windows EC2 instances and joins them to Active Directory using the 'AWS-JoinDirectoryServiceDomain' SSM document via AD Connector or AWS Managed AD directory. By default, it relies on the DNS servers being used by the EC2 instances knowing how to resolve the AD domain (i.e., Route 53 Resolvers, DHCP OptionsSet), with an option to set the DNS servers manually on the EC2 instances, as necessary. Several methods used to initiate the domain join (1) Windows EC2 instance with inline SSM association (2) Windows and Linux EC2 instance with SSM association targeting EC2 instance IDs (3) Windows EC2 instance with SSM association targeting EC2 instance tags", + "Metadata": { + "AWS::CloudFormation::Interface": { + "ParameterGroups": [ + { + "Label": { + "default": "Network Configuration" + }, + "Parameters": [ + "PrivateSubnet1ID", + "PrivateSubnet2ID" + ] + }, + { + "Label": { + "default": "EC2 Instance Configuration" + }, + "Parameters": [ + "DomainMembersInstanceType", + "DomainMember1NetBIOSName", + "DomainMember2NetBIOSName", + "DomainMember3NetBIOSName", + "DomainMember4NetBIOSName", + "KeyPairName", + "DomainMembersLinuxInstanceProfile", + "DomainMembersWindowsInstanceProfile", + "DomainMembersSGID", + "EBSKMSKey", + "AMAZONLINUX2", + "WINFULLBASE", + "SSMLogsBucketName" + ] + }, + { + "Label": { + "default": "Directory Services Configuration" + }, + "Parameters": [ + "DirectoryID", + "DirectoryName", + "DomainDNSServer1", + "DomainDNSServer2", + "DomainDNSServer3", + "DomainDNSServer4" + ] + } + ], + "ParameterLabels": { + "AMAZONLINUX2": { + "default": "SSM Parameter Value for Lastest Amazon Linux 2 AMI ID" + }, + "DirectoryID": { + "default": "ID of the Directory (e.g., d-906764663a)" + }, + "DirectoryName": { + "default": "Directory Name" + }, + "DomainDNSServer1": { + "default": "Domain DNS Server 1" + }, + "DomainDNSServer2": { + "default": "Domain DNS Server 2" + }, + "DomainDNSServer3": { + "default": "Domain DNS Server 3" + }, + "DomainDNSServer4": { + "default": "Domain DNS Server 4" + }, + "DomainMember1NetBIOSName": { + "default": "Domain Member 1 NetBIOS Name" + }, + "DomainMember2NetBIOSName": { + "default": "Domain Member 2 NetBIOS Name" + }, + "DomainMember3NetBIOSName": { + "default": "Domain Member 3 NetBIOS Name" + }, + "DomainMember4NetBIOSName": { + "default": "Domain Member 4 NetBIOS Name" + }, + "DomainMembersInstanceType": { + "default": "Domain Members Instance Type" + }, + "DomainMembersSGID": { + "default": "Domain Members Security Group" + }, + "DomainMembersLinuxInstanceProfile": { + "default": "Domain Member Linux InstanceProfile" + }, + "DomainMembersWindowsInstanceProfile": { + "default": "Domain Member Windows InstanceProfile" + }, + "EBSKMSKey": { + "default": "Amazon EBS Volume KMS Key" + }, + "KeyPairName": { + "default": "Key Pair Name" + }, + "PrivateSubnet1ID": { + "default": "Private Subnet 1 ID" + }, + "PrivateSubnet2ID": { + "default": "Private Subnet 2 ID" + }, + "SSMLogsBucketName": { + "default": "SSM Logs Bucket Name" + }, + "WINFULLBASE": { + "default": "SSM Parameter Value for Lastest Windows AMI ID" + } + } + } + }, + "Parameters": { + "AMAZONLINUX2": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-ebs" + }, + "DirectoryID": { + "Description": "Directory ID", + "Type": "String", + "AllowedPattern": "^d-[0-9a-f]{10}$" + }, + "DirectoryName": { + "Description": "Fully qualified name of the on-premises directory, such as corp.example.com", + "Type": "String", + "AllowedPattern": "[a-zA-Z0-9-]+\\..+", + "MaxLength": 25, + "MinLength": 3 + }, + "DomainDNSServer1": { + "Description": "(Optional) Domain DNS Server 1. If DNS servers are not set, then you need to ensure the DNS servers the EC2 instances are using can resolve the AD domain.", + "Type": "String", + "AllowedPattern": "^$|^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$" + }, + "DomainDNSServer2": { + "Description": "(Optional) Domain DNS Server 2. If DNS servers are not set, then you need to ensure the DNS servers the EC2 instances are using can resolve the AD domain.", + "Type": "String", + "AllowedPattern": "^$|^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$" + }, + "DomainDNSServer3": { + "Description": "(Optional) Domain DNS Server 3. If DNS servers are not set, then you need to ensure the DNS servers the EC2 instances are using can resolve the AD domain.", + "Type": "String", + "AllowedPattern": "^$|^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$" + }, + "DomainDNSServer4": { + "Description": "(Optional) Domain DNS Server 4. If DNS servers are not set, then you need to ensure the DNS servers the EC2 instances are using can resolve the AD domain.", + "Type": "String", + "AllowedPattern": "^$|^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$" + }, + "DomainMember1NetBIOSName": { + "Description": "NetBIOS name of Domain Member 1 (using inline SSM association). Note, if computer name existed in AD before, delete from AD first.", + "Type": "String", + "Default": "SERVER1", + "AllowedPattern": "[a-zA-Z0-9-]+", + "MaxLength": 15, + "MinLength": 1 + }, + "DomainMember2NetBIOSName": { + "Description": "NetBIOS name of Domain Member 2 (using SSM association via instance id). Note, if computer name existed in AD before, delete from AD first.", + "Type": "String", + "Default": "SERVER2", + "AllowedPattern": "[a-zA-Z0-9-]+", + "MaxLength": 15, + "MinLength": 1 + }, + "DomainMember3NetBIOSName": { + "Description": "NetBIOS name of Domain Member 3 (using SSM association via tag). Note, if computer name existed in AD before, delete from AD first.", + "Type": "String", + "Default": "SERVER3", + "AllowedPattern": "[a-zA-Z0-9-]+", + "MaxLength": 15, + "MinLength": 1 + }, + "DomainMember4NetBIOSName": { + "Description": "NetBIOS name of Domain Member 4 (AmazonLinux2)", + "Type": "String", + "Default": "SERVER4", + "AllowedPattern": "[a-zA-Z0-9-]+", + "MaxLength": 15, + "MinLength": 1 + }, + "DomainMembersInstanceType": { + "Description": "Amazon EC2 instance type for the AD Server instances", + "Type": "String", + "AllowedValues": [ + "t3.medium", + "t3.large" + ], + "Default": "t3.medium" + }, + "DomainMembersLinuxInstanceProfile": { + "Description": "Existing IAM InstanceProfile with Linux EC2 seamless join domain rights", + "Type": "String", + "AllowedPattern": "[\\w+=,.@-]+" + }, + "DomainMembersWindowsInstanceProfile": { + "Description": "Existing IAM InstanceProfile with Windows EC2 seamless join domain rights", + "Type": "String", + "AllowedPattern": "[\\w+=,.@-]+" + }, + "DomainMembersSGID": { + "Description": "Security Group ID for Domain Members Security Group", + "Type": "AWS::EC2::SecurityGroup::Id" + }, + "EBSKMSKey": { + "Description": "(Optional) KMS Alias, Key ID, Key ID ARN or Alias ARN to use for encrypting the EBS volumes. If empty, the default key for EBS encryption will be used of `alias/aws/ebs` or the CMK set as the default EBS encryption key.", + "Type": "String", + "AllowedPattern": "^$|(^alias/[a-zA-Z0-9/-]{1,256}$)|(^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$)|(^arn:(aws[a-z-]*)?:kms:.*:\\d{12}:key/[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$)|(^arn:(aws[a-z-]*)?:kms:.*:\\d{12}:alias/[a-zA-Z0-9/-]{1,256}$)" + }, + "KeyPairName": { + "Description": "KeyPair for ONPREMISES INSTANCES", + "Type": "AWS::EC2::KeyPair::KeyName" + }, + "PrivateSubnet1ID": { + "Description": "ID of the private subnet 1 in Availability Zone 1 (e.g., subnet-a0246dcd)", + "Type": "AWS::EC2::Subnet::Id" + }, + "PrivateSubnet2ID": { + "Description": "ID of the private subnet 2 in Availability Zone 2 (e.g., subnet-a0246dcd)", + "Type": "AWS::EC2::Subnet::Id" + }, + "SSMLogsBucketName": { + "Description": "(Optional) SSM Logs bucket name for where Systems Manager logs should store log files. SSM Logs bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-).", + "Type": "String", + "AllowedPattern": "^$|(?=^.{3,63}$)(?!.*[.-]{2})(?!.*[--]{2})(?!^(?:(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\\.(?!$)|$)){4}$)(^(([a-z0-9]|[a-z0-9][a-z0-9\\-]*[a-z0-9])\\.)*([a-z0-9]|[a-z0-9][a-z0-9\\-]*[a-z0-9])$)", + "ConstraintDescription": "SSM Logs bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-)." + }, + "WINFULLBASE": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/aws/service/ami-windows-latest/Windows_Server-2019-English-Full-Base" + } + }, + "Conditions": { + "DomainDNSServer1Condition": { + "Fn::Not": [ + { + "Fn::Equals": [ + { + "Ref": "DomainDNSServer1" + }, + "" + ] + } + ] + }, + "DomainDNSServer2Condition": { + "Fn::Not": [ + { + "Fn::Equals": [ + { + "Ref": "DomainDNSServer2" + }, + "" + ] + } + ] + }, + "DomainDNSServer3Condition": { + "Fn::Not": [ + { + "Fn::Equals": [ + { + "Ref": "DomainDNSServer3" + }, + "" + ] + } + ] + }, + "DomainDNSServer4Condition": { + "Fn::Not": [ + { + "Fn::Equals": [ + { + "Ref": "DomainDNSServer4" + }, + "" + ] + } + ] + }, + "DomainDNSServersCondition": { + "Fn::Or": [ + { + "Condition": "DomainDNSServer1Condition" + }, + { + "Condition": "DomainDNSServer2Condition" + }, + { + "Condition": "DomainDNSServer3Condition" + }, + { + "Condition": "DomainDNSServer4Condition" + } + ] + }, + "EBSKMSKeyCondition": { + "Fn::Not": [ + { + "Fn::Equals": [ + { + "Ref": "EBSKMSKey" + }, + "" + ] + } + ] + }, + "SSMLogsBucketCondition": { + "Fn::Not": [ + { + "Fn::Equals": [ + { + "Ref": "SSMLogsBucketName" + }, + "" + ] + } + ] + } + }, + "Resources": { + "DomainMember1WithInlineSsmAssociation": { + "Type": "AWS::EC2::Instance", + "Properties": { + "ImageId": { + "Ref": "WINFULLBASE" + }, + "IamInstanceProfile": { + "Ref": "DomainMembersWindowsInstanceProfile" + }, + "SsmAssociations": [ + { + "DocumentName": "AWS-JoinDirectoryServiceDomain", + "AssociationParameters": [ + { + "Key": "directoryId", + "Value": [ + { + "Ref": "DirectoryID" + } + ] + }, + { + "Key": "directoryName", + "Value": [ + { + "Ref": "DirectoryName" + } + ] + }, + { + "Fn::If": [ + "DomainDNSServersCondition", + { + "Key": "dnsIpAddresses", + "Value": [ + { + "Fn::If": [ + "DomainDNSServer1Condition", + { + "Ref": "DomainDNSServer1" + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + { + "Fn::If": [ + "DomainDNSServer2Condition", + { + "Ref": "DomainDNSServer2" + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + { + "Fn::If": [ + "DomainDNSServer3Condition", + { + "Ref": "DomainDNSServer3" + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + { + "Fn::If": [ + "DomainDNSServer4Condition", + { + "Ref": "DomainDNSServer4" + }, + { + "Ref": "AWS::NoValue" + } + ] + } + ] + }, + { + "Ref": "AWS::NoValue" + } + ] + } + ] + } + ], + "InstanceType": { + "Ref": "DomainMembersInstanceType" + }, + "SubnetId": { + "Ref": "PrivateSubnet1ID" + }, + "Tags": [ + { + "Key": "Name", + "Value": { + "Ref": "DomainMember1NetBIOSName" + } + } + ], + "BlockDeviceMappings": [ + { + "DeviceName": "/dev/sda1", + "Ebs": { + "Encrypted": true, + "VolumeType": "gp3", + "DeleteOnTermination": true, + "VolumeSize": 100, + "KmsKeyId": { + "Fn::If": [ + "EBSKMSKeyCondition", + { + "Ref": "EBSKMSKey" + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + } + ], + "SecurityGroupIds": [ + { + "Ref": "DomainMembersSGID" + } + ], + "KeyName": { + "Ref": "KeyPairName" + }, + "UserData": { + "Fn::Base64": { + "Fn::Sub": "\n$instanceId = \"null\"\nwhile ($instanceId -NotLike \"i-*\") {\nStart-Sleep -s 3\n$instanceId = Invoke-RestMethod -uri http://169.254.169.254/latest/meta-data/instance-id\n}\nRename-Computer -NewName ${DomainMember1NetBIOSName} -Force\n# Set-TimeZone -Name \"US Eastern Standard Time\"\n\nInstall-WindowsFeature -IncludeAllSubFeature RSAT\nRestart-Computer -Force\n\n" + } + } + } + }, + "DomainMember2WithSsmAssociationInstance": { + "Type": "AWS::EC2::Instance", + "Properties": { + "ImageId": { + "Ref": "WINFULLBASE" + }, + "IamInstanceProfile": { + "Ref": "DomainMembersWindowsInstanceProfile" + }, + "InstanceType": { + "Ref": "DomainMembersInstanceType" + }, + "SubnetId": { + "Ref": "PrivateSubnet2ID" + }, + "Tags": [ + { + "Key": "Name", + "Value": { + "Ref": "DomainMember2NetBIOSName" + } + } + ], + "BlockDeviceMappings": [ + { + "DeviceName": "/dev/sda1", + "Ebs": { + "Encrypted": true, + "VolumeType": "gp3", + "DeleteOnTermination": true, + "VolumeSize": 100, + "KmsKeyId": { + "Fn::If": [ + "EBSKMSKeyCondition", + { + "Ref": "EBSKMSKey" + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + } + ], + "SecurityGroupIds": [ + { + "Ref": "DomainMembersSGID" + } + ], + "KeyName": { + "Ref": "KeyPairName" + }, + "UserData": { + "Fn::Base64": { + "Fn::Sub": "\n$instanceId = \"null\"\nwhile ($instanceId -NotLike \"i-*\") {\nStart-Sleep -s 3\n$instanceId = Invoke-RestMethod -uri http://169.254.169.254/latest/meta-data/instance-id\n}\nRename-Computer -NewName ${DomainMember2NetBIOSName} -Force\n# Set-TimeZone -Name \"US Eastern Standard Time\"\n\nInstall-WindowsFeature -IncludeAllSubFeature RSAT\nRestart-Computer -Force\n\n" + } + } + } + }, + "DomainMember3WithSsmAssociationTag": { + "Type": "AWS::EC2::Instance", + "Properties": { + "ImageId": { + "Ref": "WINFULLBASE" + }, + "IamInstanceProfile": { + "Ref": "DomainMembersWindowsInstanceProfile" + }, + "InstanceType": { + "Ref": "DomainMembersInstanceType" + }, + "SubnetId": { + "Ref": "PrivateSubnet1ID" + }, + "Tags": [ + { + "Key": "Name", + "Value": { + "Ref": "DomainMember3NetBIOSName" + } + }, + { + "Key": "DomainJoin", + "Value": { + "Ref": "DirectoryName" + } + } + ], + "BlockDeviceMappings": [ + { + "DeviceName": "/dev/sda1", + "Ebs": { + "Encrypted": true, + "VolumeType": "gp3", + "DeleteOnTermination": true, + "VolumeSize": 100, + "KmsKeyId": { + "Fn::If": [ + "EBSKMSKeyCondition", + { + "Ref": "EBSKMSKey" + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + } + ], + "SecurityGroupIds": [ + { + "Ref": "DomainMembersSGID" + } + ], + "KeyName": { + "Ref": "KeyPairName" + }, + "UserData": { + "Fn::Base64": { + "Fn::Sub": "\n$instanceId = \"null\"\nwhile ($instanceId -NotLike \"i-*\") {\nStart-Sleep -s 3\n$instanceId = Invoke-RestMethod -uri http://169.254.169.254/latest/meta-data/instance-id\n}\nRename-Computer -NewName ${DomainMember3NetBIOSName} -Force\n# Set-TimeZone -Name \"US Eastern Standard Time\"\n\nInstall-WindowsFeature -IncludeAllSubFeature RSAT\nRestart-Computer -Force\n\n" + } + } + } + }, + "DomainMember4LinuxWithSsmAssociationInstance": { + "Type": "AWS::EC2::Instance", + "Properties": { + "ImageId": { + "Ref": "AMAZONLINUX2" + }, + "IamInstanceProfile": { + "Ref": "DomainMembersLinuxInstanceProfile" + }, + "InstanceType": { + "Ref": "DomainMembersInstanceType" + }, + "SubnetId": { + "Ref": "PrivateSubnet2ID" + }, + "Tags": [ + { + "Key": "Name", + "Value": { + "Ref": "DomainMember4NetBIOSName" + } + } + ], + "BlockDeviceMappings": [ + { + "DeviceName": "/dev/sda1", + "Ebs": { + "Encrypted": true, + "VolumeType": "gp3", + "DeleteOnTermination": true, + "VolumeSize": 100, + "KmsKeyId": { + "Fn::If": [ + "EBSKMSKeyCondition", + { + "Ref": "EBSKMSKey" + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + } + ], + "SecurityGroupIds": [ + { + "Ref": "DomainMembersSGID" + } + ], + "KeyName": { + "Ref": "KeyPairName" + }, + "UserData": { + "Fn::Base64": { + "Fn::Sub": "# Set HostName\nLowerEc2Name=$(echo ${DomainMember4NetBIOSName} | tr '[:upper:]' '[:lower:]')\nhostnamectl set-hostname $LowerEc2Name\n# Set TimeZone\n# sed -i 's|^ZONE=.*|ZONE=\"America/New_York\"|' /etc/sysconfig/clock\n# ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime\n# Patch System Up\nyum update -y\n# Reboot\nreboot\n" + } + } + } + }, + "JoinDomainAssociationInstances": { + "Type": "AWS::SSM::Association", + "Properties": { + "AssociationName": { + "Fn::Sub": "JoinDomain-Association-viaInstances-${AWS::StackName}" + }, + "Name": "AWS-JoinDirectoryServiceDomain", + "OutputLocation": { + "S3Location": { + "Fn::If": [ + "SSMLogsBucketCondition", + { + "OutputS3BucketName": { + "Ref": "SSMLogsBucketName" + }, + "OutputS3KeyPrefix": { + "Fn::Sub": "ssm-association-logs/AWSLogs/${AWS::AccountId}/*" + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + }, + "Targets": [ + { + "Key": "InstanceIds", + "Values": [ + { + "Ref": "DomainMember2WithSsmAssociationInstance" + }, + { + "Ref": "DomainMember4LinuxWithSsmAssociationInstance" + } + ] + } + ], + "Parameters": { + "directoryId": [ + { + "Ref": "DirectoryID" + } + ], + "directoryName": [ + { + "Ref": "DirectoryName" + } + ], + "dnsIpAddresses": { + "Fn::If": [ + "DomainDNSServersCondition", + [ + { + "Fn::If": [ + "DomainDNSServer1Condition", + { + "Ref": "DomainDNSServer1" + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + { + "Fn::If": [ + "DomainDNSServer2Condition", + { + "Ref": "DomainDNSServer2" + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + { + "Fn::If": [ + "DomainDNSServer3Condition", + { + "Ref": "DomainDNSServer3" + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + { + "Fn::If": [ + "DomainDNSServer4Condition", + { + "Ref": "DomainDNSServer4" + }, + { + "Ref": "AWS::NoValue" + } + ] + } + ], + { + "Ref": "AWS::NoValue" + } + ] + } + } + } + }, + "JoinDomainAssociationTags": { + "Type": "AWS::SSM::Association", + "Properties": { + "AssociationName": { + "Fn::Sub": "JoinDomain-Association-viaTags-${AWS::StackName}" + }, + "Name": "AWS-JoinDirectoryServiceDomain", + "OutputLocation": { + "S3Location": { + "Fn::If": [ + "SSMLogsBucketCondition", + { + "OutputS3BucketName": { + "Ref": "SSMLogsBucketName" + }, + "OutputS3KeyPrefix": { + "Fn::Sub": "ssm-association-logs/AWSLogs/${AWS::AccountId}/*" + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + }, + "Targets": [ + { + "Key": "tag:DomainJoin", + "Values": [ + { + "Ref": "DirectoryName" + } + ] + } + ], + "Parameters": { + "directoryId": [ + { + "Ref": "DirectoryID" + } + ], + "directoryName": [ + { + "Ref": "DirectoryName" + } + ], + "dnsIpAddresses": { + "Fn::If": [ + "DomainDNSServersCondition", + [ + { + "Fn::If": [ + "DomainDNSServer1Condition", + { + "Ref": "DomainDNSServer1" + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + { + "Fn::If": [ + "DomainDNSServer2Condition", + { + "Ref": "DomainDNSServer2" + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + { + "Fn::If": [ + "DomainDNSServer3Condition", + { + "Ref": "DomainDNSServer3" + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + { + "Fn::If": [ + "DomainDNSServer4Condition", + { + "Ref": "DomainDNSServer4" + }, + { + "Ref": "AWS::NoValue" + } + ] + } + ], + { + "Ref": "AWS::NoValue" + } + ] + } + } + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/DirectoryADClients/DIRECTORY-AD-CLIENTS.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/DirectoryADClients/DIRECTORY-AD-CLIENTS.yaml new file mode 100644 index 0000000000000000000000000000000000000000..afca41e445f3053b6c7ec6e5629217008e4d49fa --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/DirectoryADClients/DIRECTORY-AD-CLIENTS.yaml @@ -0,0 +1,503 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: This template creates (1) Linux and (3) Windows EC2 instances and joins them to Active Directory using the 'AWS-JoinDirectoryServiceDomain' SSM document via AD Connector or AWS Managed AD directory. By default, it relies on the DNS servers being used by the EC2 instances knowing how to resolve the AD domain (i.e., Route 53 Resolvers, DHCP OptionsSet), with an option to set the DNS servers manually on the EC2 instances, as necessary. Several methods used to initiate the domain join (1) Windows EC2 instance with inline SSM association (2) Windows and Linux EC2 instance with SSM association targeting EC2 instance IDs (3) Windows EC2 instance with SSM association targeting EC2 instance tags + +Metadata: + AWS::CloudFormation::Interface: + ParameterGroups: + - Label: + default: Network Configuration + Parameters: + - PrivateSubnet1ID + - PrivateSubnet2ID + - Label: + default: EC2 Instance Configuration + Parameters: + - DomainMembersInstanceType + - DomainMember1NetBIOSName + - DomainMember2NetBIOSName + - DomainMember3NetBIOSName + - DomainMember4NetBIOSName + - KeyPairName + - DomainMembersLinuxInstanceProfile + - DomainMembersWindowsInstanceProfile + - DomainMembersSGID + - EBSKMSKey + - AMAZONLINUX2 + - WINFULLBASE + - SSMLogsBucketName + - Label: + default: Directory Services Configuration + Parameters: + - DirectoryID + - DirectoryName + - DomainDNSServer1 + - DomainDNSServer2 + - DomainDNSServer3 + - DomainDNSServer4 + ParameterLabels: + AMAZONLINUX2: + default: SSM Parameter Value for Lastest Amazon Linux 2 AMI ID + DirectoryID: + default: ID of the Directory (e.g., d-906764663a) + DirectoryName: + default: Directory Name + DomainDNSServer1: + default: Domain DNS Server 1 + DomainDNSServer2: + default: Domain DNS Server 2 + DomainDNSServer3: + default: Domain DNS Server 3 + DomainDNSServer4: + default: Domain DNS Server 4 + DomainMember1NetBIOSName: + default: Domain Member 1 NetBIOS Name + DomainMember2NetBIOSName: + default: Domain Member 2 NetBIOS Name + DomainMember3NetBIOSName: + default: Domain Member 3 NetBIOS Name + DomainMember4NetBIOSName: + default: Domain Member 4 NetBIOS Name + DomainMembersInstanceType: + default: Domain Members Instance Type + DomainMembersSGID: + default: Domain Members Security Group + DomainMembersLinuxInstanceProfile: + default: Domain Member Linux InstanceProfile + DomainMembersWindowsInstanceProfile: + default: Domain Member Windows InstanceProfile + EBSKMSKey: + default: Amazon EBS Volume KMS Key + KeyPairName: + default: Key Pair Name + PrivateSubnet1ID: + default: Private Subnet 1 ID + PrivateSubnet2ID: + default: Private Subnet 2 ID + SSMLogsBucketName: + default: SSM Logs Bucket Name + WINFULLBASE: + default: SSM Parameter Value for Lastest Windows AMI ID + +Parameters: + AMAZONLINUX2: + Type: AWS::SSM::Parameter::Value + Default: /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-ebs + + DirectoryID: + Description: Directory ID + Type: String + AllowedPattern: ^d-[0-9a-f]{10}$ + + DirectoryName: + Description: Fully qualified name of the on-premises directory, such as corp.example.com + Type: String + AllowedPattern: '[a-zA-Z0-9-]+\..+' + MaxLength: 25 + MinLength: 3 + + DomainDNSServer1: + Description: (Optional) Domain DNS Server 1. If DNS servers are not set, then you need to ensure the DNS servers the EC2 instances are using can resolve the AD domain. + Type: String + AllowedPattern: ^$|^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$ + + DomainDNSServer2: + Description: (Optional) Domain DNS Server 2. If DNS servers are not set, then you need to ensure the DNS servers the EC2 instances are using can resolve the AD domain. + Type: String + AllowedPattern: ^$|^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$ + + DomainDNSServer3: + Description: (Optional) Domain DNS Server 3. If DNS servers are not set, then you need to ensure the DNS servers the EC2 instances are using can resolve the AD domain. + Type: String + AllowedPattern: ^$|^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$ + + DomainDNSServer4: + Description: (Optional) Domain DNS Server 4. If DNS servers are not set, then you need to ensure the DNS servers the EC2 instances are using can resolve the AD domain. + Type: String + AllowedPattern: ^$|^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$ + + DomainMember1NetBIOSName: + Description: NetBIOS name of Domain Member 1 (using inline SSM association). Note, if computer name existed in AD before, delete from AD first. + Type: String + Default: SERVER1 + AllowedPattern: '[a-zA-Z0-9-]+' + MaxLength: 15 + MinLength: 1 + + DomainMember2NetBIOSName: + Description: NetBIOS name of Domain Member 2 (using SSM association via instance id). Note, if computer name existed in AD before, delete from AD first. + Type: String + Default: SERVER2 + AllowedPattern: '[a-zA-Z0-9-]+' + MaxLength: 15 + MinLength: 1 + + DomainMember3NetBIOSName: + Description: NetBIOS name of Domain Member 3 (using SSM association via tag). Note, if computer name existed in AD before, delete from AD first. + Type: String + Default: SERVER3 + AllowedPattern: '[a-zA-Z0-9-]+' + MaxLength: 15 + MinLength: 1 + + DomainMember4NetBIOSName: + Description: NetBIOS name of Domain Member 4 (AmazonLinux2) + Type: String + Default: SERVER4 + AllowedPattern: '[a-zA-Z0-9-]+' + MaxLength: 15 + MinLength: 1 + + DomainMembersInstanceType: + Description: Amazon EC2 instance type for the AD Server instances + Type: String + AllowedValues: + - t3.medium + - t3.large + Default: t3.medium + + DomainMembersLinuxInstanceProfile: + Description: Existing IAM InstanceProfile with Linux EC2 seamless join domain rights + Type: String + AllowedPattern: '[\w+=,.@-]+' + + DomainMembersWindowsInstanceProfile: + Description: Existing IAM InstanceProfile with Windows EC2 seamless join domain rights + Type: String + AllowedPattern: '[\w+=,.@-]+' + + DomainMembersSGID: + Description: Security Group ID for Domain Members Security Group + Type: AWS::EC2::SecurityGroup::Id + + EBSKMSKey: + Description: (Optional) KMS Alias, Key ID, Key ID ARN or Alias ARN to use for encrypting the EBS volumes. If empty, the default key for EBS encryption will be used of `alias/aws/ebs` or the CMK set as the default EBS encryption key. + Type: String + AllowedPattern: ^$|(^alias/[a-zA-Z0-9/-]{1,256}$)|(^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$)|(^arn:(aws[a-z-]*)?:kms:.*:\d{12}:key/[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$)|(^arn:(aws[a-z-]*)?:kms:.*:\d{12}:alias/[a-zA-Z0-9/-]{1,256}$) + + KeyPairName: + Description: KeyPair for ONPREMISES INSTANCES + Type: AWS::EC2::KeyPair::KeyName + + PrivateSubnet1ID: + Description: ID of the private subnet 1 in Availability Zone 1 (e.g., subnet-a0246dcd) + Type: AWS::EC2::Subnet::Id + + PrivateSubnet2ID: + Description: ID of the private subnet 2 in Availability Zone 2 (e.g., subnet-a0246dcd) + Type: AWS::EC2::Subnet::Id + + SSMLogsBucketName: + Description: (Optional) SSM Logs bucket name for where Systems Manager logs should store log files. SSM Logs bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-). + Type: String + AllowedPattern: ^$|(?=^.{3,63}$)(?!.*[.-]{2})(?!.*[--]{2})(?!^(?:(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\.(?!$)|$)){4}$)(^(([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])\.)*([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])$) + ConstraintDescription: SSM Logs bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-). + + WINFULLBASE: + Type: AWS::SSM::Parameter::Value + Default: /aws/service/ami-windows-latest/Windows_Server-2019-English-Full-Base + +Conditions: + DomainDNSServer1Condition: !Not + - !Equals + - !Ref DomainDNSServer1 + - "" + + DomainDNSServer2Condition: !Not + - !Equals + - !Ref DomainDNSServer2 + - "" + + DomainDNSServer3Condition: !Not + - !Equals + - !Ref DomainDNSServer3 + - "" + + DomainDNSServer4Condition: !Not + - !Equals + - !Ref DomainDNSServer4 + - "" + + DomainDNSServersCondition: !Or + - !Condition DomainDNSServer1Condition + - !Condition DomainDNSServer2Condition + - !Condition DomainDNSServer3Condition + - !Condition DomainDNSServer4Condition + + EBSKMSKeyCondition: !Not + - !Equals + - !Ref EBSKMSKey + - "" + + SSMLogsBucketCondition: !Not + - !Equals + - !Ref SSMLogsBucketName + - "" + +Resources: + DomainMember1WithInlineSsmAssociation: + Type: AWS::EC2::Instance + Properties: + ImageId: !Ref WINFULLBASE + IamInstanceProfile: !Ref DomainMembersWindowsInstanceProfile + SsmAssociations: + - DocumentName: AWS-JoinDirectoryServiceDomain + AssociationParameters: + - Key: directoryId + Value: + - !Ref DirectoryID + - Key: directoryName + Value: + - !Ref DirectoryName + - !If + - DomainDNSServersCondition + - Key: dnsIpAddresses + Value: + - !If + - DomainDNSServer1Condition + - !Ref DomainDNSServer1 + - !Ref AWS::NoValue + - !If + - DomainDNSServer2Condition + - !Ref DomainDNSServer2 + - !Ref AWS::NoValue + - !If + - DomainDNSServer3Condition + - !Ref DomainDNSServer3 + - !Ref AWS::NoValue + - !If + - DomainDNSServer4Condition + - !Ref DomainDNSServer4 + - !Ref AWS::NoValue + - !Ref AWS::NoValue + InstanceType: !Ref DomainMembersInstanceType + SubnetId: !Ref PrivateSubnet1ID + Tags: + - Key: Name + Value: !Ref DomainMember1NetBIOSName + BlockDeviceMappings: + - DeviceName: /dev/sda1 + Ebs: + Encrypted: true + VolumeType: gp3 + DeleteOnTermination: true + VolumeSize: 100 + KmsKeyId: !If + - EBSKMSKeyCondition + - !Ref EBSKMSKey + - !Ref AWS::NoValue + SecurityGroupIds: + - !Ref DomainMembersSGID + KeyName: !Ref KeyPairName + UserData: !Base64 + Fn::Sub: | + + $instanceId = "null" + while ($instanceId -NotLike "i-*") { + Start-Sleep -s 3 + $instanceId = Invoke-RestMethod -uri http://169.254.169.254/latest/meta-data/instance-id + } + Rename-Computer -NewName ${DomainMember1NetBIOSName} -Force + # Set-TimeZone -Name "US Eastern Standard Time" + + Install-WindowsFeature -IncludeAllSubFeature RSAT + Restart-Computer -Force + + + DomainMember2WithSsmAssociationInstance: + Type: AWS::EC2::Instance + Properties: + ImageId: !Ref WINFULLBASE + IamInstanceProfile: !Ref DomainMembersWindowsInstanceProfile + InstanceType: !Ref DomainMembersInstanceType + SubnetId: !Ref PrivateSubnet2ID + Tags: + - Key: Name + Value: !Ref DomainMember2NetBIOSName + BlockDeviceMappings: + - DeviceName: /dev/sda1 + Ebs: + Encrypted: true + VolumeType: gp3 + DeleteOnTermination: true + VolumeSize: 100 + KmsKeyId: !If + - EBSKMSKeyCondition + - !Ref EBSKMSKey + - !Ref AWS::NoValue + SecurityGroupIds: + - !Ref DomainMembersSGID + KeyName: !Ref KeyPairName + UserData: !Base64 + Fn::Sub: | + + $instanceId = "null" + while ($instanceId -NotLike "i-*") { + Start-Sleep -s 3 + $instanceId = Invoke-RestMethod -uri http://169.254.169.254/latest/meta-data/instance-id + } + Rename-Computer -NewName ${DomainMember2NetBIOSName} -Force + # Set-TimeZone -Name "US Eastern Standard Time" + + Install-WindowsFeature -IncludeAllSubFeature RSAT + Restart-Computer -Force + + + DomainMember3WithSsmAssociationTag: + Type: AWS::EC2::Instance + Properties: + ImageId: !Ref WINFULLBASE + IamInstanceProfile: !Ref DomainMembersWindowsInstanceProfile + InstanceType: !Ref DomainMembersInstanceType + SubnetId: !Ref PrivateSubnet1ID + Tags: + - Key: Name + Value: !Ref DomainMember3NetBIOSName + - Key: DomainJoin + Value: !Ref DirectoryName + BlockDeviceMappings: + - DeviceName: /dev/sda1 + Ebs: + Encrypted: true + VolumeType: gp3 + DeleteOnTermination: true + VolumeSize: 100 + KmsKeyId: !If + - EBSKMSKeyCondition + - !Ref EBSKMSKey + - !Ref AWS::NoValue + SecurityGroupIds: + - !Ref DomainMembersSGID + KeyName: !Ref KeyPairName + UserData: !Base64 + Fn::Sub: | + + $instanceId = "null" + while ($instanceId -NotLike "i-*") { + Start-Sleep -s 3 + $instanceId = Invoke-RestMethod -uri http://169.254.169.254/latest/meta-data/instance-id + } + Rename-Computer -NewName ${DomainMember3NetBIOSName} -Force + # Set-TimeZone -Name "US Eastern Standard Time" + + Install-WindowsFeature -IncludeAllSubFeature RSAT + Restart-Computer -Force + + + DomainMember4LinuxWithSsmAssociationInstance: + Type: AWS::EC2::Instance + Properties: + ImageId: !Ref AMAZONLINUX2 + IamInstanceProfile: !Ref DomainMembersLinuxInstanceProfile + InstanceType: !Ref DomainMembersInstanceType + SubnetId: !Ref PrivateSubnet2ID + Tags: + - Key: Name + Value: !Ref DomainMember4NetBIOSName + BlockDeviceMappings: + - DeviceName: /dev/sda1 + Ebs: + Encrypted: true + VolumeType: gp3 + DeleteOnTermination: true + VolumeSize: 100 + KmsKeyId: !If + - EBSKMSKeyCondition + - !Ref EBSKMSKey + - !Ref AWS::NoValue + SecurityGroupIds: + - !Ref DomainMembersSGID + KeyName: !Ref KeyPairName + UserData: !Base64 + Fn::Sub: | + # Set HostName + LowerEc2Name=$(echo ${DomainMember4NetBIOSName} | tr '[:upper:]' '[:lower:]') + hostnamectl set-hostname $LowerEc2Name + # Set TimeZone + # sed -i 's|^ZONE=.*|ZONE="America/New_York"|' /etc/sysconfig/clock + # ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime + # Patch System Up + yum update -y + # Reboot + reboot + + JoinDomainAssociationInstances: + Type: AWS::SSM::Association + Properties: + AssociationName: !Sub JoinDomain-Association-viaInstances-${AWS::StackName} + Name: AWS-JoinDirectoryServiceDomain + OutputLocation: + S3Location: !If + - SSMLogsBucketCondition + - OutputS3BucketName: !Ref SSMLogsBucketName + OutputS3KeyPrefix: !Sub ssm-association-logs/AWSLogs/${AWS::AccountId}/* + - !Ref AWS::NoValue + Targets: + - Key: InstanceIds + Values: + - !Ref DomainMember2WithSsmAssociationInstance + - !Ref DomainMember4LinuxWithSsmAssociationInstance + Parameters: + directoryId: + - !Ref DirectoryID + directoryName: + - !Ref DirectoryName + dnsIpAddresses: !If + - DomainDNSServersCondition + - - !If + - DomainDNSServer1Condition + - !Ref DomainDNSServer1 + - !Ref AWS::NoValue + - !If + - DomainDNSServer2Condition + - !Ref DomainDNSServer2 + - !Ref AWS::NoValue + - !If + - DomainDNSServer3Condition + - !Ref DomainDNSServer3 + - !Ref AWS::NoValue + - !If + - DomainDNSServer4Condition + - !Ref DomainDNSServer4 + - !Ref AWS::NoValue + - !Ref AWS::NoValue + + JoinDomainAssociationTags: + Type: AWS::SSM::Association + Properties: + AssociationName: !Sub JoinDomain-Association-viaTags-${AWS::StackName} + Name: AWS-JoinDirectoryServiceDomain + OutputLocation: + S3Location: !If + - SSMLogsBucketCondition + - OutputS3BucketName: !Ref SSMLogsBucketName + OutputS3KeyPrefix: !Sub ssm-association-logs/AWSLogs/${AWS::AccountId}/* + - !Ref AWS::NoValue + Targets: + - Key: tag:DomainJoin + Values: + - !Ref DirectoryName + Parameters: + directoryId: + - !Ref DirectoryID + directoryName: + - !Ref DirectoryName + dnsIpAddresses: !If + - DomainDNSServersCondition + - - !If + - DomainDNSServer1Condition + - !Ref DomainDNSServer1 + - !Ref AWS::NoValue + - !If + - DomainDNSServer2Condition + - !Ref DomainDNSServer2 + - !Ref AWS::NoValue + - !If + - DomainDNSServer3Condition + - !Ref DomainDNSServer3 + - !Ref AWS::NoValue + - !If + - DomainDNSServer4Condition + - !Ref DomainDNSServer4 + - !Ref AWS::NoValue + - !Ref AWS::NoValue diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/DirectoryADClients/README.md b/human_reference_dataset/aws-cloudformation-templates/Solutions/DirectoryADClients/README.md new file mode 100644 index 0000000000000000000000000000000000000000..c66c7e1d07333c2f8ef44e757cf8c485939c9bed --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/DirectoryADClients/README.md @@ -0,0 +1,37 @@ +# DIRECTORY-AD-CLIENTS + +## Description + +This solution creates Linux and Windows EC2 instances and joins them to Active Directory (AD) via AD Connector or AWS Managed AD directory via +different SSM Association methods. + +- `AWS-JoinDirectoryServiceDomain` SSM document is used to join AD domain. +- To join AD domain, EC2 instances must be able to resolve the AD domain, 2 options provided: + - By default, DHCPOptionsSet is relied on to be able to resolve the AD domain. + - If Domain DNS servers are provided, then they are set manually on the EC2 instances. +- Different methods used to initiate the Domain Join, as examples: + - Windows EC2 instance using an inline SSM association + - Windows and Linux EC2 instance using an SSM association resource targeting EC2 instance IDs + - Windows EC2 instance using an SSM association resource targeting EC2 instance tags + +## Notes + +- For Linux Hosts, the + [ssm-agent domainjoin plugin](https://github.com/aws/amazon-ssm-agent/blob/mainline/agent/plugins/domainjoin/domainjoin_unix_script.go), ignores + hostname, and creates a random hostname with prefix "EC2AMAZ-" +- If NetBIOS name already exists in Active Directory, the domain join will fail. + - Terminating an EC2 instance that was previous joined to Active Directory, does not delete the Computer Name. Remember to delete computer name in + AD. +- Amazon EBS Volumes using Amazon managed server-side encryption or the CMK set as the default EBS encryption key. Optionally, a KMS CMK can be used. +- Amazon EC2 instance inline SSM associations, provides limited properties compared to using an + [SSM Association resource](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ssm-association.html). + +## Resources + +- [Join an EC2 instance to your AD Connector directory](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/ad_connector_join_instance.html) +- [Join an EC2 instance to your AWS Managed Microsoft AD directory](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/ms_ad_join_instance.html) +- [amazon-ssm-agent/agent/plugins/domainjoin](https://github.com/aws/amazon-ssm-agent/tree/mainline/agent/plugins/domainjoin) + +## Instructions + +1. Launch the AWS CloudFormation stack using the [DIRECTORY-AD-CLIENTS.cfn.yaml](templates/DIRECTORY-AD-CLIENTS.cfn.yaml) template file as the source. diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/DirectoryServiceSettings/README.md b/human_reference_dataset/aws-cloudformation-templates/Solutions/DirectoryServiceSettings/README.md new file mode 100644 index 0000000000000000000000000000000000000000..7bc6f40ab6c67977ef3e72ce741895f407bedf2d --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/DirectoryServiceSettings/README.md @@ -0,0 +1,39 @@ +# Directory Settings + +## Description + +This solution updates the settings for an AD Connector or AWS Managed AD directory. + +- Enables directory monitoring by using an Amazon SNS topic to send emails when the status of the directory changes. +- (Optional) Creates a custom access URL that can be used with AWS applications and services, to reach a login page that is associated to the + directory. +- (Optional) Enable single sign-on, this allows users in your directory to access certain AWS services from a computer joined to the directory without + having to enter their credentials separately. joined to the directory. +- (Optional) Creates **LAB EXAMPLE** IAM roles that can be used to delegate users/groups access to certain areas of the AWS Management Console. + - User/Group assignment to these IAM roles has to be done manually via Directory Services -> Directory -> Application Management Tab. + +## Notes + +- AD Connector is not an AWS CloudFormation supported resource, therefore using an AWS CloudFormation custom resource. +- CloudWatch Logs Log Group uses Amazon managed server-side encryption. Optionally, a KMS CMK can be used. +- SNS Topic using Amazon managed server-side encryption. Optionally, a KMS CMK can be used. + +## Resources + +- [Monitor your AD Connector directory](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/ad_connector_monitor.html) +- [Monitor your AWS Managed Microsoft AD](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/ms_ad_monitor.html) +- [Enable access to AWS applications and services](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/ms_ad_manage_apps_services.html) +- [Creating an access URL](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/ms_ad_create_access_url.html) +- [Single sign-on](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/ms_ad_single_sign_on.html) +- [Enable access to the AWS Management Console with AD credentials](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/ms_ad_management_console_access.html) + +## Attributions + +Using the [aws-cloudformation/custom-resource-heper](https://github.com/aws-cloudformation/custom-resource-helper) to handle the AWS CloudFormation +Custom Resource responses for the given resources. + +## Instructions + +1. Run [src/package.sh](src/package.sh) to package the code and dependencies. +2. Upload the [src/directory_settings_custom_resource.zip](src/directory_settings_custom_resource.zip) to an S3 bucket, note the bucket name. +3. Launch the AWS CloudFormation stack using the [DIRECTORY_SETTINGS.cfn.yaml](templates/DIRECTORY_SETTINGS.cfn.yaml) template file as the source. diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/DirectoryServiceSettings/src/directory_settings_custom_resource.py b/human_reference_dataset/aws-cloudformation-templates/Solutions/DirectoryServiceSettings/src/directory_settings_custom_resource.py new file mode 100644 index 0000000000000000000000000000000000000000..cb7010e5697385e2d8d1aabf155a8f7d04afc7b4 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/DirectoryServiceSettings/src/directory_settings_custom_resource.py @@ -0,0 +1,226 @@ +"""Configure Directory Settings (Directory Monitoring, Directory Alias, & Directory SSO). + +Copyright 2021 Amazon Web Services, Inc. or its affiliates. All Rights Reserved. +This AWS Content is provided subject to the terms of the AWS Customer Agreement available at +http://aws.amazon.com/agreement or other written agreement between Customer and either +Amazon Web Services, Inc. or Amazon Web Services EMEA SARL or both. +""" + +#pylint: disable=line-too-long + +from __future__ import annotations + +import json +import logging +import os +from typing import TYPE_CHECKING + +import boto3 + +# import botocore +from crhelper import CfnResource + +# Setup Default Logger +logger = logging.getLogger(__name__) +logger.setLevel(logging.INFO) +logger.setLevel(os.environ.get("LOG_LEVEL", logging.ERROR)) + +# Initialize the helper +helper = CfnResource(json_logging=False, log_level="DEBUG", boto_level="CRITICAL") + +try: + ds_client = boto3.client("ds") +except Exception as error: + helper.init_failure(error) + +if TYPE_CHECKING: + from typing import List, Tuple, Union + + +def get_directory_alias_and_sso_enabled_status(directory_id: str) -> Union[Tuple[str, bool], None]: + """Get the existing directory alias, if configured, and get the current directory SSO state. + + Args: + directory_id: Directory ID + + Returns: + existing directory alias and current directory SSO state + """ + paginator = ds_client.get_paginator("describe_directories") + page_iterator = paginator.paginate(DirectoryIds=[directory_id]) + for page in page_iterator: + for directory in page["DirectoryDescriptions"]: + return directory["Alias"], directory["SsoEnabled"] + return None + + +def get_registered_topics(directory_id: str) -> List[str]: + """Get existing list of SNS topics configured for directory monitoring. + + Args: + directory_id: Directory ID + + Returns: + Existing SNS Topics configured for directory monitoring + """ + response = ds_client.describe_event_topics(DirectoryId=directory_id) + registered_topics: list = [] + for registered_topic in response["EventTopics"]: + registered_topics.append(registered_topic["TopicName"]) + return registered_topics + + +def register_directory_monitoring_topic(directory_id: str, topic: str) -> None: + """Register SNS topic for directory monitoring. + + Args: + directory_id: Directory ID + topic: SNS topic name + """ + registered_topics: list = get_registered_topics(directory_id) + if topic not in registered_topics: + response = ds_client.register_event_topic(DirectoryId=directory_id, TopicName=topic) + logger.info(f"Directory Monitoring registered with Topic '{topic}'") + logger.debug(f"register_topic_response = {json.dumps(response, default=str)}") + + +def deregister_directory_monitoring_topic(directory_id: str, topic: str) -> None: + """Deregister SNS topic for directory monitoring. + + Args: + directory_id: Directory ID + topic: SNS topic name + """ + registered_topics: list = get_registered_topics(directory_id) + for registered_topic in registered_topics: + if topic == registered_topic: + response = ds_client.deregister_event_topic(DirectoryId=directory_id, TopicName=registered_topic) + logger.info(f"Directory Monitoring deregistered with Topic '{registered_topic}'") + logger.debug(f"deregister_topic_response = {json.dumps(response, default=str)}") + + +def create_directory_alias(directory_id: str, alias: str, existing_alias: str) -> str: + """Create and assigns an alias to the directory. + + Args: + directory_id: Directory ID + alias: Requested directory alias + existing_alias: Existing directory alias + + Raises: + ValueError: Directory already has a different alias. Use existing alias for the 'DirectoryAlias' CloudFormation parameter. + + Returns: + The directory alias, either the new alias created, or the existing alias that was already configured. + """ + if alias == existing_alias: + return alias + + if not existing_alias: + response = ds_client.create_alias(DirectoryId=directory_id, Alias=alias) + logger.info("Directory alias created") + logger.debug(f"create_alias_response = {json.dumps(response, default=str)}") + return alias + + error_message = f"Directory already has a different alias. Use '{existing_alias}' for the 'DirectoryAlias' CloudFormation parameter." + raise ValueError(error_message) + + +def enable_directory_sso(directory_id: str, existing_sso_enabled: bool) -> None: + """Enables single sign-on for the directory. + + Args: + directory_id: Directory ID + existing_sso_enabled: Status of single sing-on for the directory + """ + if not existing_sso_enabled: + response = ds_client.enable_sso(DirectoryId=directory_id) + logger.info("Directory enabled for SSO") + logger.debug(f"enable_sso_response = {json.dumps(response, default=str)}") + else: + logger.info("Directory was already enabled for SSO") + + +def disable_directory_sso(directory_id: str, existing_sso_enabled: bool) -> None: + """Disables single sign-on for the directory. + + Args: + directory_id: Directory ID + existing_sso_enabled: Status of single sing-on for the directory + """ + if existing_sso_enabled: + response = ds_client.disable_sso(DirectoryId=directory_id) + logger.info("Directory disabled for SSO") + logger.debug(f"disable_sso_response = {json.dumps(response, default=str)}") + else: + logger.info("Directory was already disabled for SSO") + + +@helper.create +@helper.update +def create_and_update(event, _): + """Create/Update Event from AWS CloudFormation. + + Args: + event: event data + context: runtime information + + """ + logger.info(f"{event['RequestType']} Event") + logger.info(f"REQUEST RECEIVED: {json.dumps(event, default=str)}") + directory_id: str = event["ResourceProperties"]["DirectoryId"] + create_alias: str = event["ResourceProperties"]["CreateDirectoryAlias"] + enable_sso: str = event["ResourceProperties"]["EnableDirectorySSO"] + alias: str = event["ResourceProperties"]["DirectoryAlias"] + topic: str = event["ResourceProperties"]["DirectoryMonitoringTopicName"] + # Directory Monitoring + register_directory_monitoring_topic(directory_id, topic) + # Existing Alias & SSO Status + existing_alias, existing_sso_status = get_directory_alias_and_sso_enabled_status(directory_id) + logger.info(f"existing_alias={existing_alias} --- existing_sso_status={existing_sso_status}") + # Directory Alias + if create_alias == "Yes": + create_directory_alias(directory_id, alias, existing_alias) + helper.Data.update({"AliasUrl": f"https://{alias}.awsapps.com"}) + else: + helper.Data.update({"AliasUrl": ""}) + # Directory SSO + if enable_sso == "Yes": + enable_directory_sso(directory_id, existing_sso_status) + else: + disable_directory_sso(directory_id, existing_sso_status) + + +@helper.delete +def delete(event, _): + """Delete Event from AWS CloudFormation. Deletes the ADConnector Directory. + + Args: + event: event data + context: runtime information + + """ + logger.info("Delete Event") + logger.info(f"REQUEST RECEIVED: {json.dumps(event, default=str)}") + directory_id: str = event["ResourceProperties"]["DirectoryId"] + topic: str = event["ResourceProperties"]["DirectoryMonitoringTopicName"] + # Directory Monitoring + deregister_directory_monitoring_topic(directory_id, topic) + # Existing Alias & SSO Status + existing_alias, existing_sso_status = get_directory_alias_and_sso_enabled_status(directory_id) + # Directory Alias + if existing_alias: + logger.info("Directory Alias by design cannot be modified. Skipped!") + # Directory SSO + disable_directory_sso(directory_id, existing_sso_status) + + +def lambda_handler(event, context): + """Lambda Handler. + + Args: + event: event data + context: runtime information + """ + logger.info("....Lambda Handler Started....") + helper(event, context) diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/DirectoryServiceSettings/src/package.sh b/human_reference_dataset/aws-cloudformation-templates/Solutions/DirectoryServiceSettings/src/package.sh new file mode 100644 index 0000000000000000000000000000000000000000..f45be66d2732773878c0799df7ea16a83e5b55d4 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/DirectoryServiceSettings/src/package.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +set -e + +# Builds a lambda package from a single Python 3 module with pip dependencies. +# This is a modified version of the AWS packaging instructions: +# https://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html#python-package-dependencies + +# Set name of python script, excluding .py extension +SCRIPT_NAME="directory_settings_custom_resource" +SCRIPT_DIRECTORY=$(pwd) + +# Clean-Up +rm -rf .package .DS_Store "$SCRIPT_NAME".zip + +create_package() { + # Create .package directory + mkdir -p .package + # Add dependencies to .package, per the requirements.txt + pip3 install --target .package --requirement requirements.txt + # Add the python script to .package + cp ./"${SCRIPT_NAME}".py .package +} + +# Includes Python Script & Dependencies (if any) +make_zip() { + cd .package + zip -r ../"${SCRIPT_NAME}".zip ./* + echo -e "\n### SCRIPT DIRECTORY: ${SCRIPT_DIRECTORY}" + echo -e "\n### LAMBDA ZIP FILE: ${SCRIPT_NAME}.zip" + cd .. +} + +create_package +make_zip + +echo -e "### LAMBDA PACKAGE SIZE: $(du -sh .package)" diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/DirectoryServiceSettings/src/requirements.txt b/human_reference_dataset/aws-cloudformation-templates/Solutions/DirectoryServiceSettings/src/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..7d2f6bbe093ec8f06df1c7a545cbf7bbddda2b47 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/DirectoryServiceSettings/src/requirements.txt @@ -0,0 +1,2 @@ +# DEPENDENCIES +crhelper \ No newline at end of file diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/DirectoryServiceSettings/templates/DIRECTORY_SETTINGS.cfn.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/DirectoryServiceSettings/templates/DIRECTORY_SETTINGS.cfn.json new file mode 100644 index 0000000000000000000000000000000000000000..f2561b493d4ac78015e0f1898709b0423ecede99 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/DirectoryServiceSettings/templates/DIRECTORY_SETTINGS.cfn.json @@ -0,0 +1,617 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "This templates updates the settings for an AD Connector or AWS Managed AD directory. Tasks accomplied, (1) enables directory monitoring (2) option to create a custom access url (alias) (3) option to enable SSO via directory services. Note, deleting the directory, will only remove directory monitoring, directory SSO or alias settings will not be touched.", + "Metadata": { + "AWS::CloudFormation::Interface": { + "ParameterGroups": [ + { + "Label": { + "default": "Directory Services Configuration" + }, + "Parameters": [ + "DirectoryID", + "DirectoryMonitoringEmail", + "DirectoryMonitoringSNSTopicKMSKey", + "EnableDirectorySSO", + "CreateDirectoryAlias", + "DirectoryAlias", + "CreateDirectoryConsoleDelegatedAccessRoles" + ] + }, + { + "Label": { + "default": "Lambda Function Configuration (Directory Settings Custom Resource)" + }, + "Parameters": [ + "LambdaFunctionName", + "LambdaS3BucketName", + "LambdaZipFileName", + "LambdaLogsLogGroupRetention", + "LambdaLogsCloudWatchKMSKey", + "LambdaLogLevel" + ] + } + ], + "ParameterLabels": { + "CreateDirectoryConsoleDelegatedAccessRoles": { + "default": "Create Directory Console Delegated Access Roles" + }, + "CreateDirectoryAlias": { + "default": "Create Directory Alias" + }, + "DirectoryAlias": { + "default": "Directory Alias" + }, + "DirectoryID": { + "default": "ID of the Directory (e.g., d-906764663a)" + }, + "DirectoryMonitoringEmail": { + "default": "Directory Monitoring Email" + }, + "DirectoryMonitoringSNSTopicKMSKey": { + "default": "SNS Topic KMS Key for Directory Monitoring messages" + }, + "EnableDirectorySSO": { + "default": "Enable Directory SSO" + }, + "LambdaFunctionName": { + "default": "Lambda Function Name" + }, + "LambdaLogLevel": { + "default": "Lambda Log Level" + }, + "LambdaLogsLogGroupRetention": { + "default": "CloudWatch log retention days for Lambda logs" + }, + "LambdaLogsCloudWatchKMSKey": { + "default": "CloudWatch Logs KMS Key for Lambda logs" + }, + "LambdaS3BucketName": { + "default": "Lambda S3 Bucket Name" + }, + "LambdaZipFileName": { + "default": "Lambda Zip File Name" + } + } + } + }, + "Parameters": { + "CreateDirectoryConsoleDelegatedAccessRoles": { + "Description": "Create sample IAM ROLES that can be used to delegate users/groups access to certain areas of the AWS Management Console. User/Group assignment to these IAM roles has to be done manually via Directory Services -> Directory -> Application Management Tab.", + "Type": "String", + "AllowedValues": [ + "Yes", + "No" + ], + "Default": "No" + }, + "CreateDirectoryAlias": { + "Description": "Create an alias for the directory. The alias is used to construct the access URL for the directory, such as http://.awsapps.com. NOTE, after an alias has been created, it cannot be deleted or reused. Hence if a different alias already exists, then you must use the existing alias (also shown in CloudFormation error).", + "Type": "String", + "AllowedValues": [ + "Yes", + "No" + ], + "Default": "No" + }, + "DirectoryAlias": { + "Description": "(Optional) Specifies an alias to be assigned to the directory, such as http://.awsapps.com. Note, after alias is created it cannot be deleted or reused. Note, will only be set, if `CreateDirectoryAlias` parameter, has a value of `Yes`.", + "Type": "String", + "AllowedPattern": "^$|^(?!d-)([\\da-zA-Z]+)([-]*[\\da-zA-Z])*$", + "MaxLength": 62 + }, + "DirectoryID": { + "Description": "Directory ID that will have settings updated", + "Type": "String", + "AllowedPattern": "^d-[0-9a-f]{10}$" + }, + "DirectoryMonitoringEmail": { + "Description": "Email for SNS Topic to monitor directory changes.", + "Type": "String", + "AllowedPattern": "^[\\w%+.-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,63}$" + }, + "DirectoryMonitoringSNSTopicKMSKey": { + "Description": "(Optional) KMS Key ID to use for encrypting the directory monitoring SNS topic messages. If empty, encryption is enabled with SNS managing the server-side encryption keys.", + "Type": "String", + "AllowedPattern": "^$|^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$", + "ConstraintDescription": "Key ID example: 1234abcd-12ab-34cd-56ef-1234567890ab" + }, + "EnableDirectorySSO": { + "Description": "Enable single sign-on for a directory. Single sign-on allows users in your directory to access certain AWS services from a computer joined to the directory without having to enter their credentials separately. If true, \"DirectoryAlias\" must also be true, & \"DirectoryAlias\" parameter input required.", + "Type": "String", + "AllowedValues": [ + "Yes", + "No" + ], + "Default": "No" + }, + "LambdaFunctionName": { + "Description": "Lambda Function Name for Custom Resource", + "Type": "String", + "Default": "CR-DirectorySettings", + "AllowedPattern": "^[\\w-]{1,64}$", + "ConstraintDescription": "Max 64 alphanumeric characters. Also special characters supported [_, -]" + }, + "LambdaLogLevel": { + "Description": "Lambda logging level", + "Type": "String", + "AllowedValues": [ + "INFO", + "DEBUG" + ], + "Default": "INFO" + }, + "LambdaLogsLogGroupRetention": { + "Description": "Specifies the number of days you want to retain Lambda log events in the CloudWatch Logs", + "Type": "String", + "AllowedValues": [ + 1, + 3, + 5, + 7, + 14, + 30, + 60, + 90, + 120, + 150, + 180, + 365, + 400, + 545, + 731, + 1827, + 3653 + ], + "Default": 14 + }, + "LambdaLogsCloudWatchKMSKey": { + "Description": "(Optional) KMS Key ARN to use for encrypting the Lambda logs data. If empty, encryption is enabled with CloudWatch Logs managing the server-side encryption keys.", + "Type": "String", + "AllowedPattern": "^$|^arn:(aws[a-zA-Z-]*)?:kms:[a-z0-9-]+:\\d{12}:key\\/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$", + "ConstraintDescription": "Key ARN example: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab" + }, + "LambdaS3BucketName": { + "Description": "Lambda S3 bucket name for the Lambda deployment package. Lambda bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-).", + "Type": "String", + "AllowedPattern": "(?=^.{3,63}$)(?!.*[.-]{2})(?!.*[--]{2})(?!^(?:(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\\.(?!$)|$)){4}$)(^(([a-z0-9]|[a-z0-9][a-z0-9\\-]*[a-z0-9])\\.)*([a-z0-9]|[a-z0-9][a-z0-9\\-]*[a-z0-9])$)", + "ConstraintDescription": "Lambda S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-)." + }, + "LambdaZipFileName": { + "Description": "Amazon S3 key of the deployment package.", + "Type": "String", + "Default": "directory_settings_custom_resource.zip", + "MaxLength": 1024, + "MinLength": 1 + }, + "Subnets": { + "Type": "List" + }, + "SecurityGroups": { + "Type": "List" + } + }, + "Rules": { + "CreateDirectoryAlias": { + "RuleCondition": { + "Fn::Equals": [ + { + "Ref": "CreateDirectoryAlias" + }, + "Yes" + ] + }, + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Equals": [ + { + "Ref": "DirectoryAlias" + }, + "" + ] + } + ] + }, + "AssertDescription": "To create directory alias, the parameter, `DirectoryAlias` must be set" + } + ] + }, + "EnableDirectorySSO": { + "RuleCondition": { + "Fn::Equals": [ + { + "Ref": "EnableDirectorySSO" + }, + "Yes" + ] + }, + "Assertions": [ + { + "Assert": { + "Fn::Equals": [ + { + "Ref": "CreateDirectoryAlias" + }, + "Yes" + ] + }, + "AssertDescription": "To enable directory SSO, the parameter, `CreateDirectoryAlias` must be set to `Yes`" + } + ] + } + }, + "Conditions": { + "DirectoryConsoleDelegatedAccessRolesCondition": { + "Fn::Equals": [ + { + "Ref": "CreateDirectoryConsoleDelegatedAccessRoles" + }, + "Yes" + ] + }, + "DirectoryMonitoringSNSTopicKMSKeyCondition": { + "Fn::Not": [ + { + "Fn::Equals": [ + { + "Ref": "DirectoryMonitoringSNSTopicKMSKey" + }, + "" + ] + } + ] + }, + "LambdaLogsCloudWatchKMSKeyCondition": { + "Fn::Not": [ + { + "Fn::Equals": [ + { + "Ref": "LambdaLogsCloudWatchKMSKey" + }, + "" + ] + } + ] + } + }, + "Resources": { + "DirectoryConsoleDelegatedAccessEC2ReadOnlyRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "Description": "IAM Role for Directory Service 'AWS Management Console' Delegated Access for \"EC2 ReadOnly\"", + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Principal": { + "Service": [ + "ds.amazonaws.com" + ] + }, + "Action": "sts:AssumeRole" + } + ] + }, + "ManagedPolicyArns": [ + { + "Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/AmazonEC2ReadOnlyAccess" + } + ], + "Path": "/", + "Tags": [ + { + "Key": "StackName", + "Value": { + "Ref": "AWS::StackName" + } + } + ] + }, + "Condition": "DirectoryConsoleDelegatedAccessRolesCondition" + }, + "DirectoryConsoleDelegatedAccessSecurityAuditRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "Description": "IAM Role for Directory Service 'AWS Management Console' Delegated Access for \"Security Audit\"", + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Principal": { + "Service": [ + "ds.amazonaws.com" + ] + }, + "Action": "sts:AssumeRole" + } + ] + }, + "ManagedPolicyArns": [ + { + "Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/SecurityAudit" + } + ], + "Path": "/", + "Tags": [ + { + "Key": "StackName", + "Value": { + "Ref": "AWS::StackName" + } + } + ] + }, + "Condition": "DirectoryConsoleDelegatedAccessRolesCondition" + }, + "DirectoryMonitoringTopic": { + "Type": "AWS::SNS::Topic", + "Properties": { + "KmsMasterKeyId": { + "Fn::If": [ + "DirectoryMonitoringSNSTopicKMSKeyCondition", + { + "Ref": "DirectoryMonitoringSNSTopicKMSKey" + }, + "aws/sns" + ] + }, + "Subscription": [ + { + "Endpoint": { + "Ref": "DirectoryMonitoringEmail" + }, + "Protocol": "email" + } + ], + "Tags": [ + { + "Key": "StackName", + "Value": { + "Ref": "AWS::StackName" + } + }, + { + "Key": "DirectoryID", + "Value": { + "Ref": "DirectoryID" + } + } + ] + } + }, + "DirectorySettingsLambdaFunction": { + "Type": "AWS::Lambda::Function", + "Metadata": { + "cfn_nag": { + "rules_to_suppress": [ + { + "id": "W58", + "reason": "Permissions to write to CloudWatch Logs provided by the attached IAM role" + } + ] + } + }, + "Properties": { + "FunctionName": { + "Ref": "LambdaFunctionName" + }, + "Handler": "directory_settings_custom_resource.lambda_handler", + "Role": { + "Fn::GetAtt": [ + "DirectorySettingsLambdaRole", + "Arn" + ] + }, + "Runtime": "python3.12", + "MemorySize": 128, + "Timeout": 120, + "Environment": { + "Variables": { + "LOG_LEVEL": { + "Ref": "LambdaLogLevel" + } + } + }, + "Code": { + "S3Bucket": { + "Ref": "LambdaS3BucketName" + }, + "S3Key": { + "Ref": "LambdaZipFileName" + } + }, + "VpcConfig": { + "SubnetIds": { + "Ref": "Subnets" + }, + "SecurityGroupIds": { + "Ref": "SecurityGroups" + } + } + } + }, + "DirectorySettingsLambdaLogsLogGroup": { + "Type": "AWS::Logs::LogGroup", + "Properties": { + "LogGroupName": { + "Fn::Sub": "/aws/lambda/${LambdaFunctionName}" + }, + "RetentionInDays": { + "Ref": "LambdaLogsLogGroupRetention" + }, + "KmsKeyId": { + "Fn::If": [ + "LambdaLogsCloudWatchKMSKeyCondition", + { + "Ref": "LambdaLogsCloudWatchKMSKey" + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + }, + "DirectorySettingsLambdaRole": { + "Type": "AWS::IAM::Role", + "Metadata": { + "cfn_nag": { + "rules_to_suppress": [ + { + "id": "W11", + "reason": "Allow * in resource when required" + }, + { + "id": "W28", + "reason": "The role name is defined to identify automation resources" + } + ] + } + }, + "Properties": { + "RoleName": { + "Fn::Sub": "${LambdaFunctionName}-LambdaRole" + }, + "Description": { + "Fn::Sub": "Rights to Setup Directory Settings for Directory ID, ${DirectoryID}" + }, + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": "sts:AssumeRole", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "Path": "/", + "Tags": [ + { + "Key": "StackName", + "Value": { + "Ref": "AWS::StackName" + } + } + ], + "Policies": [ + { + "PolicyName": "CloudWatchLogGroup", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Sid": "CreateLogGroup", + "Effect": "Allow", + "Action": "logs:CreateLogGroup", + "Resource": { + "Fn::Sub": "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:${DirectorySettingsLambdaLogsLogGroup}" + } + }, + { + "Sid": "CreateLogStreamAndEvents", + "Effect": "Allow", + "Action": [ + "logs:CreateLogStream", + "logs:PutLogEvents" + ], + "Resource": { + "Fn::Sub": "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:${DirectorySettingsLambdaLogsLogGroup}:log-stream:*" + } + } + ] + } + }, + { + "PolicyName": "DirectorySettings", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Sid": "SnsTopic", + "Effect": "Allow", + "Action": [ + "ds:RegisterEventTopic", + "ds:DeregisterEventTopic", + "ds:DescribeEventTopics" + ], + "Resource": { + "Fn::Sub": "arn:${AWS::Partition}:ds:${AWS::Region}:${AWS::AccountId}:directory/${DirectoryID}" + } + }, + { + "Sid": "DescribeDirectories", + "Effect": "Allow", + "Action": "ds:DescribeDirectories", + "Resource": "*" + }, + { + "Sid": "AliasSso", + "Effect": "Allow", + "Action": [ + "ds:CreateAlias", + "ds:EnableSso", + "ds:DisableSso" + ], + "Resource": { + "Fn::Sub": "arn:${AWS::Partition}:ds:${AWS::Region}:${AWS::AccountId}:directory/${DirectoryID}" + } + } + ] + } + } + ] + } + }, + "DirectorySettingsResource": { + "Type": "Custom::DirectorySettingsResource", + "Properties": { + "ServiceToken": { + "Fn::GetAtt": [ + "DirectorySettingsLambdaFunction", + "Arn" + ] + }, + "DirectoryId": { + "Ref": "DirectoryID" + }, + "CreateDirectoryAlias": { + "Ref": "CreateDirectoryAlias" + }, + "EnableDirectorySSO": { + "Ref": "EnableDirectorySSO" + }, + "DirectoryAlias": { + "Ref": "DirectoryAlias" + }, + "DirectoryMonitoringTopicName": { + "Fn::GetAtt": [ + "DirectoryMonitoringTopic", + "TopicName" + ] + } + }, + "Version": "1.0" + } + }, + "Outputs": { + "DirectoryAliasUrl": { + "Description": "Directory Alias", + "Value": { + "Fn::GetAtt": [ + "DirectorySettingsResource", + "AliasUrl" + ] + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/DirectoryServiceSettings/templates/DIRECTORY_SETTINGS.cfn.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/DirectoryServiceSettings/templates/DIRECTORY_SETTINGS.cfn.yaml new file mode 100644 index 0000000000000000000000000000000000000000..78bf1e229621714481eb66d8a3d7fee06f4e7800 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/DirectoryServiceSettings/templates/DIRECTORY_SETTINGS.cfn.yaml @@ -0,0 +1,369 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: This templates updates the settings for an AD Connector or AWS Managed AD directory. Tasks accomplied, (1) enables directory monitoring (2) option to create a custom access url (alias) (3) option to enable SSO via directory services. Note, deleting the directory, will only remove directory monitoring, directory SSO or alias settings will not be touched. + +Metadata: + AWS::CloudFormation::Interface: + ParameterGroups: + - Label: + default: Directory Services Configuration + Parameters: + - DirectoryID + - DirectoryMonitoringEmail + - DirectoryMonitoringSNSTopicKMSKey + - EnableDirectorySSO + - CreateDirectoryAlias + - DirectoryAlias + - CreateDirectoryConsoleDelegatedAccessRoles + - Label: + default: Lambda Function Configuration (Directory Settings Custom Resource) + Parameters: + - LambdaFunctionName + - LambdaS3BucketName + - LambdaZipFileName + - LambdaLogsLogGroupRetention + - LambdaLogsCloudWatchKMSKey + - LambdaLogLevel + ParameterLabels: + CreateDirectoryConsoleDelegatedAccessRoles: + default: Create Directory Console Delegated Access Roles + CreateDirectoryAlias: + default: Create Directory Alias + DirectoryAlias: + default: Directory Alias + DirectoryID: + default: ID of the Directory (e.g., d-906764663a) + DirectoryMonitoringEmail: + default: Directory Monitoring Email + DirectoryMonitoringSNSTopicKMSKey: + default: SNS Topic KMS Key for Directory Monitoring messages + EnableDirectorySSO: + default: Enable Directory SSO + LambdaFunctionName: + default: Lambda Function Name + LambdaLogLevel: + default: Lambda Log Level + LambdaLogsLogGroupRetention: + default: CloudWatch log retention days for Lambda logs + LambdaLogsCloudWatchKMSKey: + default: CloudWatch Logs KMS Key for Lambda logs + LambdaS3BucketName: + default: Lambda S3 Bucket Name + LambdaZipFileName: + default: Lambda Zip File Name + +Parameters: + CreateDirectoryConsoleDelegatedAccessRoles: + Description: Create sample IAM ROLES that can be used to delegate users/groups access to certain areas of the AWS Management Console. User/Group assignment to these IAM roles has to be done manually via Directory Services -> Directory -> Application Management Tab. + Type: String + AllowedValues: + - Yes + - No + Default: No + + CreateDirectoryAlias: + Description: Create an alias for the directory. The alias is used to construct the access URL for the directory, such as http://.awsapps.com. NOTE, after an alias has been created, it cannot be deleted or reused. Hence if a different alias already exists, then you must use the existing alias (also shown in CloudFormation error). + Type: String + AllowedValues: + - Yes + - No + Default: No + + DirectoryAlias: + Description: (Optional) Specifies an alias to be assigned to the directory, such as http://.awsapps.com. Note, after alias is created it cannot be deleted or reused. Note, will only be set, if `CreateDirectoryAlias` parameter, has a value of `Yes`. + Type: String + AllowedPattern: ^$|^(?!d-)([\da-zA-Z]+)([-]*[\da-zA-Z])*$ + MaxLength: 62 + + DirectoryID: + Description: Directory ID that will have settings updated + Type: String + AllowedPattern: ^d-[0-9a-f]{10}$ + + DirectoryMonitoringEmail: + Description: Email for SNS Topic to monitor directory changes. + Type: String + AllowedPattern: ^[\w%+.-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,63}$ + + DirectoryMonitoringSNSTopicKMSKey: + Description: (Optional) KMS Key ID to use for encrypting the directory monitoring SNS topic messages. If empty, encryption is enabled with SNS managing the server-side encryption keys. + Type: String + AllowedPattern: ^$|^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$ + ConstraintDescription: 'Key ID example: 1234abcd-12ab-34cd-56ef-1234567890ab' + + EnableDirectorySSO: + Description: Enable single sign-on for a directory. Single sign-on allows users in your directory to access certain AWS services from a computer joined to the directory without having to enter their credentials separately. If true, "DirectoryAlias" must also be true, & "DirectoryAlias" parameter input required. + Type: String + AllowedValues: + - Yes + - No + Default: No + + LambdaFunctionName: + Description: Lambda Function Name for Custom Resource + Type: String + Default: CR-DirectorySettings + AllowedPattern: ^[\w-]{1,64}$ + ConstraintDescription: Max 64 alphanumeric characters. Also special characters supported [_, -] + + LambdaLogLevel: + Description: Lambda logging level + Type: String + AllowedValues: + - INFO + - DEBUG + Default: INFO + + LambdaLogsLogGroupRetention: + Description: Specifies the number of days you want to retain Lambda log events in the CloudWatch Logs + Type: String + AllowedValues: + - 1 + - 3 + - 5 + - 7 + - 14 + - 30 + - 60 + - 90 + - 120 + - 150 + - 180 + - 365 + - 400 + - 545 + - 731 + - 1827 + - 3653 + Default: 14 + + LambdaLogsCloudWatchKMSKey: + Description: (Optional) KMS Key ARN to use for encrypting the Lambda logs data. If empty, encryption is enabled with CloudWatch Logs managing the server-side encryption keys. + Type: String + AllowedPattern: ^$|^arn:(aws[a-zA-Z-]*)?:kms:[a-z0-9-]+:\d{12}:key\/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$ + ConstraintDescription: 'Key ARN example: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab' + + LambdaS3BucketName: + Description: Lambda S3 bucket name for the Lambda deployment package. Lambda bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-). + Type: String + AllowedPattern: (?=^.{3,63}$)(?!.*[.-]{2})(?!.*[--]{2})(?!^(?:(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\.(?!$)|$)){4}$)(^(([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])\.)*([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])$) + ConstraintDescription: Lambda S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-). + + LambdaZipFileName: + Description: Amazon S3 key of the deployment package. + Type: String + Default: directory_settings_custom_resource.zip + MaxLength: 1024 + MinLength: 1 + + Subnets: + Type: List + + SecurityGroups: + Type: List + +Rules: + CreateDirectoryAlias: + RuleCondition: !Equals + - !Ref CreateDirectoryAlias + - Yes + Assertions: + - Assert: !Not + - !Equals + - !Ref DirectoryAlias + - "" + AssertDescription: To create directory alias, the parameter, `DirectoryAlias` must be set + + EnableDirectorySSO: + RuleCondition: !Equals + - !Ref EnableDirectorySSO + - Yes + Assertions: + - Assert: !Equals + - !Ref CreateDirectoryAlias + - Yes + AssertDescription: To enable directory SSO, the parameter, `CreateDirectoryAlias` must be set to `Yes` + +Conditions: + DirectoryConsoleDelegatedAccessRolesCondition: !Equals + - !Ref CreateDirectoryConsoleDelegatedAccessRoles + - Yes + + DirectoryMonitoringSNSTopicKMSKeyCondition: !Not + - !Equals + - !Ref DirectoryMonitoringSNSTopicKMSKey + - "" + + LambdaLogsCloudWatchKMSKeyCondition: !Not + - !Equals + - !Ref LambdaLogsCloudWatchKMSKey + - "" + +Resources: + DirectoryConsoleDelegatedAccessEC2ReadOnlyRole: + Type: AWS::IAM::Role + Properties: + Description: IAM Role for Directory Service 'AWS Management Console' Delegated Access for "EC2 ReadOnly" + AssumeRolePolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Principal: + Service: + - ds.amazonaws.com + Action: sts:AssumeRole + ManagedPolicyArns: + - !Sub arn:${AWS::Partition}:iam::aws:policy/AmazonEC2ReadOnlyAccess + Path: / + Tags: + - Key: StackName + Value: !Ref AWS::StackName + Condition: DirectoryConsoleDelegatedAccessRolesCondition + + DirectoryConsoleDelegatedAccessSecurityAuditRole: + Type: AWS::IAM::Role + Properties: + Description: IAM Role for Directory Service 'AWS Management Console' Delegated Access for "Security Audit" + AssumeRolePolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Principal: + Service: + - ds.amazonaws.com + Action: sts:AssumeRole + ManagedPolicyArns: + - !Sub arn:${AWS::Partition}:iam::aws:policy/SecurityAudit + Path: / + Tags: + - Key: StackName + Value: !Ref AWS::StackName + Condition: DirectoryConsoleDelegatedAccessRolesCondition + + DirectoryMonitoringTopic: + Type: AWS::SNS::Topic + Properties: + KmsMasterKeyId: !If + - DirectoryMonitoringSNSTopicKMSKeyCondition + - !Ref DirectoryMonitoringSNSTopicKMSKey + - aws/sns + Subscription: + - Endpoint: !Ref DirectoryMonitoringEmail + Protocol: email + Tags: + - Key: StackName + Value: !Ref AWS::StackName + - Key: DirectoryID + Value: !Ref DirectoryID + + DirectorySettingsLambdaFunction: + Type: AWS::Lambda::Function + Metadata: + cfn_nag: + rules_to_suppress: + - id: W58 + reason: Permissions to write to CloudWatch Logs provided by the attached IAM role + Properties: + FunctionName: !Ref LambdaFunctionName + Handler: directory_settings_custom_resource.lambda_handler + Role: !GetAtt DirectorySettingsLambdaRole.Arn + Runtime: python3.12 + MemorySize: 128 + Timeout: 120 + Environment: + Variables: + LOG_LEVEL: !Ref LambdaLogLevel + Code: + S3Bucket: !Ref LambdaS3BucketName + S3Key: !Ref LambdaZipFileName + VpcConfig: + SubnetIds: !Ref Subnets + SecurityGroupIds: !Ref SecurityGroups + + DirectorySettingsLambdaLogsLogGroup: + Type: AWS::Logs::LogGroup + Properties: + LogGroupName: !Sub /aws/lambda/${LambdaFunctionName} + RetentionInDays: !Ref LambdaLogsLogGroupRetention + KmsKeyId: !If + - LambdaLogsCloudWatchKMSKeyCondition + - !Ref LambdaLogsCloudWatchKMSKey + - !Ref AWS::NoValue + + DirectorySettingsLambdaRole: + Type: AWS::IAM::Role + Metadata: + cfn_nag: + rules_to_suppress: + - id: W11 + reason: Allow * in resource when required + - id: W28 + reason: The role name is defined to identify automation resources + Properties: + RoleName: !Sub ${LambdaFunctionName}-LambdaRole + Description: !Sub Rights to Setup Directory Settings for Directory ID, ${DirectoryID} + AssumeRolePolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: sts:AssumeRole + Principal: + Service: + - lambda.amazonaws.com + Path: / + Tags: + - Key: StackName + Value: !Ref AWS::StackName + Policies: + - PolicyName: CloudWatchLogGroup + PolicyDocument: + Version: "2012-10-17" + Statement: + - Sid: CreateLogGroup + Effect: Allow + Action: logs:CreateLogGroup + Resource: !Sub arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:${DirectorySettingsLambdaLogsLogGroup} + - Sid: CreateLogStreamAndEvents + Effect: Allow + Action: + - logs:CreateLogStream + - logs:PutLogEvents + Resource: !Sub arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:${DirectorySettingsLambdaLogsLogGroup}:log-stream:* + - PolicyName: DirectorySettings + PolicyDocument: + Version: "2012-10-17" + Statement: + - Sid: SnsTopic + Effect: Allow + Action: + - ds:RegisterEventTopic + - ds:DeregisterEventTopic + - ds:DescribeEventTopics + Resource: !Sub arn:${AWS::Partition}:ds:${AWS::Region}:${AWS::AccountId}:directory/${DirectoryID} + - Sid: DescribeDirectories + Effect: Allow + Action: ds:DescribeDirectories + Resource: '*' + - Sid: AliasSso + Effect: Allow + Action: + - ds:CreateAlias + - ds:EnableSso + - ds:DisableSso + Resource: !Sub arn:${AWS::Partition}:ds:${AWS::Region}:${AWS::AccountId}:directory/${DirectoryID} + + DirectorySettingsResource: + Type: Custom::DirectorySettingsResource + Properties: + ServiceToken: !GetAtt DirectorySettingsLambdaFunction.Arn + DirectoryId: !Ref DirectoryID + CreateDirectoryAlias: !Ref CreateDirectoryAlias + EnableDirectorySSO: !Ref EnableDirectorySSO + DirectoryAlias: !Ref DirectoryAlias + DirectoryMonitoringTopicName: !GetAtt DirectoryMonitoringTopic.TopicName + Version: "1.0" + +Outputs: + DirectoryAliasUrl: + Description: Directory Alias + Value: !GetAtt DirectorySettingsResource.AliasUrl diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/EC2DomainJoin/EC2-Domain-Join.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/EC2DomainJoin/EC2-Domain-Join.json new file mode 100644 index 0000000000000000000000000000000000000000..437f7bb0f20e56c210897d053649a0ac6ad91616 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/EC2DomainJoin/EC2-Domain-Join.json @@ -0,0 +1,246 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "Join Windows instance to AWS-Active Directory or Microsoft AD (no powershell). Create SSM document, IAM Role, SSM doc and EC2 Instance. Attaches EC2 instance to AD. Will need to use Domain Logins to RDP in.", + "Parameters": { + "AMI": { + "Description": "Windows 2016 AMI available in your region", + "Type": "AWS::EC2::Image::Id" + }, + "KeyPair": { + "Description": "KeyPair for EC2 Instance", + "Type": "AWS::EC2::KeyPair::KeyName" + }, + "PublicSubnet": { + "Description": "Subnet to place instance in", + "Type": "AWS::EC2::Subnet::Id" + }, + "VPC": { + "Description": "VPC to place instance in", + "Type": "AWS::EC2::VPC::Id" + }, + "InstanceType": { + "Type": "String", + "AllowedValues": [ + "t1.micro", + "t2.micro", + "t2.small", + "t2.medium", + "m1.small", + "m1.medium", + "m1.large", + "m1.xlarge", + "m2.xlarge", + "m2.2xlarge", + "m2.4xlarge", + "m3.medium", + "m3.large", + "m3.xlarge", + "m3.2xlarge", + "c1.medium", + "c1.xlarge", + "c3.large", + "c3.xlarge", + "c3.2xlarge", + "c3.4xlarge", + "c3.8xlarge", + "c4.large", + "c4.xlarge", + "c4.2xlarge", + "c4.4xlarge", + "c4.8xlarge", + "g2.2xlarge", + "r3.large", + "r3.xlarge", + "r3.2xlarge", + "r3.4xlarge", + "r3.8xlarge", + "i2.xlarge", + "i2.2xlarge", + "i2.4xlarge", + "i2.8xlarge", + "d2.xlarge", + "d2.2xlarge", + "d2.4xlarge", + "d2.8xlarge", + "hs1.8xlarge", + "cr1.8xlarge", + "cc2.8xlarge" + ], + "Default": "t2.small", + "ConstraintDescription": "Must be a valid EC2 instance type." + }, + "ADDirectoryId": { + "Description": "Active DirectoryId. Eg. d-12345679a", + "Type": "String" + }, + "ADDirectoryName": { + "Description": "Active Directory Name. Eg. my.ad.com", + "Type": "String" + }, + "ADDnsIpAddresses1": { + "Description": "Active Directory DNS 1. Eg. 10.0.0.142", + "Type": "String" + }, + "ADDnsIpAddresses2": { + "Description": "Active Directory DNS 2. Eg. 10.0.0.143", + "Type": "String" + } + }, + "Resources": { + "myssmdocument": { + "Type": "AWS::SSM::Document", + "Properties": { + "Content": { + "schemaVersion": "1.2", + "description": "Join instances to an AWS Directory Service domain.", + "parameters": { + "directoryId": { + "type": "String", + "description": "(Required) The ID of the AWS Directory Service directory." + }, + "directoryName": { + "type": "String", + "description": "(Required) The name of the directory; for example, test.example.com" + }, + "dnsIpAddresses": { + "type": "StringList", + "default": [], + "description": "(Optional) The IP addresses of the DNS servers in the directory. Required when DHCP is not configured. Learn more at http://docs.aws.amazon.com/directoryservice/latest/simple-ad/join_get_dns_addresses.html", + "allowedPattern": "((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" + } + }, + "runtimeConfig": { + "aws:domainJoin": { + "properties": { + "directoryId": "{{ directoryId }}", + "directoryName": "{{ directoryName }}", + "dnsIpAddresses": "{{ dnsIpAddresses }}" + } + } + } + } + } + }, + "myEC2InstanceSSM": { + "Type": "AWS::EC2::Instance", + "Properties": { + "IamInstanceProfile": { + "Ref": "myInstanceProfile" + }, + "SsmAssociations": [ + { + "DocumentName": { + "Ref": "myssmdocument" + }, + "AssociationParameters": [ + { + "Key": "directoryId", + "Value": [ + { + "Ref": "ADDirectoryId" + } + ] + }, + { + "Key": "directoryName", + "Value": [ + { + "Ref": "ADDirectoryName" + } + ] + }, + { + "Key": "dnsIpAddresses", + "Value": [ + { + "Ref": "ADDnsIpAddresses1" + }, + { + "Ref": "ADDnsIpAddresses2" + } + ] + } + ] + } + ], + "KeyName": { + "Ref": "KeyPair" + }, + "ImageId": { + "Ref": "AMI" + }, + "InstanceType": { + "Ref": "InstanceType" + }, + "Tags": [ + { + "Key": "Name", + "Value": "myEC2InstanceSSM" + } + ], + "SubnetId": { + "Ref": "PublicSubnet" + }, + "SecurityGroupIds": [ + { + "Fn::GetAtt": [ + "InstanceSecurityGroup", + "GroupId" + ] + } + ] + } + }, + "myInstanceProfile": { + "Type": "AWS::IAM::InstanceProfile", + "Properties": { + "Roles": [ + "DemoEC2SSMRole" + ], + "InstanceProfileName": "myEC2SSMRole" + } + }, + "myEC2SSMRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Principal": { + "Service": [ + "ec2.amazonaws.com" + ] + }, + "Action": [ + "sts:AssumeRole" + ] + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforSSM" + ], + "RoleName": "DemoEC2SSMRole" + } + }, + "InstanceSecurityGroup": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "Allow http to client host", + "VpcId": { + "Ref": "VPC" + }, + "SecurityGroupIngress": [ + { + "IpProtocol": "tcp", + "FromPort": "3389", + "ToPort": "3389", + "CidrIp": "0.0.0.0/0" + } + ] + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/EC2DomainJoin/EC2-Domain-Join.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/EC2DomainJoin/EC2-Domain-Join.yaml new file mode 100644 index 0000000000000000000000000000000000000000..36cbe30b690230a1b004eeadce2e88083f409057 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/EC2DomainJoin/EC2-Domain-Join.yaml @@ -0,0 +1,173 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: Join Windows instance to AWS-Active Directory or Microsoft AD (no powershell). Create SSM document, IAM Role, SSM doc and EC2 Instance. Attaches EC2 instance to AD. Will need to use Domain Logins to RDP in. + +Parameters: + AMI: + Description: Windows 2016 AMI available in your region + Type: AWS::EC2::Image::Id + + KeyPair: + Description: KeyPair for EC2 Instance + Type: AWS::EC2::KeyPair::KeyName + + PublicSubnet: + Description: Subnet to place instance in + Type: AWS::EC2::Subnet::Id + + VPC: + Description: VPC to place instance in + Type: AWS::EC2::VPC::Id + + InstanceType: + Type: String + AllowedValues: + - t1.micro + - t2.micro + - t2.small + - t2.medium + - m1.small + - m1.medium + - m1.large + - m1.xlarge + - m2.xlarge + - m2.2xlarge + - m2.4xlarge + - m3.medium + - m3.large + - m3.xlarge + - m3.2xlarge + - c1.medium + - c1.xlarge + - c3.large + - c3.xlarge + - c3.2xlarge + - c3.4xlarge + - c3.8xlarge + - c4.large + - c4.xlarge + - c4.2xlarge + - c4.4xlarge + - c4.8xlarge + - g2.2xlarge + - r3.large + - r3.xlarge + - r3.2xlarge + - r3.4xlarge + - r3.8xlarge + - i2.xlarge + - i2.2xlarge + - i2.4xlarge + - i2.8xlarge + - d2.xlarge + - d2.2xlarge + - d2.4xlarge + - d2.8xlarge + - hs1.8xlarge + - cr1.8xlarge + - cc2.8xlarge + Default: t2.small + ConstraintDescription: Must be a valid EC2 instance type. + + ADDirectoryId: + Description: Active DirectoryId. Eg. d-12345679a + Type: String + + ADDirectoryName: + Description: Active Directory Name. Eg. my.ad.com + Type: String + + ADDnsIpAddresses1: + Description: Active Directory DNS 1. Eg. 10.0.0.142 + Type: String + + ADDnsIpAddresses2: + Description: Active Directory DNS 2. Eg. 10.0.0.143 + Type: String + +Resources: + myssmdocument: + Type: AWS::SSM::Document + Properties: + Content: + schemaVersion: "1.2" + description: Join instances to an AWS Directory Service domain. + parameters: + directoryId: + type: String + description: (Required) The ID of the AWS Directory Service directory. + directoryName: + type: String + description: (Required) The name of the directory; for example, test.example.com + dnsIpAddresses: + type: StringList + default: [] + description: (Optional) The IP addresses of the DNS servers in the directory. Required when DHCP is not configured. Learn more at http://docs.aws.amazon.com/directoryservice/latest/simple-ad/join_get_dns_addresses.html + allowedPattern: ((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) + runtimeConfig: + aws:domainJoin: + properties: + directoryId: '{{ directoryId }}' + directoryName: '{{ directoryName }}' + dnsIpAddresses: '{{ dnsIpAddresses }}' + + myEC2InstanceSSM: + Type: AWS::EC2::Instance + Properties: + IamInstanceProfile: !Ref myInstanceProfile + SsmAssociations: + - DocumentName: !Ref myssmdocument + AssociationParameters: + - Key: directoryId + Value: + - !Ref ADDirectoryId + - Key: directoryName + Value: + - !Ref ADDirectoryName + - Key: dnsIpAddresses + Value: + - !Ref ADDnsIpAddresses1 + - !Ref ADDnsIpAddresses2 + KeyName: !Ref KeyPair + ImageId: !Ref AMI + InstanceType: !Ref InstanceType + Tags: + - Key: Name + Value: myEC2InstanceSSM + SubnetId: !Ref PublicSubnet + SecurityGroupIds: + - !GetAtt InstanceSecurityGroup.GroupId + + myInstanceProfile: + Type: AWS::IAM::InstanceProfile + Properties: + Roles: + - DemoEC2SSMRole + InstanceProfileName: myEC2SSMRole + + myEC2SSMRole: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Principal: + Service: + - ec2.amazonaws.com + Action: + - sts:AssumeRole + ManagedPolicyArns: + - arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforSSM + RoleName: DemoEC2SSMRole + + InstanceSecurityGroup: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Allow http to client host + VpcId: !Ref VPC + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: "3389" + ToPort: "3389" + CidrIp: 0.0.0.0/0 diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/EC2DomainJoin/README.MD b/human_reference_dataset/aws-cloudformation-templates/Solutions/EC2DomainJoin/README.MD new file mode 100644 index 0000000000000000000000000000000000000000..6bd66cf10a2d4ca5e98a87b666c64392964d0bc7 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/EC2DomainJoin/README.MD @@ -0,0 +1,18 @@ +# Join a new EC2 Windows to AD with no Powershelll + +Cloudformation template that will join a new Windows Server instance to Active Directory without powershell in UserData. + +Template will invoke the following: + +- Create SSM Document +- Create IAM Role for the EC2 instance with the AWS Managed policy 'AmazonEC2RoleforSSM' +- Create EC2 Instance +- Attach the SSM document and IAM role to EC2 Instance +- Join EC2 instance to the Domain using EC2::Instance -> SsmAssociations +Prerequisites. + +AWS Simple AD or Microsoft AD and have the following details: + +- Directory ID +- Directory Name +- DNS Addresses \ No newline at end of file diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/GitLab/GitLabServer-pkg.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/GitLab/GitLabServer-pkg.json new file mode 100644 index 0000000000000000000000000000000000000000..f2cb9658ac73ee2728c0eb3453ba99bdf50a8ecd --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/GitLab/GitLabServer-pkg.json @@ -0,0 +1,736 @@ +{ + "Parameters": { + "LatestAMI": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64" + }, + "InstanceType": { + "Type": "String", + "Default": "m5.large" + } + }, + "Mappings": { + "Prefixes": { + "ap-northeast-1": { + "PrefixList": "pl-58a04531" + }, + "ap-northeast-2": { + "PrefixList": "pl-22a6434b" + }, + "ap-south-1": { + "PrefixList": "pl-9aa247f3" + }, + "ap-southeast-1": { + "PrefixList": "pl-31a34658" + }, + "ap-southeast-2": { + "PrefixList": "pl-b8a742d1" + }, + "ca-central-1": { + "PrefixList": "pl-38a64351" + }, + "eu-central-1": { + "PrefixList": "pl-a3a144ca" + }, + "eu-north-1": { + "PrefixList": "pl-fab65393" + }, + "eu-west-1": { + "PrefixList": "pl-4fa04526" + }, + "eu-west-2": { + "PrefixList": "pl-93a247fa" + }, + "eu-west-3": { + "PrefixList": "pl-75b1541c" + }, + "sa-east-1": { + "PrefixList": "pl-5da64334" + }, + "us-east-1": { + "PrefixList": "pl-3b927c52" + }, + "us-east-2": { + "PrefixList": "pl-b6a144df" + }, + "us-west-1": { + "PrefixList": "pl-4ea04527" + }, + "us-west-2": { + "PrefixList": "pl-82a045eb" + } + } + }, + "Resources": { + "InstanceSecurityGroup": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "gitlab-server-isg", + "SecurityGroupIngress": [ + { + "Description": "Allow HTTP from com.amazonaws.global.cloudfront.origin-facing", + "IpProtocol": "tcp", + "FromPort": 80, + "ToPort": 80, + "SourcePrefixListId": { + "Fn::FindInMap": [ + "Prefixes", + { + "Ref": "AWS::Region" + }, + "PrefixList" + ] + } + } + ], + "SecurityGroupEgress": [ + { + "CidrIp": "0.0.0.0/0", + "Description": "Allow all outbound traffic by default", + "IpProtocol": "-1" + } + ], + "Tags": [ + { + "Key": "Name", + "Value": "gitlab-server-isg" + } + ], + "VpcId": { + "Ref": "NetworkVPC" + } + } + }, + "InstanceRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ec2.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "Tags": [ + { + "Key": "Name", + "Value": "gitlab-server-instance" + } + ] + } + }, + "InstanceRolePolicy": { + "Type": "AWS::IAM::RolePolicy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "ec2messages:*", + "ssm:UpdateInstanceInformation", + "ssmmessages:*", + "secretsmanager:GetSecretValue" + ], + "Effect": "Allow", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "InstanceRolePolicy", + "RoleName": { + "Ref": "InstanceRole" + } + } + }, + "InstanceProfile": { + "Type": "AWS::IAM::InstanceProfile", + "Properties": { + "Roles": [ + { + "Ref": "InstanceRole" + } + ] + } + }, + "Server": { + "Type": "AWS::EC2::Instance", + "DependsOn": [ + "InstanceRolePolicy", + "InstanceRole" + ], + "Properties": { + "AvailabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": null + } + ] + }, + "BlockDeviceMappings": [ + { + "DeviceName": "/dev/xvda", + "Ebs": { + "VolumeSize": 128 + } + } + ], + "IamInstanceProfile": { + "Ref": "InstanceProfile" + }, + "ImageId": { + "Ref": "LatestAMI" + }, + "InstanceType": { + "Ref": "InstanceType" + }, + "SecurityGroupIds": [ + { + "Fn::GetAtt": [ + "InstanceSecurityGroup", + "GroupId" + ] + } + ], + "SubnetId": { + "Fn::GetAtt": [ + "NetworkPublicSubnet1", + "SubnetId" + ] + }, + "Tags": [ + { + "Key": "Name", + "Value": "gitlab-server" + } + ], + "UserData": { + "Fn::Base64": { + "Fn::Sub": "#!/bin/bash\n\nset -eou pipefail\n\nlocal_ip=$(ec2-metadata | grep \"^local-ipv4: \" | cut -d \" \" -f 2)\n\n# Install cfn-signal\nyum install -y aws-cfn-bootstrap\n\n# Install postfix\nyum install -y postfix\nsystemctl enable postfix\nsystemctl start postfix\n\n# Get the yum repo\ncurl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash\n\n# Install gitlab and run it on the local ip\nexport EXTERNAL_URL=\"http://$local_ip\" \nyum install -y gitlab-ee\n\n# Tell CloudFormation we're ready to go\n# This is a variable for the Sub intrisic function, not a bash variable\ncfn-signal -s true --stack ${AWS::StackName} --resource Server --region ${AWS::Region}" + } + } + } + }, + "NetworkVPC": { + "Type": "AWS::EC2::VPC", + "Properties": { + "CidrBlock": "10.0.0.0/16", + "EnableDnsHostnames": true, + "EnableDnsSupport": true, + "InstanceTenancy": "default", + "Tags": [ + { + "Key": "Name", + "Value": "gitlab-server" + } + ] + } + }, + "NetworkPublicSubnet1": { + "Type": "AWS::EC2::Subnet", + "Metadata": { + "guard": { + "SuppressedRules": [ + "SUBNET_AUTO_ASSIGN_PUBLIC_IP_DISABLED" + ] + } + }, + "Properties": { + "AvailabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": { + "Ref": "AWS::Region" + } + } + ] + }, + "CidrBlock": "10.0.0.0/18", + "MapPublicIpOnLaunch": true, + "VpcId": { + "Ref": "NetworkVPC" + }, + "Tags": [ + { + "Key": "Name", + "Value": "gitlab-server-public-subnet-1" + } + ] + } + }, + "NetworkPublicSubnet1RouteTable": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "NetworkVPC" + }, + "Tags": [ + { + "Key": "Name", + "Value": "gitlab-server-public-subnet-1-rt" + } + ] + } + }, + "NetworkPublicSubnet1RouteTableAssociation": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "NetworkPublicSubnet1RouteTable" + }, + "SubnetId": { + "Ref": "NetworkPublicSubnet1" + } + } + }, + "NetworkPublicSubnet1DefaultRoute": { + "Type": "AWS::EC2::Route", + "DependsOn": [ + "NetworkVPCGW" + ], + "Metadata": { + "guard": { + "SuppressedRules": [ + "NO_UNRESTRICTED_ROUTE_TO_IGW" + ] + } + }, + "Properties": { + "DestinationCidrBlock": "0.0.0.0/0", + "GatewayId": { + "Ref": "NetworkInternetGateway" + }, + "RouteTableId": { + "Ref": "NetworkPublicSubnet1RouteTable" + } + } + }, + "NetworkPublicSubnet1EIP": { + "Type": "AWS::EC2::EIP", + "Properties": { + "Domain": "vpc", + "Tags": [ + { + "Key": "Name", + "Value": "gitlab-server-public-subnet-1-eip" + } + ] + } + }, + "NetworkPublicSubnet1NATGateway": { + "Type": "AWS::EC2::NatGateway", + "DependsOn": [ + "NetworkPublicSubnet1DefaultRoute", + "NetworkPublicSubnet1RouteTableAssociation" + ], + "Properties": { + "AllocationId": { + "Fn::GetAtt": [ + "NetworkPublicSubnet1EIP", + "AllocationId" + ] + }, + "SubnetId": { + "Ref": "NetworkPublicSubnet1" + }, + "Tags": [ + { + "Key": "Name", + "Value": "gitlab-server-public-subnet-1-ngw" + } + ] + } + }, + "NetworkPublicSubnet2": { + "Type": "AWS::EC2::Subnet", + "Metadata": { + "guard": { + "SuppressedRules": [ + "SUBNET_AUTO_ASSIGN_PUBLIC_IP_DISABLED" + ] + } + }, + "Properties": { + "AvailabilityZone": { + "Fn::Select": [ + 1, + { + "Fn::GetAZs": { + "Ref": "AWS::Region" + } + } + ] + }, + "CidrBlock": "10.0.64.0/18", + "MapPublicIpOnLaunch": true, + "VpcId": { + "Ref": "NetworkVPC" + }, + "Tags": [ + { + "Key": "Name", + "Value": "gitlab-server-public-subnet-2" + } + ] + } + }, + "NetworkPublicSubnet2RouteTable": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "NetworkVPC" + }, + "Tags": [ + { + "Key": "Name", + "Value": "gitlab-server-public-subnet-2-rt" + } + ] + } + }, + "NetworkPublicSubnet2RouteTableAssociation": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "NetworkPublicSubnet2RouteTable" + }, + "SubnetId": { + "Ref": "NetworkPublicSubnet2" + } + } + }, + "NetworkPublicSubnet2DefaultRoute": { + "Type": "AWS::EC2::Route", + "DependsOn": [ + "NetworkVPCGW" + ], + "Metadata": { + "guard": { + "SuppressedRules": [ + "NO_UNRESTRICTED_ROUTE_TO_IGW" + ] + } + }, + "Properties": { + "DestinationCidrBlock": "0.0.0.0/0", + "GatewayId": { + "Ref": "NetworkInternetGateway" + }, + "RouteTableId": { + "Ref": "NetworkPublicSubnet2RouteTable" + } + } + }, + "NetworkPublicSubnet2EIP": { + "Type": "AWS::EC2::EIP", + "Properties": { + "Domain": "vpc", + "Tags": [ + { + "Key": "Name", + "Value": "gitlab-server-public-subnet-eip" + } + ] + } + }, + "NetworkPublicSubnet2NATGateway": { + "Type": "AWS::EC2::NatGateway", + "DependsOn": [ + "NetworkPublicSubnet2DefaultRoute", + "NetworkPublicSubnet2RouteTableAssociation" + ], + "Properties": { + "AllocationId": { + "Fn::GetAtt": [ + "NetworkPublicSubnet2EIP", + "AllocationId" + ] + }, + "SubnetId": { + "Ref": "NetworkPublicSubnet2" + }, + "Tags": [ + { + "Key": "Name", + "Value": "gitlab-server-public-subnet-ngw" + } + ] + } + }, + "NetworkPrivateSubnet1Subnet": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "AvailabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": { + "Ref": "AWS::Region" + } + } + ] + }, + "CidrBlock": "10.0.128.0/18", + "MapPublicIpOnLaunch": false, + "VpcId": { + "Ref": "NetworkVPC" + }, + "Tags": [ + { + "Key": "Name", + "Value": "gitlab-server-private-subnet-1" + } + ] + } + }, + "NetworkPrivateSubnet1RouteTable": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "NetworkVPC" + }, + "Tags": [ + { + "Key": "Name", + "Value": "gitlab-server-private-subnet-1-rt" + } + ] + } + }, + "NetworkPrivateSubnet1RouteTableAssociation": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "NetworkPrivateSubnet1RouteTable" + }, + "SubnetId": { + "Ref": "NetworkPrivateSubnet1Subnet" + } + } + }, + "NetworkPrivateSubnet1DefaultRoute": { + "Type": "AWS::EC2::Route", + "Properties": { + "DestinationCidrBlock": "0.0.0.0/0", + "NatGatewayId": { + "Ref": "NetworkPublicSubnet1NATGateway" + }, + "RouteTableId": { + "Ref": "NetworkPrivateSubnet1RouteTable" + } + } + }, + "NetworkPrivateSubnet2Subnet": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "AvailabilityZone": { + "Fn::Select": [ + 1, + { + "Fn::GetAZs": { + "Ref": "AWS::Region" + } + } + ] + }, + "CidrBlock": "10.0.192.0/18", + "MapPublicIpOnLaunch": false, + "VpcId": { + "Ref": "NetworkVPC" + }, + "Tags": [ + { + "Key": "Name", + "Value": "gitlab-server-private-subnet-2" + } + ] + } + }, + "NetworkPrivateSubnet2RouteTable": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "NetworkVPC" + }, + "Tags": [ + { + "Key": "Name", + "Value": "gitlab-server-private-subnet-2-rt" + } + ] + } + }, + "NetworkPrivateSubnet2RouteTableAssociation": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "NetworkPrivateSubnet2RouteTable" + }, + "SubnetId": { + "Ref": "NetworkPrivateSubnet2Subnet" + } + } + }, + "NetworkPrivateSubnet2DefaultRoute": { + "Type": "AWS::EC2::Route", + "Properties": { + "DestinationCidrBlock": "0.0.0.0/0", + "NatGatewayId": { + "Ref": "NetworkPublicSubnet2NATGateway" + }, + "RouteTableId": { + "Ref": "NetworkPrivateSubnet2RouteTable" + } + } + }, + "NetworkInternetGateway": { + "Type": "AWS::EC2::InternetGateway", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "gitlab-server" + } + ] + } + }, + "NetworkVPCGW": { + "Type": "AWS::EC2::VPCGatewayAttachment", + "Properties": { + "InternetGatewayId": { + "Ref": "NetworkInternetGateway" + }, + "VpcId": { + "Ref": "NetworkVPC" + } + } + }, + "CloudFrontCachePolicy": { + "Type": "AWS::CloudFront::CachePolicy", + "Properties": { + "CachePolicyConfig": { + "DefaultTTL": 86400, + "MaxTTL": 31536000, + "MinTTL": 1, + "Name": "gitlab-server", + "ParametersInCacheKeyAndForwardedToOrigin": { + "CookiesConfig": { + "CookieBehavior": "all" + }, + "EnableAcceptEncodingGzip": false, + "HeadersConfig": { + "HeaderBehavior": "whitelist", + "Headers": [ + "Accept-Charset", + "Authorization", + "Origin", + "Accept", + "Referer", + "Host", + "Accept-Language", + "Accept-Encoding", + "Accept-Datetime" + ] + }, + "QueryStringsConfig": { + "QueryStringBehavior": "all" + } + } + } + } + }, + "CloudFrontDistribution": { + "Type": "AWS::CloudFront::Distribution", + "DependsOn": [ + "Server" + ], + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "gitlab-server" + }, + { + "Key": "Description", + "Value": "gitlab-server" + } + ], + "DistributionConfig": { + "Enabled": true, + "HttpVersion": "http2", + "CacheBehaviors": [ + { + "AllowedMethods": [ + "GET", + "HEAD", + "OPTIONS", + "PUT", + "PATCH", + "POST", + "DELETE" + ], + "CachePolicyId": "4135ea2d-6df8-44a3-9df3-4b5a84be39ad", + "Compress": false, + "OriginRequestPolicyId": "216adef6-5c7f-47e4-b989-5492eafa07d3", + "TargetOriginId": { + "Fn::Sub": "CloudFront-${AWS::StackName}" + }, + "ViewerProtocolPolicy": "allow-all", + "PathPattern": "/proxy/*" + } + ], + "DefaultCacheBehavior": { + "AllowedMethods": [ + "GET", + "HEAD", + "OPTIONS", + "PUT", + "PATCH", + "POST", + "DELETE" + ], + "CachePolicyId": { + "Ref": "CloudFrontCachePolicy" + }, + "OriginRequestPolicyId": "216adef6-5c7f-47e4-b989-5492eafa07d3", + "TargetOriginId": { + "Fn::Sub": "CloudFront-${AWS::StackName}" + }, + "ViewerProtocolPolicy": "allow-all" + }, + "Origins": [ + { + "DomainName": { + "Fn::GetAtt": [ + "Server", + "PublicDnsName" + ] + }, + "Id": { + "Fn::Sub": "CloudFront-${AWS::StackName}" + }, + "CustomOriginConfig": { + "HTTPPort": 80, + "OriginProtocolPolicy": "http-only" + } + } + ] + } + } + } + }, + "Outputs": { + "URL": { + "Value": { + "Fn::Sub": "https://${CloudFrontDistribution.DomainName}/?folder=/home/ec2-user" + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/GitLab/GitLabServer-pkg.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/GitLab/GitLabServer-pkg.yaml new file mode 100644 index 0000000000000000000000000000000000000000..4365d6ea229980c9e90d427e522d9f674bb01a67 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/GitLab/GitLabServer-pkg.yaml @@ -0,0 +1,434 @@ +Parameters: + LatestAMI: + Type: AWS::SSM::Parameter::Value + Default: /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64 + + InstanceType: + Type: String + Default: m5.large + +Mappings: + Prefixes: + ap-northeast-1: + PrefixList: pl-58a04531 + ap-northeast-2: + PrefixList: pl-22a6434b + ap-south-1: + PrefixList: pl-9aa247f3 + ap-southeast-1: + PrefixList: pl-31a34658 + ap-southeast-2: + PrefixList: pl-b8a742d1 + ca-central-1: + PrefixList: pl-38a64351 + eu-central-1: + PrefixList: pl-a3a144ca + eu-north-1: + PrefixList: pl-fab65393 + eu-west-1: + PrefixList: pl-4fa04526 + eu-west-2: + PrefixList: pl-93a247fa + eu-west-3: + PrefixList: pl-75b1541c + sa-east-1: + PrefixList: pl-5da64334 + us-east-1: + PrefixList: pl-3b927c52 + us-east-2: + PrefixList: pl-b6a144df + us-west-1: + PrefixList: pl-4ea04527 + us-west-2: + PrefixList: pl-82a045eb + +Resources: + InstanceSecurityGroup: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: gitlab-server-isg + SecurityGroupIngress: + - Description: Allow HTTP from com.amazonaws.global.cloudfront.origin-facing + IpProtocol: tcp + FromPort: 80 + ToPort: 80 + SourcePrefixListId: !FindInMap + - Prefixes + - !Ref AWS::Region + - PrefixList + SecurityGroupEgress: + - CidrIp: 0.0.0.0/0 + Description: Allow all outbound traffic by default + IpProtocol: "-1" + Tags: + - Key: Name + Value: gitlab-server-isg + VpcId: !Ref NetworkVPC + + InstanceRole: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Statement: + - Action: sts:AssumeRole + Effect: Allow + Principal: + Service: ec2.amazonaws.com + Version: "2012-10-17" + Tags: + - Key: Name + Value: gitlab-server-instance + + InstanceRolePolicy: + Type: AWS::IAM::RolePolicy + Properties: + PolicyDocument: + Statement: + - Action: + - ec2messages:* + - ssm:UpdateInstanceInformation + - ssmmessages:* + - secretsmanager:GetSecretValue + Effect: Allow + Resource: '*' + Version: "2012-10-17" + PolicyName: InstanceRolePolicy + RoleName: !Ref InstanceRole + + InstanceProfile: + Type: AWS::IAM::InstanceProfile + Properties: + Roles: + - !Ref InstanceRole + + Server: + Type: AWS::EC2::Instance + DependsOn: + - InstanceRolePolicy + - InstanceRole + + #CreationPolicy: + #ResourceSignal: + #Timeout: PT30M + Properties: + AvailabilityZone: !Select + - 0 + - !GetAZs + BlockDeviceMappings: + - DeviceName: /dev/xvda + Ebs: + VolumeSize: 128 + IamInstanceProfile: !Ref InstanceProfile + ImageId: !Ref LatestAMI + InstanceType: !Ref InstanceType + SecurityGroupIds: + - !GetAtt InstanceSecurityGroup.GroupId + SubnetId: !GetAtt NetworkPublicSubnet1.SubnetId + Tags: + - Key: Name + Value: gitlab-server + UserData: !Base64 + Fn::Sub: "#!/bin/bash\n\nset -eou pipefail\n\nlocal_ip=$(ec2-metadata | grep \"^local-ipv4: \" | cut -d \" \" -f 2)\n\n# Install cfn-signal\nyum install -y aws-cfn-bootstrap\n\n# Install postfix\nyum install -y postfix\nsystemctl enable postfix\nsystemctl start postfix\n\n# Get the yum repo\ncurl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash\n\n# Install gitlab and run it on the local ip\nexport EXTERNAL_URL=\"http://$local_ip\" \nyum install -y gitlab-ee\n\n# Tell CloudFormation we're ready to go\n# This is a variable for the Sub intrisic function, not a bash variable\ncfn-signal -s true --stack ${AWS::StackName} --resource Server --region ${AWS::Region}" + + NetworkVPC: + Type: AWS::EC2::VPC + Properties: + CidrBlock: 10.0.0.0/16 + EnableDnsHostnames: true + EnableDnsSupport: true + InstanceTenancy: default + Tags: + - Key: Name + Value: gitlab-server + + NetworkPublicSubnet1: + Type: AWS::EC2::Subnet + Properties: + AvailabilityZone: !Select + - 0 + - !GetAZs + Ref: AWS::Region + CidrBlock: 10.0.0.0/18 + MapPublicIpOnLaunch: true + VpcId: !Ref NetworkVPC + Tags: + - Key: Name + Value: gitlab-server-public-subnet-1 + Metadata: + guard: + SuppressedRules: + - SUBNET_AUTO_ASSIGN_PUBLIC_IP_DISABLED + + NetworkPublicSubnet1RouteTable: + Type: AWS::EC2::RouteTable + Properties: + VpcId: !Ref NetworkVPC + Tags: + - Key: Name + Value: gitlab-server-public-subnet-1-rt + + NetworkPublicSubnet1RouteTableAssociation: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + RouteTableId: !Ref NetworkPublicSubnet1RouteTable + SubnetId: !Ref NetworkPublicSubnet1 + + NetworkPublicSubnet1DefaultRoute: + Type: AWS::EC2::Route + Properties: + DestinationCidrBlock: 0.0.0.0/0 + GatewayId: !Ref NetworkInternetGateway + RouteTableId: !Ref NetworkPublicSubnet1RouteTable + Metadata: + guard: + SuppressedRules: + - NO_UNRESTRICTED_ROUTE_TO_IGW + DependsOn: + - NetworkVPCGW + + NetworkPublicSubnet1EIP: + Type: AWS::EC2::EIP + Properties: + Domain: vpc + Tags: + - Key: Name + Value: gitlab-server-public-subnet-1-eip + + NetworkPublicSubnet1NATGateway: + Type: AWS::EC2::NatGateway + Properties: + AllocationId: !GetAtt NetworkPublicSubnet1EIP.AllocationId + SubnetId: !Ref NetworkPublicSubnet1 + Tags: + - Key: Name + Value: gitlab-server-public-subnet-1-ngw + DependsOn: + - NetworkPublicSubnet1DefaultRoute + - NetworkPublicSubnet1RouteTableAssociation + + NetworkPublicSubnet2: + Type: AWS::EC2::Subnet + Properties: + AvailabilityZone: !Select + - 1 + - !GetAZs + Ref: AWS::Region + CidrBlock: 10.0.64.0/18 + MapPublicIpOnLaunch: true + VpcId: !Ref NetworkVPC + Tags: + - Key: Name + Value: gitlab-server-public-subnet-2 + Metadata: + guard: + SuppressedRules: + - SUBNET_AUTO_ASSIGN_PUBLIC_IP_DISABLED + + NetworkPublicSubnet2RouteTable: + Type: AWS::EC2::RouteTable + Properties: + VpcId: !Ref NetworkVPC + Tags: + - Key: Name + Value: gitlab-server-public-subnet-2-rt + + NetworkPublicSubnet2RouteTableAssociation: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + RouteTableId: !Ref NetworkPublicSubnet2RouteTable + SubnetId: !Ref NetworkPublicSubnet2 + + NetworkPublicSubnet2DefaultRoute: + Type: AWS::EC2::Route + Properties: + DestinationCidrBlock: 0.0.0.0/0 + GatewayId: !Ref NetworkInternetGateway + RouteTableId: !Ref NetworkPublicSubnet2RouteTable + Metadata: + guard: + SuppressedRules: + - NO_UNRESTRICTED_ROUTE_TO_IGW + DependsOn: + - NetworkVPCGW + + NetworkPublicSubnet2EIP: + Type: AWS::EC2::EIP + Properties: + Domain: vpc + Tags: + - Key: Name + Value: gitlab-server-public-subnet-eip + + NetworkPublicSubnet2NATGateway: + Type: AWS::EC2::NatGateway + Properties: + AllocationId: !GetAtt NetworkPublicSubnet2EIP.AllocationId + SubnetId: !Ref NetworkPublicSubnet2 + Tags: + - Key: Name + Value: gitlab-server-public-subnet-ngw + DependsOn: + - NetworkPublicSubnet2DefaultRoute + - NetworkPublicSubnet2RouteTableAssociation + + NetworkPrivateSubnet1Subnet: + Type: AWS::EC2::Subnet + Properties: + AvailabilityZone: !Select + - 0 + - !GetAZs + Ref: AWS::Region + CidrBlock: 10.0.128.0/18 + MapPublicIpOnLaunch: false + VpcId: !Ref NetworkVPC + Tags: + - Key: Name + Value: gitlab-server-private-subnet-1 + + NetworkPrivateSubnet1RouteTable: + Type: AWS::EC2::RouteTable + Properties: + VpcId: !Ref NetworkVPC + Tags: + - Key: Name + Value: gitlab-server-private-subnet-1-rt + + NetworkPrivateSubnet1RouteTableAssociation: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + RouteTableId: !Ref NetworkPrivateSubnet1RouteTable + SubnetId: !Ref NetworkPrivateSubnet1Subnet + + NetworkPrivateSubnet1DefaultRoute: + Type: AWS::EC2::Route + Properties: + DestinationCidrBlock: 0.0.0.0/0 + NatGatewayId: !Ref NetworkPublicSubnet1NATGateway + RouteTableId: !Ref NetworkPrivateSubnet1RouteTable + + NetworkPrivateSubnet2Subnet: + Type: AWS::EC2::Subnet + Properties: + AvailabilityZone: !Select + - 1 + - !GetAZs + Ref: AWS::Region + CidrBlock: 10.0.192.0/18 + MapPublicIpOnLaunch: false + VpcId: !Ref NetworkVPC + Tags: + - Key: Name + Value: gitlab-server-private-subnet-2 + + NetworkPrivateSubnet2RouteTable: + Type: AWS::EC2::RouteTable + Properties: + VpcId: !Ref NetworkVPC + Tags: + - Key: Name + Value: gitlab-server-private-subnet-2-rt + + NetworkPrivateSubnet2RouteTableAssociation: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + RouteTableId: !Ref NetworkPrivateSubnet2RouteTable + SubnetId: !Ref NetworkPrivateSubnet2Subnet + + NetworkPrivateSubnet2DefaultRoute: + Type: AWS::EC2::Route + Properties: + DestinationCidrBlock: 0.0.0.0/0 + NatGatewayId: !Ref NetworkPublicSubnet2NATGateway + RouteTableId: !Ref NetworkPrivateSubnet2RouteTable + + NetworkInternetGateway: + Type: AWS::EC2::InternetGateway + Properties: + Tags: + - Key: Name + Value: gitlab-server + + NetworkVPCGW: + Type: AWS::EC2::VPCGatewayAttachment + Properties: + InternetGatewayId: !Ref NetworkInternetGateway + VpcId: !Ref NetworkVPC + + CloudFrontCachePolicy: + Type: AWS::CloudFront::CachePolicy + Properties: + CachePolicyConfig: + DefaultTTL: 86400 + MaxTTL: 31536000 + MinTTL: 1 + Name: gitlab-server + ParametersInCacheKeyAndForwardedToOrigin: + CookiesConfig: + CookieBehavior: all + EnableAcceptEncodingGzip: False + HeadersConfig: + HeaderBehavior: whitelist + Headers: + - Accept-Charset + - Authorization + - Origin + - Accept + - Referer + - Host + - Accept-Language + - Accept-Encoding + - Accept-Datetime + QueryStringsConfig: + QueryStringBehavior: all + + CloudFrontDistribution: + Type: AWS::CloudFront::Distribution + Properties: + Tags: + - Key: Name + Value: gitlab-server + - Key: Description + Value: gitlab-server + DistributionConfig: + Enabled: True + HttpVersion: http2 + CacheBehaviors: + - AllowedMethods: + - GET + - HEAD + - OPTIONS + - PUT + - PATCH + - POST + - DELETE + CachePolicyId: 4135ea2d-6df8-44a3-9df3-4b5a84be39ad + Compress: False + OriginRequestPolicyId: 216adef6-5c7f-47e4-b989-5492eafa07d3 + TargetOriginId: !Sub CloudFront-${AWS::StackName} + ViewerProtocolPolicy: allow-all + PathPattern: /proxy/* + DefaultCacheBehavior: + AllowedMethods: + - GET + - HEAD + - OPTIONS + - PUT + - PATCH + - POST + - DELETE + CachePolicyId: !Ref CloudFrontCachePolicy + OriginRequestPolicyId: 216adef6-5c7f-47e4-b989-5492eafa07d3 + TargetOriginId: !Sub CloudFront-${AWS::StackName} + ViewerProtocolPolicy: allow-all + Origins: + - DomainName: !GetAtt Server.PublicDnsName + Id: !Sub CloudFront-${AWS::StackName} + CustomOriginConfig: + HTTPPort: 80 + OriginProtocolPolicy: http-only + DependsOn: + - Server + +Outputs: + URL: + Value: !Sub https://${CloudFrontDistribution.DomainName}/?folder=/home/ec2-user diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/GitLab/GitLabServer.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/GitLab/GitLabServer.json new file mode 100644 index 0000000000000000000000000000000000000000..e2f6ccaa3ffd047e3d70b0db36db97f5c6a27f3e --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/GitLab/GitLabServer.json @@ -0,0 +1,263 @@ +{ + "Parameters": { + "LatestAMI": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64" + }, + "InstanceType": { + "Type": "String", + "Default": "m5.large" + } + }, + "Mappings": { + "Prefixes": { + "ap-northeast-1": { + "PrefixList": "pl-58a04531" + }, + "ap-northeast-2": { + "PrefixList": "pl-22a6434b" + }, + "ap-south-1": { + "PrefixList": "pl-9aa247f3" + }, + "ap-southeast-1": { + "PrefixList": "pl-31a34658" + }, + "ap-southeast-2": { + "PrefixList": "pl-b8a742d1" + }, + "ca-central-1": { + "PrefixList": "pl-38a64351" + }, + "eu-central-1": { + "PrefixList": "pl-a3a144ca" + }, + "eu-north-1": { + "PrefixList": "pl-fab65393" + }, + "eu-west-1": { + "PrefixList": "pl-4fa04526" + }, + "eu-west-2": { + "PrefixList": "pl-93a247fa" + }, + "eu-west-3": { + "PrefixList": "pl-75b1541c" + }, + "sa-east-1": { + "PrefixList": "pl-5da64334" + }, + "us-east-1": { + "PrefixList": "pl-3b927c52" + }, + "us-east-2": { + "PrefixList": "pl-b6a144df" + }, + "us-west-1": { + "PrefixList": "pl-4ea04527" + }, + "us-west-2": { + "PrefixList": "pl-82a045eb" + } + } + }, + "Resources": { + "Network": { + "Type": { + "Rain::Module": "../../RainModules/vpc.yml" + }, + "Properties": { + "Name": "gitlab-server" + } + }, + "InstanceSecurityGroup": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "gitlab-server-isg", + "SecurityGroupIngress": [ + { + "Description": "Allow HTTP from com.amazonaws.global.cloudfront.origin-facing", + "IpProtocol": "tcp", + "FromPort": 80, + "ToPort": 80, + "SourcePrefixListId": { + "Fn::FindInMap": [ + "Prefixes", + { + "Ref": "AWS::Region" + }, + "PrefixList" + ] + } + } + ], + "SecurityGroupEgress": [ + { + "CidrIp": "0.0.0.0/0", + "Description": "Allow all outbound traffic by default", + "IpProtocol": "-1" + } + ], + "Tags": [ + { + "Key": "Name", + "Value": "gitlab-server-isg" + } + ], + "VpcId": { + "Ref": "NetworkVPC" + } + } + }, + "InstanceRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ec2.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "Tags": [ + { + "Key": "Name", + "Value": "gitlab-server-instance" + } + ] + } + }, + "InstanceRolePolicy": { + "Type": "AWS::IAM::RolePolicy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "ec2messages:*", + "ssm:UpdateInstanceInformation", + "ssmmessages:*", + "secretsmanager:GetSecretValue" + ], + "Effect": "Allow", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "InstanceRolePolicy", + "RoleName": { + "Ref": "InstanceRole" + } + } + }, + "InstanceProfile": { + "Type": "AWS::IAM::InstanceProfile", + "Properties": { + "Roles": [ + { + "Ref": "InstanceRole" + } + ] + } + }, + "Server": { + "CreationPolicy": { + "ResourceSignal": { + "Timeout": "PT30M" + } + }, + "Type": "AWS::EC2::Instance", + "DependsOn": [ + "InstanceRolePolicy", + "InstanceRole" + ], + "Properties": { + "AvailabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": null + } + ] + }, + "BlockDeviceMappings": [ + { + "DeviceName": "/dev/xvda", + "Ebs": { + "VolumeSize": 128 + } + } + ], + "IamInstanceProfile": { + "Ref": "InstanceProfile" + }, + "ImageId": { + "Ref": "LatestAMI" + }, + "InstanceType": { + "Ref": "InstanceType" + }, + "SecurityGroupIds": [ + { + "Fn::GetAtt": [ + "InstanceSecurityGroup", + "GroupId" + ] + } + ], + "SubnetId": { + "Fn::GetAtt": [ + "NetworkPublicSubnet1", + "SubnetId" + ] + }, + "Tags": [ + { + "Key": "Name", + "Value": "gitlab-server" + } + ], + "UserData": { + "Fn::Base64": { + "Fn::Sub": { + "Rain::Embed": "GitLabServer.sh" + } + } + } + } + }, + "CloudFront": { + "Type": { + "Rain::Module": "../../RainModules/cloudfront-nocache.yml" + }, + "Properties": { + "Name": "gitlab-server", + "DomainName": { + "Fn::GetAtt": [ + "Server", + "PublicDnsName" + ] + }, + "Port": 80 + }, + "Overrides": { + "Distribution": { + "DependsOn": "Server" + } + } + } + }, + "Outputs": { + "URL": { + "Value": { + "Fn::Sub": "https://${CloudFrontDistribution.DomainName}/?folder=/home/ec2-user" + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/GitLab/GitLabServer.sh b/human_reference_dataset/aws-cloudformation-templates/Solutions/GitLab/GitLabServer.sh new file mode 100644 index 0000000000000000000000000000000000000000..fb385b15f30ce7f59b645d553383ac59f2be4909 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/GitLab/GitLabServer.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +set -eou pipefail + +local_ip=$(ec2-metadata | grep "^local-ipv4: " | cut -d " " -f 2) + +# Install cfn-signal +yum install -y aws-cfn-bootstrap + +# Install postfix +yum install -y postfix +systemctl enable postfix +systemctl start postfix + +# Get the yum repo +curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash + +# Install gitlab and run it on the local ip +export EXTERNAL_URL="http://$local_ip" +yum install -y gitlab-ee + +# Tell CloudFormation we're ready to go +# This is a variable for the Sub intrisic function, not a bash variable +cfn-signal -s true --stack ${AWS::StackName} --resource Server --region ${AWS::Region} + + diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/GitLab/GitLabServer.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/GitLab/GitLabServer.yaml new file mode 100644 index 0000000000000000000000000000000000000000..261e26b6da5089c0e0ef6f74393fb401cdcb72a4 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/GitLab/GitLabServer.yaml @@ -0,0 +1,149 @@ +Parameters: + LatestAMI: + Type: AWS::SSM::Parameter::Value + Default: /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64 + + InstanceType: + Type: String + Default: m5.large + +Mappings: + Prefixes: + ap-northeast-1: + PrefixList: pl-58a04531 + ap-northeast-2: + PrefixList: pl-22a6434b + ap-south-1: + PrefixList: pl-9aa247f3 + ap-southeast-1: + PrefixList: pl-31a34658 + ap-southeast-2: + PrefixList: pl-b8a742d1 + ca-central-1: + PrefixList: pl-38a64351 + eu-central-1: + PrefixList: pl-a3a144ca + eu-north-1: + PrefixList: pl-fab65393 + eu-west-1: + PrefixList: pl-4fa04526 + eu-west-2: + PrefixList: pl-93a247fa + eu-west-3: + PrefixList: pl-75b1541c + sa-east-1: + PrefixList: pl-5da64334 + us-east-1: + PrefixList: pl-3b927c52 + us-east-2: + PrefixList: pl-b6a144df + us-west-1: + PrefixList: pl-4ea04527 + us-west-2: + PrefixList: pl-82a045eb + +Resources: + Network: + Type: !Rain::Module ../../RainModules/vpc.yml + Properties: + Name: gitlab-server + + InstanceSecurityGroup: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: gitlab-server-isg + SecurityGroupIngress: + - Description: Allow HTTP from com.amazonaws.global.cloudfront.origin-facing + IpProtocol: tcp + FromPort: 80 + ToPort: 80 + SourcePrefixListId: !FindInMap + - Prefixes + - !Ref AWS::Region + - PrefixList + SecurityGroupEgress: + - CidrIp: 0.0.0.0/0 + Description: Allow all outbound traffic by default + IpProtocol: "-1" + Tags: + - Key: Name + Value: gitlab-server-isg + VpcId: !Ref NetworkVPC + + InstanceRole: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Statement: + - Action: sts:AssumeRole + Effect: Allow + Principal: + Service: ec2.amazonaws.com + Version: "2012-10-17" + Tags: + - Key: Name + Value: gitlab-server-instance + + InstanceRolePolicy: + Type: AWS::IAM::RolePolicy + Properties: + PolicyDocument: + Statement: + - Action: + - ec2messages:* + - ssm:UpdateInstanceInformation + - ssmmessages:* + - secretsmanager:GetSecretValue + Effect: Allow + Resource: '*' + Version: "2012-10-17" + PolicyName: InstanceRolePolicy + RoleName: !Ref InstanceRole + + InstanceProfile: + Type: AWS::IAM::InstanceProfile + Properties: + Roles: + - !Ref InstanceRole + + Server: + Type: AWS::EC2::Instance + DependsOn: + - InstanceRolePolicy + - InstanceRole + CreationPolicy: + ResourceSignal: + Timeout: PT30M + Properties: + AvailabilityZone: !Select + - 0 + - !GetAZs + BlockDeviceMappings: + - DeviceName: /dev/xvda + Ebs: + VolumeSize: 128 + IamInstanceProfile: !Ref InstanceProfile + ImageId: !Ref LatestAMI + InstanceType: !Ref InstanceType + SecurityGroupIds: + - !GetAtt InstanceSecurityGroup.GroupId + SubnetId: !GetAtt NetworkPublicSubnet1.SubnetId + Tags: + - Key: Name + Value: gitlab-server + UserData: !Base64 + Fn::Sub: !Rain::Embed GitLabServer.sh + + CloudFront: + Type: !Rain::Module ../../RainModules/cloudfront-nocache.yml + Properties: + Name: gitlab-server + DomainName: !GetAtt Server.PublicDnsName + Port: 80 + Overrides: + Distribution: + DependsOn: Server + +Outputs: + URL: + Value: !Sub https://${CloudFrontDistribution.DomainName}/?folder=/home/ec2-user diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/GitLab/README.md b/human_reference_dataset/aws-cloudformation-templates/Solutions/GitLab/README.md new file mode 100644 index 0000000000000000000000000000000000000000..d1a1a99e48024df12c482448ef7465ec120f745c --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/GitLab/README.md @@ -0,0 +1,7 @@ +# A CloudFormation template to install GitLab on an EC2 instance + +This template creates a VPC and an EC2 instance with a self-hosted instance of GitLab. + + + + diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/GitLabAndVSCode/GitLabAndVSCode.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/GitLabAndVSCode/GitLabAndVSCode.json new file mode 100644 index 0000000000000000000000000000000000000000..3774e2785aec23cf7f078fbbd4f5b6d2c45c0ef9 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/GitLabAndVSCode/GitLabAndVSCode.json @@ -0,0 +1,357 @@ +{ + "Parameters": { + "LatestAMI": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64" + }, + "InstanceType": { + "Type": "String", + "Default": "m5.large" + }, + "SecretName": { + "Description": "The name of the secrets manager secret that stores the password to be used for the VSCode Server. The password must be a simple plaintext string with no JSON.", + "Type": "String", + "Default": "vscode-password" + } + }, + "Mappings": { + "Prefixes": { + "ap-northeast-1": { + "PrefixList": "pl-58a04531" + }, + "ap-northeast-2": { + "PrefixList": "pl-22a6434b" + }, + "ap-south-1": { + "PrefixList": "pl-9aa247f3" + }, + "ap-southeast-1": { + "PrefixList": "pl-31a34658" + }, + "ap-southeast-2": { + "PrefixList": "pl-b8a742d1" + }, + "ca-central-1": { + "PrefixList": "pl-38a64351" + }, + "eu-central-1": { + "PrefixList": "pl-a3a144ca" + }, + "eu-north-1": { + "PrefixList": "pl-fab65393" + }, + "eu-west-1": { + "PrefixList": "pl-4fa04526" + }, + "eu-west-2": { + "PrefixList": "pl-93a247fa" + }, + "eu-west-3": { + "PrefixList": "pl-75b1541c" + }, + "sa-east-1": { + "PrefixList": "pl-5da64334" + }, + "us-east-1": { + "PrefixList": "pl-3b927c52" + }, + "us-east-2": { + "PrefixList": "pl-b6a144df" + }, + "us-west-1": { + "PrefixList": "pl-4ea04527" + }, + "us-west-2": { + "PrefixList": "pl-82a045eb" + } + } + }, + "Resources": { + "Network": { + "Type": { + "Rain::Module": "../../RainModules/vpc.yml" + }, + "Properties": { + "Name": "gitlab-server" + } + }, + "InstanceSecurityGroup": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "gitlab-server-isg", + "SecurityGroupIngress": [ + { + "Description": "Allow HTTP from com.amazonaws.global.cloudfront.origin-facing", + "IpProtocol": "tcp", + "FromPort": 80, + "ToPort": 80, + "SourcePrefixListId": { + "Fn::FindInMap": [ + "Prefixes", + { + "Ref": "AWS::Region" + }, + "PrefixList" + ] + } + } + ], + "SecurityGroupEgress": [ + { + "CidrIp": "0.0.0.0/0", + "Description": "Allow all outbound traffic by default", + "IpProtocol": "-1" + } + ], + "Tags": [ + { + "Key": "Name", + "Value": "gitlab-server-isg" + } + ], + "VpcId": { + "Ref": "NetworkVPC" + } + } + }, + "InstanceRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ec2.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "Tags": [ + { + "Key": "Name", + "Value": "gitlab-server-instance" + } + ] + } + }, + "InstanceRolePolicy": { + "Type": "AWS::IAM::RolePolicy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "ec2messages:*", + "ssm:UpdateInstanceInformation", + "ssmmessages:*", + "secretsmanager:GetSecretValue" + ], + "Effect": "Allow", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "InstanceRolePolicy", + "RoleName": { + "Ref": "InstanceRole" + } + } + }, + "InstanceProfile": { + "Type": "AWS::IAM::InstanceProfile", + "Properties": { + "Roles": [ + { + "Ref": "InstanceRole" + } + ] + } + }, + "GitLabServer": { + "CreationPolicy": { + "ResourceSignal": { + "Timeout": "PT30M" + } + }, + "Type": "AWS::EC2::Instance", + "DependsOn": [ + "InstanceRolePolicy", + "InstanceRole" + ], + "Properties": { + "AvailabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": null + } + ] + }, + "BlockDeviceMappings": [ + { + "DeviceName": "/dev/xvda", + "Ebs": { + "VolumeSize": 128 + } + } + ], + "IamInstanceProfile": { + "Ref": "InstanceProfile" + }, + "ImageId": { + "Ref": "LatestAMI" + }, + "InstanceType": { + "Ref": "InstanceType" + }, + "SecurityGroupIds": [ + { + "Fn::GetAtt": [ + "InstanceSecurityGroup", + "GroupId" + ] + } + ], + "SubnetId": { + "Fn::GetAtt": [ + "NetworkPublicSubnet1", + "SubnetId" + ] + }, + "Tags": [ + { + "Key": "Name", + "Value": "gitlab-server" + } + ], + "UserData": { + "Fn::Base64": { + "Fn::Sub": { + "Rain::Embed": "GitLabServer.sh" + } + } + } + } + }, + "VSCodeServer": { + "CreationPolicy": { + "ResourceSignal": { + "Timeout": "PT5M" + } + }, + "Type": "AWS::EC2::Instance", + "DependsOn": [ + "InstanceRolePolicy", + "InstanceRole" + ], + "Properties": { + "AvailabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": null + } + ] + }, + "BlockDeviceMappings": [ + { + "DeviceName": "/dev/xvda", + "Ebs": { + "VolumeSize": 128 + } + } + ], + "IamInstanceProfile": { + "Ref": "InstanceProfile" + }, + "ImageId": { + "Ref": "LatestAMI" + }, + "InstanceType": { + "Ref": "InstanceType" + }, + "SecurityGroupIds": [ + { + "Fn::GetAtt": [ + "InstanceSecurityGroup", + "GroupId" + ] + } + ], + "SubnetId": { + "Fn::GetAtt": [ + "NetworkPublicSubnet1", + "SubnetId" + ] + }, + "Tags": [ + { + "Key": "Name", + "Value": "vscode-server" + } + ], + "UserData": { + "Fn::Base64": { + "Fn::Sub": { + "Rain::Embed": "VSCodeServer.sh" + } + } + } + } + }, + "GitLabCloudFront": { + "Type": { + "Rain::Module": "../../RainModules/cloudfront-nocache.yml" + }, + "Properties": { + "Name": "gitlab-server", + "DomainName": { + "Fn::GetAtt": [ + "GitLabServer", + "PublicDnsName" + ] + }, + "Port": 80 + }, + "Overrides": { + "Distribution": { + "DependsOn": "GitLabServer" + } + } + }, + "VSCodeCloudFront": { + "Type": { + "Rain::Module": "../../RainModules/cloudfront-nocache.yml" + }, + "Properties": { + "Name": "vscode-server", + "DomainName": { + "Fn::GetAtt": [ + "VSCodeServer", + "PublicDnsName" + ] + }, + "Port": 8080 + }, + "Overrides": { + "Distribution": "DependsOn:VSCodeServer" + } + } + }, + "Outputs": { + "VSCodeURL": { + "Value": { + "Fn::Sub": "https://${VSCodeCloudFrontDistribution.DomainName}/?folder=/home/ec2-user" + } + }, + "GitLabURL": { + "Value": { + "Fn::Sub": "https://${GitLabCloudFrontDistribution.DomainName}/?folder=/home/ec2-user" + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/GitLabAndVSCode/GitLabAndVSCode.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/GitLabAndVSCode/GitLabAndVSCode.yaml new file mode 100644 index 0000000000000000000000000000000000000000..c1a86612df0f59b996b4c85c933881064091f8d7 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/GitLabAndVSCode/GitLabAndVSCode.yaml @@ -0,0 +1,194 @@ +Parameters: + LatestAMI: + Type: AWS::SSM::Parameter::Value + Default: /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64 + + InstanceType: + Type: String + Default: m5.large + + SecretName: + Type: String + Default: vscode-password + Description: The name of the secrets manager secret that stores the password to be used for the VSCode Server. The password must be a simple plaintext string with no JSON. + +Mappings: + Prefixes: + ap-northeast-1: + PrefixList: pl-58a04531 + ap-northeast-2: + PrefixList: pl-22a6434b + ap-south-1: + PrefixList: pl-9aa247f3 + ap-southeast-1: + PrefixList: pl-31a34658 + ap-southeast-2: + PrefixList: pl-b8a742d1 + ca-central-1: + PrefixList: pl-38a64351 + eu-central-1: + PrefixList: pl-a3a144ca + eu-north-1: + PrefixList: pl-fab65393 + eu-west-1: + PrefixList: pl-4fa04526 + eu-west-2: + PrefixList: pl-93a247fa + eu-west-3: + PrefixList: pl-75b1541c + sa-east-1: + PrefixList: pl-5da64334 + us-east-1: + PrefixList: pl-3b927c52 + us-east-2: + PrefixList: pl-b6a144df + us-west-1: + PrefixList: pl-4ea04527 + us-west-2: + PrefixList: pl-82a045eb + +Resources: + Network: + Type: !Rain::Module ../../RainModules/vpc.yml + Properties: + Name: gitlab-server + + InstanceSecurityGroup: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: gitlab-server-isg + SecurityGroupIngress: + - Description: Allow HTTP from com.amazonaws.global.cloudfront.origin-facing + IpProtocol: tcp + FromPort: 80 + ToPort: 80 + SourcePrefixListId: !FindInMap + - Prefixes + - !Ref AWS::Region + - PrefixList + SecurityGroupEgress: + - CidrIp: 0.0.0.0/0 + Description: Allow all outbound traffic by default + IpProtocol: "-1" + Tags: + - Key: Name + Value: gitlab-server-isg + VpcId: !Ref NetworkVPC + + InstanceRole: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Statement: + - Action: sts:AssumeRole + Effect: Allow + Principal: + Service: ec2.amazonaws.com + Version: "2012-10-17" + Tags: + - Key: Name + Value: gitlab-server-instance + + InstanceRolePolicy: + Type: AWS::IAM::RolePolicy + Properties: + PolicyDocument: + Statement: + - Action: + - ec2messages:* + - ssm:UpdateInstanceInformation + - ssmmessages:* + - secretsmanager:GetSecretValue + Effect: Allow + Resource: '*' + Version: "2012-10-17" + PolicyName: InstanceRolePolicy + RoleName: !Ref InstanceRole + + InstanceProfile: + Type: AWS::IAM::InstanceProfile + Properties: + Roles: + - !Ref InstanceRole + + GitLabServer: + Type: AWS::EC2::Instance + DependsOn: + - InstanceRolePolicy + - InstanceRole + CreationPolicy: + ResourceSignal: + Timeout: PT30M + Properties: + AvailabilityZone: !Select + - 0 + - !GetAZs + BlockDeviceMappings: + - DeviceName: /dev/xvda + Ebs: + VolumeSize: 128 + IamInstanceProfile: !Ref InstanceProfile + ImageId: !Ref LatestAMI + InstanceType: !Ref InstanceType + SecurityGroupIds: + - !GetAtt InstanceSecurityGroup.GroupId + SubnetId: !GetAtt NetworkPublicSubnet1.SubnetId + Tags: + - Key: Name + Value: gitlab-server + UserData: !Base64 + Fn::Sub: !Rain::Embed GitLabServer.sh + + VSCodeServer: + Type: AWS::EC2::Instance + DependsOn: + - InstanceRolePolicy + - InstanceRole + CreationPolicy: + ResourceSignal: + Timeout: PT5M + Properties: + AvailabilityZone: !Select + - 0 + - !GetAZs + BlockDeviceMappings: + - DeviceName: /dev/xvda + Ebs: + VolumeSize: 128 + IamInstanceProfile: !Ref InstanceProfile + ImageId: !Ref LatestAMI + InstanceType: !Ref InstanceType + SecurityGroupIds: + - !GetAtt InstanceSecurityGroup.GroupId + SubnetId: !GetAtt NetworkPublicSubnet1.SubnetId + Tags: + - Key: Name + Value: vscode-server + UserData: !Base64 + Fn::Sub: !Rain::Embed VSCodeServer.sh + + GitLabCloudFront: + Type: !Rain::Module ../../RainModules/cloudfront-nocache.yml + Properties: + Name: gitlab-server + DomainName: !GetAtt GitLabServer.PublicDnsName + Port: 80 + Overrides: + Distribution: + DependsOn: GitLabServer + + VSCodeCloudFront: + Type: !Rain::Module ../../RainModules/cloudfront-nocache.yml + Properties: + Name: vscode-server + DomainName: !GetAtt VSCodeServer.PublicDnsName + Port: 8080 + Overrides: + Distribution: DependsOn:VSCodeServer + +Outputs: + VSCodeURL: + Value: !Sub https://${VSCodeCloudFrontDistribution.DomainName}/?folder=/home/ec2-user + + GitLabURL: + Value: !Sub https://${GitLabCloudFrontDistribution.DomainName}/?folder=/home/ec2-user diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/GitLabAndVSCode/GitLabServer.sh b/human_reference_dataset/aws-cloudformation-templates/Solutions/GitLabAndVSCode/GitLabServer.sh new file mode 100644 index 0000000000000000000000000000000000000000..fb385b15f30ce7f59b645d553383ac59f2be4909 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/GitLabAndVSCode/GitLabServer.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +set -eou pipefail + +local_ip=$(ec2-metadata | grep "^local-ipv4: " | cut -d " " -f 2) + +# Install cfn-signal +yum install -y aws-cfn-bootstrap + +# Install postfix +yum install -y postfix +systemctl enable postfix +systemctl start postfix + +# Get the yum repo +curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash + +# Install gitlab and run it on the local ip +export EXTERNAL_URL="http://$local_ip" +yum install -y gitlab-ee + +# Tell CloudFormation we're ready to go +# This is a variable for the Sub intrisic function, not a bash variable +cfn-signal -s true --stack ${AWS::StackName} --resource Server --region ${AWS::Region} + + diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/GitLabAndVSCode/VSCodeServer.sh b/human_reference_dataset/aws-cloudformation-templates/Solutions/GitLabAndVSCode/VSCodeServer.sh new file mode 100644 index 0000000000000000000000000000000000000000..1bc9824616696c0a5ef446fe4e210c80b37af8a7 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/GitLabAndVSCode/VSCodeServer.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +set -eou pipefail + +local_ip=$(ec2-metadata | grep "^local-ipv4: " | cut -d " " -f 2) + +# Install the latest code-server from coder.com (not from yum) +export HOME=/root +curl -fsSL https://code-server.dev/install.sh | bash + +# Install cfn-signal +yum install -y aws-cfn-bootstrap + +#Install argon2 for hashing the vscode server password +yum install -y argon2 + +# Configure the service +tee /etc/systemd/system/code-server.service <", + "Default": "/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64" + }, + "InstanceType": { + "Type": "String", + "Default": "m7i.xlarge" + }, + "SecretName": { + "Description": "The name of the secrets manager secret to be used as the password for the Gitea admin1 user. The password must be a plaintext string, not JSON.", + "Type": "String", + "Default": "gitea-password" + } + }, + "Mappings": { + "Prefixes": { + "ap-northeast-1": { + "PrefixList": "pl-58a04531" + }, + "ap-northeast-2": { + "PrefixList": "pl-22a6434b" + }, + "ap-south-1": { + "PrefixList": "pl-9aa247f3" + }, + "ap-southeast-1": { + "PrefixList": "pl-31a34658" + }, + "ap-southeast-2": { + "PrefixList": "pl-b8a742d1" + }, + "ca-central-1": { + "PrefixList": "pl-38a64351" + }, + "eu-central-1": { + "PrefixList": "pl-a3a144ca" + }, + "eu-north-1": { + "PrefixList": "pl-fab65393" + }, + "eu-west-1": { + "PrefixList": "pl-4fa04526" + }, + "eu-west-2": { + "PrefixList": "pl-93a247fa" + }, + "eu-west-3": { + "PrefixList": "pl-75b1541c" + }, + "sa-east-1": { + "PrefixList": "pl-5da64334" + }, + "us-east-1": { + "PrefixList": "pl-3b927c52" + }, + "us-east-2": { + "PrefixList": "pl-b6a144df" + }, + "us-west-1": { + "PrefixList": "pl-4ea04527" + }, + "us-west-2": { + "PrefixList": "pl-82a045eb" + } + } + }, + "Resources": { + "InstanceSecurityGroup": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "gitea-server-isg", + "SecurityGroupIngress": [ + { + "Description": "Allow HTTP from com.amazonaws.global.cloudfront.origin-facing", + "IpProtocol": "tcp", + "FromPort": 8080, + "ToPort": 8080, + "SourcePrefixListId": { + "Fn::FindInMap": [ + "Prefixes", + { + "Ref": "AWS::Region" + }, + "PrefixList" + ] + } + } + ], + "SecurityGroupEgress": [ + { + "CidrIp": "0.0.0.0/0", + "Description": "Allow all outbound traffic by default", + "IpProtocol": "-1" + } + ], + "Tags": [ + { + "Key": "Name", + "Value": "gitea-server-isg" + } + ], + "VpcId": { + "Ref": "NetworkVPC" + } + } + }, + "InstanceRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ec2.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "Tags": [ + { + "Key": "Name", + "Value": "gitea-server-instance" + } + ] + } + }, + "InstanceRolePolicy": { + "Type": "AWS::IAM::RolePolicy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "ec2messages:*", + "ssm:UpdateInstanceInformation", + "ssmmessages:*", + "secretsmanager:GetSecretValue" + ], + "Effect": "Allow", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "InstanceRolePolicy", + "RoleName": { + "Ref": "InstanceRole" + } + } + }, + "InstanceProfile": { + "Type": "AWS::IAM::InstanceProfile", + "Properties": { + "Roles": [ + { + "Ref": "InstanceRole" + } + ] + } + }, + "Server": { + "CreationPolicy": { + "ResourceSignal": { + "Timeout": "PT20M" + } + }, + "Type": "AWS::EC2::Instance", + "DependsOn": [ + "InstanceRolePolicy", + "InstanceRole" + ], + "Properties": { + "AvailabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": null + } + ] + }, + "BlockDeviceMappings": [ + { + "DeviceName": "/dev/xvda", + "Ebs": { + "VolumeSize": 128 + } + } + ], + "IamInstanceProfile": { + "Ref": "InstanceProfile" + }, + "ImageId": { + "Ref": "LatestAMI" + }, + "InstanceType": { + "Ref": "InstanceType" + }, + "SecurityGroupIds": [ + { + "Fn::GetAtt": [ + "InstanceSecurityGroup", + "GroupId" + ] + } + ], + "SubnetId": { + "Fn::GetAtt": [ + "NetworkPublicSubnet1", + "SubnetId" + ] + }, + "Tags": [ + { + "Key": "Name", + "Value": "gitea-server" + } + ], + "UserData": { + "Fn::Base64": { + "Fn::Sub": "#!/bin/bash\n\nset -eou pipefail\n\nlocal_ip=$(ec2-metadata | grep \"^local-ipv4: \" | cut -d \" \" -f 2)\n\n# Get the password from secrets manager\nsecret_string=$(aws secretsmanager get-secret-value --secret-id ${SecretName} | jq -r \".SecretString\")\n\n# Install cfn-signal\nyum install -y aws-cfn-bootstrap\n\n# Install go\nyum install -y go\n\n# Install nodejs\nyum install -y nodejs\n\n# Clone the repo and build Gitea\nsudo -u ec2-user -i < + Default: /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64 + + InstanceType: + Type: String + Default: m7i.xlarge + + SecretName: + Type: String + Default: gitea-password + Description: The name of the secrets manager secret to be used as the password for the Gitea admin1 user. The password must be a plaintext string, not JSON. + +Mappings: + Prefixes: + ap-northeast-1: + PrefixList: pl-58a04531 + ap-northeast-2: + PrefixList: pl-22a6434b + ap-south-1: + PrefixList: pl-9aa247f3 + ap-southeast-1: + PrefixList: pl-31a34658 + ap-southeast-2: + PrefixList: pl-b8a742d1 + ca-central-1: + PrefixList: pl-38a64351 + eu-central-1: + PrefixList: pl-a3a144ca + eu-north-1: + PrefixList: pl-fab65393 + eu-west-1: + PrefixList: pl-4fa04526 + eu-west-2: + PrefixList: pl-93a247fa + eu-west-3: + PrefixList: pl-75b1541c + sa-east-1: + PrefixList: pl-5da64334 + us-east-1: + PrefixList: pl-3b927c52 + us-east-2: + PrefixList: pl-b6a144df + us-west-1: + PrefixList: pl-4ea04527 + us-west-2: + PrefixList: pl-82a045eb + +Resources: + InstanceSecurityGroup: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: gitea-server-isg + SecurityGroupIngress: + - Description: Allow HTTP from com.amazonaws.global.cloudfront.origin-facing + IpProtocol: tcp + FromPort: 8080 + ToPort: 8080 + SourcePrefixListId: !FindInMap + - Prefixes + - !Ref AWS::Region + - PrefixList + SecurityGroupEgress: + - CidrIp: 0.0.0.0/0 + Description: Allow all outbound traffic by default + IpProtocol: "-1" + Tags: + - Key: Name + Value: gitea-server-isg + VpcId: !Ref NetworkVPC + + InstanceRole: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Statement: + - Action: sts:AssumeRole + Effect: Allow + Principal: + Service: ec2.amazonaws.com + Version: "2012-10-17" + Tags: + - Key: Name + Value: gitea-server-instance + + InstanceRolePolicy: + Type: AWS::IAM::RolePolicy + Properties: + PolicyDocument: + Statement: + - Action: + - ec2messages:* + - ssm:UpdateInstanceInformation + - ssmmessages:* + - secretsmanager:GetSecretValue + Effect: Allow + Resource: '*' + Version: "2012-10-17" + PolicyName: InstanceRolePolicy + RoleName: !Ref InstanceRole + + InstanceProfile: + Type: AWS::IAM::InstanceProfile + Properties: + Roles: + - !Ref InstanceRole + + Server: + Type: AWS::EC2::Instance + DependsOn: + - InstanceRolePolicy + - InstanceRole + CreationPolicy: + ResourceSignal: + Timeout: PT20M + Properties: + AvailabilityZone: !Select + - 0 + - !GetAZs + BlockDeviceMappings: + - DeviceName: /dev/xvda + Ebs: + VolumeSize: 128 + IamInstanceProfile: !Ref InstanceProfile + ImageId: !Ref LatestAMI + InstanceType: !Ref InstanceType + SecurityGroupIds: + - !GetAtt InstanceSecurityGroup.GroupId + SubnetId: !GetAtt NetworkPublicSubnet1.SubnetId + Tags: + - Key: Name + Value: gitea-server + UserData: !Base64 + Fn::Sub: "#!/bin/bash\n\nset -eou pipefail\n\nlocal_ip=$(ec2-metadata | grep \"^local-ipv4: \" | cut -d \" \" -f 2)\n\n# Get the password from secrets manager\nsecret_string=$(aws secretsmanager get-secret-value --secret-id ${SecretName} | jq -r \".SecretString\")\n\n# Install cfn-signal\nyum install -y aws-cfn-bootstrap\n\n# Install go\nyum install -y go\n\n# Install nodejs\nyum install -y nodejs\n\n# Clone the repo and build Gitea\nsudo -u ec2-user -i <", + "Default": "/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64" + }, + "InstanceType": { + "Type": "String", + "Default": "m7i.xlarge" + }, + "SecretName": { + "Description": "The name of the secrets manager secret to be used as the password for the Gitea admin1 user. The password must be a plaintext string, not JSON.", + "Type": "String", + "Default": "gitea-password" + } + }, + "Mappings": { + "Prefixes": { + "ap-northeast-1": { + "PrefixList": "pl-58a04531" + }, + "ap-northeast-2": { + "PrefixList": "pl-22a6434b" + }, + "ap-south-1": { + "PrefixList": "pl-9aa247f3" + }, + "ap-southeast-1": { + "PrefixList": "pl-31a34658" + }, + "ap-southeast-2": { + "PrefixList": "pl-b8a742d1" + }, + "ca-central-1": { + "PrefixList": "pl-38a64351" + }, + "eu-central-1": { + "PrefixList": "pl-a3a144ca" + }, + "eu-north-1": { + "PrefixList": "pl-fab65393" + }, + "eu-west-1": { + "PrefixList": "pl-4fa04526" + }, + "eu-west-2": { + "PrefixList": "pl-93a247fa" + }, + "eu-west-3": { + "PrefixList": "pl-75b1541c" + }, + "sa-east-1": { + "PrefixList": "pl-5da64334" + }, + "us-east-1": { + "PrefixList": "pl-3b927c52" + }, + "us-east-2": { + "PrefixList": "pl-b6a144df" + }, + "us-west-1": { + "PrefixList": "pl-4ea04527" + }, + "us-west-2": { + "PrefixList": "pl-82a045eb" + } + } + }, + "Resources": { + "Network": { + "Type": { + "Rain::Module": "../../RainModules/vpc.yml" + }, + "Properties": { + "Name": "gitea-server" + } + }, + "InstanceSecurityGroup": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "gitea-server-isg", + "SecurityGroupIngress": [ + { + "Description": "Allow HTTP from com.amazonaws.global.cloudfront.origin-facing", + "IpProtocol": "tcp", + "FromPort": 8080, + "ToPort": 8080, + "SourcePrefixListId": { + "Fn::FindInMap": [ + "Prefixes", + { + "Ref": "AWS::Region" + }, + "PrefixList" + ] + } + } + ], + "SecurityGroupEgress": [ + { + "CidrIp": "0.0.0.0/0", + "Description": "Allow all outbound traffic by default", + "IpProtocol": "-1" + } + ], + "Tags": [ + { + "Key": "Name", + "Value": "gitea-server-isg" + } + ], + "VpcId": { + "Ref": "NetworkVPC" + } + } + }, + "InstanceRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ec2.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "Tags": [ + { + "Key": "Name", + "Value": "gitea-server-instance" + } + ] + } + }, + "InstanceRolePolicy": { + "Type": "AWS::IAM::RolePolicy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "ec2messages:*", + "ssm:UpdateInstanceInformation", + "ssmmessages:*", + "secretsmanager:GetSecretValue", + "kms:Decrypt" + ], + "Effect": "Allow", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "InstanceRolePolicy", + "RoleName": { + "Ref": "InstanceRole" + } + } + }, + "InstanceProfile": { + "Type": "AWS::IAM::InstanceProfile", + "Properties": { + "Roles": [ + { + "Ref": "InstanceRole" + } + ] + } + }, + "Server": { + "CreationPolicy": { + "ResourceSignal": { + "Timeout": "PT20M" + } + }, + "Type": "AWS::EC2::Instance", + "DependsOn": [ + "InstanceRolePolicy", + "InstanceRole" + ], + "Properties": { + "AvailabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": null + } + ] + }, + "BlockDeviceMappings": [ + { + "DeviceName": "/dev/xvda", + "Ebs": { + "VolumeSize": 128 + } + } + ], + "IamInstanceProfile": { + "Ref": "InstanceProfile" + }, + "ImageId": { + "Ref": "LatestAMI" + }, + "InstanceType": { + "Ref": "InstanceType" + }, + "SecurityGroupIds": [ + { + "Fn::GetAtt": [ + "InstanceSecurityGroup", + "GroupId" + ] + } + ], + "SubnetId": { + "Fn::GetAtt": [ + "NetworkPublicSubnet1", + "SubnetId" + ] + }, + "Tags": [ + { + "Key": "Name", + "Value": "gitea-server" + } + ], + "UserData": { + "Fn::Base64": { + "Fn::Sub": { + "Rain::Embed": "Gitea.sh" + } + } + } + } + }, + "CloudFront": { + "Type": { + "Rain::Module": "../../RainModules/cloudfront-nocache.yml" + }, + "Properties": { + "Name": "gitea-server", + "DomainName": { + "Fn::GetAtt": [ + "Server", + "PublicDnsName" + ] + }, + "Port": 8080 + }, + "Overrides": { + "Distribution": { + "DependsOn": "Server" + } + } + } + }, + "Outputs": { + "URL": { + "Value": { + "Fn::Sub": "https://${CloudFrontDistribution.DomainName}" + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/Gitea/Gitea.sh b/human_reference_dataset/aws-cloudformation-templates/Solutions/Gitea/Gitea.sh new file mode 100644 index 0000000000000000000000000000000000000000..33b2ce6eb7f48defc8d4742cb3b0ce545a40ed80 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/Gitea/Gitea.sh @@ -0,0 +1,94 @@ +#!/bin/bash + +set -eou pipefail + +local_ip=$(ec2-metadata | grep "^local-ipv4: " | cut -d " " -f 2) + +# Get the password from secrets manager +secret_string=$(aws secretsmanager get-secret-value --secret-id ${SecretName} | jq -r ".SecretString") + +# Install cfn-signal +yum install -y aws-cfn-bootstrap + +# Install go +yum install -y go + +# Install nodejs +yum install -y nodejs + +# Clone the repo and build Gitea +sudo -u ec2-user -i < + Default: /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64 + + InstanceType: + Type: String + Default: m7i.xlarge + + SecretName: + Type: String + Default: gitea-password + Description: The name of the secrets manager secret to be used as the password for the Gitea admin1 user. The password must be a plaintext string, not JSON. + +Mappings: + Prefixes: + ap-northeast-1: + PrefixList: pl-58a04531 + ap-northeast-2: + PrefixList: pl-22a6434b + ap-south-1: + PrefixList: pl-9aa247f3 + ap-southeast-1: + PrefixList: pl-31a34658 + ap-southeast-2: + PrefixList: pl-b8a742d1 + ca-central-1: + PrefixList: pl-38a64351 + eu-central-1: + PrefixList: pl-a3a144ca + eu-north-1: + PrefixList: pl-fab65393 + eu-west-1: + PrefixList: pl-4fa04526 + eu-west-2: + PrefixList: pl-93a247fa + eu-west-3: + PrefixList: pl-75b1541c + sa-east-1: + PrefixList: pl-5da64334 + us-east-1: + PrefixList: pl-3b927c52 + us-east-2: + PrefixList: pl-b6a144df + us-west-1: + PrefixList: pl-4ea04527 + us-west-2: + PrefixList: pl-82a045eb + +Resources: + Network: + Type: !Rain::Module ../../RainModules/vpc.yml + Properties: + Name: gitea-server + + InstanceSecurityGroup: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: gitea-server-isg + SecurityGroupIngress: + - Description: Allow HTTP from com.amazonaws.global.cloudfront.origin-facing + IpProtocol: tcp + FromPort: 8080 + ToPort: 8080 + SourcePrefixListId: !FindInMap + - Prefixes + - !Ref AWS::Region + - PrefixList + SecurityGroupEgress: + - CidrIp: 0.0.0.0/0 + Description: Allow all outbound traffic by default + IpProtocol: "-1" + Tags: + - Key: Name + Value: gitea-server-isg + VpcId: !Ref NetworkVPC + + InstanceRole: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Statement: + - Action: sts:AssumeRole + Effect: Allow + Principal: + Service: ec2.amazonaws.com + Version: "2012-10-17" + Tags: + - Key: Name + Value: gitea-server-instance + + InstanceRolePolicy: + Type: AWS::IAM::RolePolicy + Properties: + PolicyDocument: + Statement: + - Action: + - ec2messages:* + - ssm:UpdateInstanceInformation + - ssmmessages:* + - secretsmanager:GetSecretValue + - kms:Decrypt + Effect: Allow + Resource: '*' + Version: "2012-10-17" + PolicyName: InstanceRolePolicy + RoleName: !Ref InstanceRole + + InstanceProfile: + Type: AWS::IAM::InstanceProfile + Properties: + Roles: + - !Ref InstanceRole + + Server: + Type: AWS::EC2::Instance + DependsOn: + - InstanceRolePolicy + - InstanceRole + CreationPolicy: + ResourceSignal: + Timeout: PT20M + Properties: + AvailabilityZone: !Select + - 0 + - !GetAZs + BlockDeviceMappings: + - DeviceName: /dev/xvda + Ebs: + VolumeSize: 128 + IamInstanceProfile: !Ref InstanceProfile + ImageId: !Ref LatestAMI + InstanceType: !Ref InstanceType + SecurityGroupIds: + - !GetAtt InstanceSecurityGroup.GroupId + SubnetId: !GetAtt NetworkPublicSubnet1.SubnetId + Tags: + - Key: Name + Value: gitea-server + UserData: !Base64 + Fn::Sub: !Rain::Embed Gitea.sh + + CloudFront: + Type: !Rain::Module ../../RainModules/cloudfront-nocache.yml + Properties: + Name: gitea-server + DomainName: !GetAtt Server.PublicDnsName + Port: 8080 + Overrides: + Distribution: + DependsOn: Server + +Outputs: + URL: + Value: !Sub https://${CloudFrontDistribution.DomainName} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/Gitea/README.md b/human_reference_dataset/aws-cloudformation-templates/Solutions/Gitea/README.md new file mode 100644 index 0000000000000000000000000000000000000000..2e55c7704527257f858ee1e7b7df0d31a7cd9489 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/Gitea/README.md @@ -0,0 +1,31 @@ +# Gitea Server + +Create an EC2 instance with Gitea installed, and a CloudFront distribution for +encrypted access to the web ui from the browser. The output from the template +provides the CloudFront URL. + +As a prerequisite, you need to create a plaintext secret in Secrets Manager to +store your password for a Gitea user called 'admin1' that will be created by the +user data script. The default name for the secret is 'gitea-password'. Do not create +a "Key/value" secret, choose "Plaintext". + +## Files + +### `Gitea.yaml` + +This is the raw template, which includes [Rain](https://github.com/aws-cloudformation/rain) +directives to import a VPC module and embed the user data script. + +### `Gitea-pkg.yaml` + +The is the rendered template that you can deploy with `aws cloudformation +deploy` or `rain deploy`. To regenerate this template if you make any changes +to `Gitea.yaml`, run `rain pkg -x Gitea.yaml > Gitea-pkg.yaml`. + +### `Gitea.sh` + +This is the user data script that is embedded in the packaged template. It is +meant to be used with Amazon Linux instances. + + + diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/ManagedAD/README.md b/human_reference_dataset/aws-cloudformation-templates/Solutions/ManagedAD/README.md new file mode 100644 index 0000000000000000000000000000000000000000..dd110f44bcc5bf309086cb693111470bd912ff40 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/ManagedAD/README.md @@ -0,0 +1,34 @@ +# AWS Managed Microsoft AD + +## Description + +This solution creates an AWS Managed Microsoft AD directory that runs Active Directory (AD). + +- (Optional) Create AWS resources (IAM role & instance profile) to support seamlessly join Windows EC2 instances to your AWS Managed Microsoft AD + directory. +- (Optional) Create AWS resources (IAM role, instance profile, and secret) to support seamlessly join Linux EC2 instances to your AWS Managed + Microsoft AD directory. +- (Optional) Creates a Domain Members Security Group with **EXAMPLE** rules allowing all Private IP communications inbound. + +## Notes + +- CloudWatch Logs Log Group uses Amazon managed server-side encryption. Optionally, a KMS CMK can be used. +- Secrets Manager Secrets using Amazon managed server-side encryption. Optionally, a KMS CMK can be used. +- **NOTE** Security Group rules are configured to allow all inbound communications from [RFC1918](https://tools.ietf.org/html/rfc1918#section-3) + Private Address Space, which includes: `10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16`, this is used as an **EXAMPLE**, however, all security group + rules can be locked down based on the requirements. +- **NOTE** using the `Admin` AD credentials for the secret created to support seamlessly join Linux EC2 instances to AWS Managed Microsoft AD + directory as an **EXAMPLE**. + - However, you can create a new AD user and + [delegate directory join privileges for AWS Managed Microsoft AD](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/directory_join_privileges.html), + and then update the secret credentials accordingly. + +## Resources + +- [AWS Managed Microsoft AD](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/directory_microsoft_ad.html) +- [AWS Managed Microsoft AD Prerequisites](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/ms_ad_getting_started_prereqs.html) +- [Join an EC2 instance to your AWS Managed Microsoft AD directory](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/ms_ad_join_instance.html) + +## Instructions + +1. Launch the AWS CloudFormation stack using the [MANAGEDAD.cfn.yaml](templates/MANAGEDAD.cfn.yaml) template file as the source. diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/ManagedAD/templates/MANAGEDAD.cfn.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/ManagedAD/templates/MANAGEDAD.cfn.json new file mode 100644 index 0000000000000000000000000000000000000000..872cb7baba86d9cc312aa549d0d21665fa388f06 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/ManagedAD/templates/MANAGEDAD.cfn.json @@ -0,0 +1,776 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "This template creates an AWS Managed Microsoft AD directory. Tasks accomplished, (1) create AWS Managed Microsoft AD directory (2) option to create seamless domain join resources for Windows & Linux EC2 instances (3) option to create a domain members security group that allows all PrivateIP communications inbound (4) option to create DHCPOptionSet pointing to AWS Managed Microsoft AD DNS servers", + "Metadata": { + "AWS::CloudFormation::Interface": { + "ParameterGroups": [ + { + "Label": "Network Configuration", + "Parameters": [ + "VPCID", + "PrivateSubnet1ID", + "PrivateSubnet2ID", + "CreateDomainMembersSG", + "CreateDHCPOptionSet" + ] + }, + { + "Label": { + "default": "AWS Managed Microsoft AD Configuration" + }, + "Parameters": [ + "AWSManagedADDomainDNSName", + "AWSManagedADDomainNetBiosName", + "AWSManagedADEdition", + "SecretsManagerDomainCredentialsSecretsKMSKey", + "CreateWindowsEC2DomainJoinResources", + "CreateLinuxEC2DomainJoinResources", + "SSMLogsBucketName" + ] + } + ], + "ParameterLabels": { + "AWSManagedADDomainDNSName": { + "default": "AWS Managed Microsoft AD Domain DNS Name" + }, + "AWSManagedADDomainNetBiosName": { + "default": "AWS Managed Microsoft AD Domain NetBIOS Name" + }, + "AWSManagedADEdition": { + "default": "AWS Managed Microsoft AD Edition" + }, + "CreateDHCPOptionSet": { + "default": "Create DHCP Option Set" + }, + "CreateDomainMembersSG": { + "default": "Create Domain Members Security Group" + }, + "CreateLinuxEC2DomainJoinResources": { + "default": "Create AWS resources to support seamless domain join Linux EC2 instances" + }, + "CreateWindowsEC2DomainJoinResources": { + "default": "Create AWS resources to support seamless domain join Windows EC2 instances" + }, + "PrivateSubnet1ID": { + "default": "Private Subnet 1 ID" + }, + "PrivateSubnet2ID": { + "default": "Private Subnet 2 ID" + }, + "SecretsManagerDomainCredentialsSecretsKMSKey": { + "default": "Secrets Manager KMS Key for domain credentials secret" + }, + "SSMLogsBucketName": { + "default": "Systems Manager (SSM) Logs Bucket Name" + }, + "VPCID": { + "default": "VPC ID" + } + } + } + }, + "Parameters": { + "AWSManagedADDomainDNSName": { + "Description": "Fully qualified domain name for the AWS Managed Microsoft AD directory, such as corp.example.com.", + "Type": "String", + "Default": "awsmad.lab", + "AllowedPattern": "[a-zA-Z0-9-]+\\..+" + }, + "AWSManagedADDomainNetBiosName": { + "Description": "NetBIOS name for your domain, such as CORP.", + "Type": "String", + "Default": "AWSMAD", + "AllowedPattern": "[a-zA-Z0-9-]+", + "MaxLength": 15, + "MinLength": 1 + }, + "AWSManagedADEdition": { + "Description": "AWS Managed AD Edition. Standard supports up to 30,000+ directory objects. Enterprise supports up to 500,000+ directory objects.", + "Type": "String", + "AllowedValues": [ + "Standard", + "Enterprise" + ], + "Default": "Standard" + }, + "CreateDHCPOptionSet": { + "Description": "Create DHCP Option Set", + "Type": "String", + "AllowedValues": [ + "Yes", + "No" + ], + "Default": "No" + }, + "CreateDomainMembersSG": { + "Description": "Create Domain Members Security Group. Note, using allow any type rules, restrict accordingly.", + "Type": "String", + "AllowedValues": [ + "Yes", + "No" + ], + "Default": "No" + }, + "CreateLinuxEC2DomainJoinResources": { + "Description": "Create AWS resources (IAM role, instance profile, & secret) to support seamless domain join Linux EC2 instances", + "Type": "String", + "AllowedValues": [ + "Yes", + "No" + ], + "Default": "No" + }, + "CreateWindowsEC2DomainJoinResources": { + "Description": "Create AWS resources (IAM role & instnace profile)to support seamless domain join Windows EC2 instances", + "Type": "String", + "AllowedValues": [ + "Yes", + "No" + ], + "Default": "No" + }, + "PrivateSubnet1ID": { + "Description": "ID of the private subnet 1 in Availability Zone 1 (e.g., subnet-a0246dcd)", + "Type": "AWS::EC2::Subnet::Id" + }, + "PrivateSubnet2ID": { + "Description": "ID of the private subnet 2 in Availability Zone 2 (e.g., subnet-a0246dcd)", + "Type": "AWS::EC2::Subnet::Id" + }, + "SecretsManagerDomainCredentialsSecretsKMSKey": { + "Description": "(Optional) KMS Key ARN to use for encrypting the SecretsManager domain credentials secret. If empty, encryption is enabled with SecretsManager managing the server-side encryption keys.", + "Type": "String" + }, + "SSMLogsBucketName": { + "Description": "(Optional) SSM Logs bucket name for where Systems Manager logs should store log files. SSM Logs bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-).", + "Type": "String", + "Default": "", + "AllowedPattern": "^$|(?=^.{3,63}$)(?!.*[.-]{2})(?!.*[--]{2})(?!^(?:(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\\.(?!$)|$)){4}$)(^(([a-z0-9]|[a-z0-9][a-z0-9\\-]*[a-z0-9])\\.)*([a-z0-9]|[a-z0-9][a-z0-9\\-]*[a-z0-9])$)", + "ConstraintDescription": "SSM Logs bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-)." + }, + "VPCID": { + "Description": "ID of the VPC (e.g., vpc-0343606e)", + "Type": "AWS::EC2::VPC::Id" + } + }, + "Conditions": { + "DHCPOptionSetCondition": { + "Fn::Equals": [ + { + "Ref": "CreateDHCPOptionSet" + }, + "Yes" + ] + }, + "DomainMembersSGCondition": { + "Fn::Equals": [ + { + "Ref": "CreateDomainMembersSG" + }, + "Yes" + ] + }, + "LinuxEC2DomainJoinResourcesCondition": { + "Fn::Equals": [ + { + "Ref": "CreateLinuxEC2DomainJoinResources" + }, + "Yes" + ] + }, + "SecretsManagerDomainCredentialsSecretsKMSKeyCondition": { + "Fn::Not": [ + { + "Fn::Equals": [ + { + "Ref": "SecretsManagerDomainCredentialsSecretsKMSKey" + }, + "" + ] + } + ] + }, + "SSMLogsBucketNameCondition": { + "Fn::Not": [ + { + "Fn::Equals": [ + { + "Ref": "SSMLogsBucketName" + }, + "" + ] + } + ] + }, + "WindowsEC2DomainJoinResourcesCondition": { + "Fn::Equals": [ + { + "Ref": "CreateWindowsEC2DomainJoinResources" + }, + "Yes" + ] + } + }, + "Resources": { + "AWSManagedAD": { + "Type": "AWS::DirectoryService::MicrosoftAD", + "Properties": { + "Name": { + "Ref": "AWSManagedADDomainDNSName" + }, + "ShortName": { + "Ref": "AWSManagedADDomainNetBiosName" + }, + "Password": "{{resolve:secretsmanager:AWSManagedADAdminPassword:SecretString:password}}", + "Edition": { + "Ref": "AWSManagedADEdition" + }, + "VpcSettings": { + "SubnetIds": [ + { + "Ref": "PrivateSubnet1ID" + }, + { + "Ref": "PrivateSubnet2ID" + } + ], + "VpcId": { + "Ref": "VPCID" + } + } + } + }, + "AWSManagedADDomainMembersSG": { + "Type": "AWS::EC2::SecurityGroup", + "Metadata": { + "cfn_nag": { + "rules_to_suppress": [ + { + "id": "W42", + "reason": "Allow all inbound communications from Private IP CIDRs (for Lab purposes)" + }, + { + "id": "W40", + "reason": "Allow all outbound communications (for Lab purposes)" + }, + { + "id": "W5", + "reason": "Allow all outbound communications (for Lab purposes)" + }, + { + "id": "W9", + "reason": "Allow all inbound communications from Private IP CIDRs (for Lab purposes)" + } + ] + } + }, + "Properties": { + "GroupDescription": { + "Fn::Sub": "${AWSManagedADDomainNetBiosName} Domain Members SG via AWS Managed Microsoft AD" + }, + "VpcId": { + "Ref": "VPCID" + }, + "SecurityGroupIngress": [ + { + "IpProtocol": "-1", + "Description": "LAB - Allow All Private IP Communications", + "CidrIp": "10.0.0.0/8" + }, + { + "IpProtocol": "-1", + "Description": "LAB - Allow All Private IP Communications", + "CidrIp": "172.16.0.0/12" + }, + { + "IpProtocol": "-1", + "Description": "LAB - Allow All Private IP Communications", + "CidrIp": "192.168.0.0/16" + } + ], + "SecurityGroupEgress": [ + { + "Description": "Allow All Outbound Communications", + "IpProtocol": "-1", + "CidrIp": "0.0.0.0/0" + } + ], + "Tags": [ + { + "Key": "Name", + "Value": { + "Fn::Sub": "${AWSManagedADDomainNetBiosName}-DomainMembersSG-AWSManagedAD" + } + } + ] + }, + "Condition": "DomainMembersSGCondition" + }, + "AWSManagedADLinuxEC2DomainJoinInstanceProfile": { + "Type": "AWS::IAM::InstanceProfile", + "Properties": { + "InstanceProfileName": { + "Ref": "AWSManagedADLinuxEC2DomainJoinRole" + }, + "Path": "/", + "Roles": [ + { + "Ref": "AWSManagedADLinuxEC2DomainJoinRole" + } + ] + }, + "Condition": "LinuxEC2DomainJoinResourcesCondition" + }, + "AWSManagedADLinuxEC2DomainJoinRole": { + "Type": "AWS::IAM::Role", + "Metadata": { + "cfn_nag": { + "rules_to_suppress": [ + { + "id": "W28", + "reason": "The role name is defined to identify automation resources" + } + ] + } + }, + "Properties": { + "RoleName": { + "Fn::Sub": "${AWSManagedADDomainNetBiosName}-LinuxEC2DomainJoinRole-AWSManagedAD" + }, + "Description": { + "Fn::Sub": "IAM Role to Seamlessly Join Linux EC2 Instances to ${AWSManagedADDomainNetBiosName} Domain via AWS Managed Microsoft AD" + }, + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": "sts:AssumeRole", + "Principal": { + "Service": [ + "ec2.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + { + "Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/AmazonSSMManagedInstanceCore" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/AmazonSSMDirectoryServiceAccess" + } + ], + "Path": "/", + "Tags": [ + { + "Key": "StackName", + "Value": { + "Ref": "AWS::StackName" + } + } + ], + "Policies": [ + { + "PolicyName": "SSMAgent", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": "s3:GetObject", + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::aws-ssm-${AWS::Region}/*" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::aws-windows-downloads-${AWS::Region}/*" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::amazon-ssm-${AWS::Region}/*" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::amazon-ssm-packages-${AWS::Region}/*" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AWS::Region}-birdwatcher-prod/*" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::patch-baseline-snapshot-${AWS::Region}/*" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::aws-ssm-distributor-file-${AWS::Region}/*" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::aws-ssm-document-attachments-${AWS::Region}/*" + } + ] + } + ] + } + }, + { + "Fn::If": [ + "SSMLogsBucketNameCondition", + { + "PolicyName": "SsmLogs", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "s3:GetObject", + "s3:PutObject", + "s3:PutObjectAcl", + "s3:GetEncryptionConfiguration" + ], + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${SSMLogsBucketName}" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${SSMLogsBucketName}/*" + } + ] + } + ] + } + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + { + "PolicyName": "AWSManagedADLinuxEC2SeamlessDomainJoinSecret", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "secretsmanager:GetSecretValue", + "secretsmanager:DescribeSecret" + ], + "Resource": { + "Ref": "AWSManagedADLinuxEC2SeamlessDomainJoinSecret" + } + } + ] + } + }, + { + "Fn::If": [ + "SecretsManagerDomainCredentialsSecretsKMSKeyCondition", + { + "PolicyName": "KMSKeyForSecret", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": "kms:Decrypt", + "Resource": { + "Ref": "SecretsManagerDomainCredentialsSecretsKMSKey" + } + } + ] + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + ] + }, + "Condition": "LinuxEC2DomainJoinResourcesCondition" + }, + "AWSManagedADLinuxEC2SeamlessDomainJoinSecret": { + "Type": "AWS::SecretsManager::Secret", + "Properties": { + "Name": { + "Fn::Sub": "aws/directory-services/${AWSManagedAD}/seamless-domain-join" + }, + "Description": { + "Fn::Sub": "AD Credentials for Seamless Domain Join Windows/Linux EC2 instances to ${AWSManagedADDomainNetBiosName} Domain via AWS Managed Microsoft AD" + }, + "SecretString": "{ \"awsSeamlessDomainUsername\" : \"Admin\", \"awsSeamlessDomainPassword\" : \"{{resolve:secretsmanager:AWSManagedADAdminPassword:SecretString:password}}\" }", + "KmsKeyId": { + "Fn::If": [ + "SecretsManagerDomainCredentialsSecretsKMSKeyCondition", + { + "Ref": "SecretsManagerDomainCredentialsSecretsKMSKey" + }, + { + "Ref": "AWS::NoValue" + } + ] + } + }, + "Condition": "LinuxEC2DomainJoinResourcesCondition" + }, + "AWSManagedADWindowsEC2DomainJoinInstanceProfile": { + "Type": "AWS::IAM::InstanceProfile", + "Properties": { + "InstanceProfileName": { + "Ref": "AWSManagedADWindowsEC2DomainJoinRole" + }, + "Path": "/", + "Roles": [ + { + "Ref": "AWSManagedADWindowsEC2DomainJoinRole" + } + ] + }, + "Condition": "WindowsEC2DomainJoinResourcesCondition" + }, + "AWSManagedADWindowsEC2DomainJoinRole": { + "Type": "AWS::IAM::Role", + "Metadata": { + "cfn_nag": { + "rules_to_suppress": [ + { + "id": "W28", + "reason": "The role name is defined to identify automation resources" + } + ] + } + }, + "Properties": { + "RoleName": { + "Fn::Sub": "${AWSManagedADDomainNetBiosName}-AWSManagedAD-WindowsEC2DomainJoinRole" + }, + "Description": { + "Fn::Sub": "IAM Role to Seamlessly Join Windows EC2 Instances to ${AWSManagedADDomainDNSName} Domain via AWS Managed Microsoft AD" + }, + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": "sts:AssumeRole", + "Principal": { + "Service": [ + "ec2.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + { + "Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/AmazonSSMManagedInstanceCore" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/AmazonSSMDirectoryServiceAccess" + } + ], + "Path": "/", + "Tags": [ + { + "Key": "StackName", + "Value": { + "Ref": "AWS::StackName" + } + } + ], + "Policies": [ + { + "PolicyName": "SSMAgent", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": "s3:GetObject", + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::aws-ssm-${AWS::Region}/*" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::aws-windows-downloads-${AWS::Region}/*" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::amazon-ssm-${AWS::Region}/*" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::amazon-ssm-packages-${AWS::Region}/*" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AWS::Region}-birdwatcher-prod/*" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::patch-baseline-snapshot-${AWS::Region}/*" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::aws-ssm-distributor-file-${AWS::Region}/*" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::aws-ssm-document-attachments-${AWS::Region}/*" + } + ] + } + ] + } + }, + { + "Fn::If": [ + "SSMLogsBucketNameCondition", + { + "PolicyName": "SsmLogs", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "s3:GetObject", + "s3:PutObject", + "s3:PutObjectAcl", + "s3:GetEncryptionConfiguration" + ], + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${SSMLogsBucketName}" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${SSMLogsBucketName}/*" + } + ] + } + ] + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + ] + }, + "Condition": "WindowsEC2DomainJoinResourcesCondition" + }, + "DHCPOptions": { + "Type": "AWS::EC2::DHCPOptions", + "Properties": { + "DomainName": { + "Ref": "AWSManagedADDomainDNSName" + }, + "DomainNameServers": { + "Fn::GetAtt": [ + "AWSManagedAD", + "DnsIpAddresses" + ] + }, + "Tags": [ + { + "Key": "Name", + "Value": { + "Ref": "AWSManagedADDomainDNSName" + } + } + ] + }, + "Condition": "DHCPOptionSetCondition" + }, + "DHCPOptionsVPCAssociation": { + "Type": "AWS::EC2::VPCDHCPOptionsAssociation", + "Properties": { + "VpcId": { + "Ref": "VPCID" + }, + "DhcpOptionsId": { + "Ref": "DHCPOptions" + } + }, + "Condition": "DHCPOptionSetCondition" + } + }, + "Outputs": { + "AWSManagedADDirectoryId": { + "Description": "AWS Managed Microsoft AD Directory ID", + "Value": { + "Ref": "AWSManagedAD" + }, + "Export": { + "Name": { + "Fn::Sub": "${AWS::StackName}-AWSManagedADDirectoryId" + } + } + }, + "AWSManagedADDirectoryName": { + "Description": "AWS Managed Microsoft AD Directory Name", + "Value": { + "Ref": "AWSManagedADDomainDNSName" + }, + "Export": { + "Name": { + "Fn::Sub": "${AWS::StackName}-AWSManagedADDirectoryName" + } + } + }, + "AWSManagedADAWSManagedADDomainMembersSG": { + "Description": "AWS Managed Microsoft AD Domain Members Security Group", + "Value": { + "Ref": "AWSManagedADDomainMembersSG" + }, + "Export": { + "Name": { + "Fn::Sub": "${AWS::StackName}-${AWSManagedADDomainNetBiosName}-AWSManagedADDomainMembersSG" + } + }, + "Condition": "DomainMembersSGCondition" + }, + "AWSManagedADWindowsEC2SeamlessDomainJoinInstanceProfile": { + "Description": "IAM Instance Profile with SSM Document Rights to Join Windows Computers via AWS Managed Microsoft AD", + "Value": { + "Ref": "AWSManagedADWindowsEC2DomainJoinInstanceProfile" + }, + "Export": { + "Name": { + "Fn::Sub": "${AWS::StackName}-${AWSManagedADDomainNetBiosName}-AWSManagedADWindowsEC2DomainJoinProfile" + } + }, + "Condition": "WindowsEC2DomainJoinResourcesCondition" + }, + "AWSManagedADWindowsEC2SeamlessDomainJoinRole": { + "Description": "IAM Instance Profile with SSM Document Rights to Join Windows Computers via AWS Managed Microsoft AD", + "Value": { + "Ref": "AWSManagedADWindowsEC2DomainJoinRole" + }, + "Export": { + "Name": { + "Fn::Sub": "${AWS::StackName}-${AWSManagedADDomainNetBiosName}-AWSManagedADWindowsEC2DomainJoinRole" + } + }, + "Condition": "WindowsEC2DomainJoinResourcesCondition" + }, + "AWSManagedADLinuxEC2SeamlessDomainJoinInstanceProfile": { + "Description": "IAM Instance Profile with SSM Document Rights to Join Linux Computers via AWS Managed Microsoft AD", + "Value": { + "Ref": "AWSManagedADLinuxEC2DomainJoinInstanceProfile" + }, + "Export": { + "Name": { + "Fn::Sub": "${AWS::StackName}-${AWSManagedADDomainNetBiosName}-AWSManagedADLinuxEC2DomainJoinProfile" + } + }, + "Condition": "LinuxEC2DomainJoinResourcesCondition" + }, + "AWSManagedADLinuxEC2SeamlessDomainJoinRole": { + "Description": "IAM Instance Profile with SSM Document Rights to Join Linux Computers via AWS Managed Microsoft AD", + "Value": { + "Ref": "AWSManagedADLinuxEC2DomainJoinRole" + }, + "Export": { + "Name": { + "Fn::Sub": "${AWS::StackName}-${AWSManagedADDomainNetBiosName}-AWSManagedADLinuxEC2DomainJoinRole" + } + }, + "Condition": "LinuxEC2DomainJoinResourcesCondition" + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/ManagedAD/templates/MANAGEDAD.cfn.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/ManagedAD/templates/MANAGEDAD.cfn.yaml new file mode 100644 index 0000000000000000000000000000000000000000..8cccfc0c17bfb67f753aa5b7a81268752e1a010a --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/ManagedAD/templates/MANAGEDAD.cfn.yaml @@ -0,0 +1,435 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: This template creates an AWS Managed Microsoft AD directory. Tasks accomplished, (1) create AWS Managed Microsoft AD directory (2) option to create seamless domain join resources for Windows & Linux EC2 instances (3) option to create a domain members security group that allows all PrivateIP communications inbound (4) option to create DHCPOptionSet pointing to AWS Managed Microsoft AD DNS servers + +Metadata: + AWS::CloudFormation::Interface: + ParameterGroups: + - Label: Network Configuration + Parameters: + - VPCID + - PrivateSubnet1ID + - PrivateSubnet2ID + - CreateDomainMembersSG + - CreateDHCPOptionSet + - Label: + default: AWS Managed Microsoft AD Configuration + Parameters: + - AWSManagedADDomainDNSName + - AWSManagedADDomainNetBiosName + - AWSManagedADEdition + - SecretsManagerDomainCredentialsSecretsKMSKey + - CreateWindowsEC2DomainJoinResources + - CreateLinuxEC2DomainJoinResources + - SSMLogsBucketName + ParameterLabels: + AWSManagedADDomainDNSName: + default: AWS Managed Microsoft AD Domain DNS Name + AWSManagedADDomainNetBiosName: + default: AWS Managed Microsoft AD Domain NetBIOS Name + AWSManagedADEdition: + default: AWS Managed Microsoft AD Edition + CreateDHCPOptionSet: + default: Create DHCP Option Set + CreateDomainMembersSG: + default: Create Domain Members Security Group + CreateLinuxEC2DomainJoinResources: + default: Create AWS resources to support seamless domain join Linux EC2 instances + CreateWindowsEC2DomainJoinResources: + default: Create AWS resources to support seamless domain join Windows EC2 instances + PrivateSubnet1ID: + default: Private Subnet 1 ID + PrivateSubnet2ID: + default: Private Subnet 2 ID + SecretsManagerDomainCredentialsSecretsKMSKey: + default: Secrets Manager KMS Key for domain credentials secret + SSMLogsBucketName: + default: Systems Manager (SSM) Logs Bucket Name + VPCID: + default: VPC ID + +Parameters: + AWSManagedADDomainDNSName: + Description: Fully qualified domain name for the AWS Managed Microsoft AD directory, such as corp.example.com. + Type: String + Default: awsmad.lab + AllowedPattern: '[a-zA-Z0-9-]+\..+' + + AWSManagedADDomainNetBiosName: + Description: NetBIOS name for your domain, such as CORP. + Type: String + Default: AWSMAD + AllowedPattern: '[a-zA-Z0-9-]+' + MaxLength: 15 + MinLength: 1 + + AWSManagedADEdition: + Description: AWS Managed AD Edition. Standard supports up to 30,000+ directory objects. Enterprise supports up to 500,000+ directory objects. + Type: String + AllowedValues: + - Standard + - Enterprise + Default: Standard + + CreateDHCPOptionSet: + Description: Create DHCP Option Set + Type: String + AllowedValues: + - Yes + - No + Default: No + + CreateDomainMembersSG: + Description: Create Domain Members Security Group. Note, using allow any type rules, restrict accordingly. + Type: String + AllowedValues: + - Yes + - No + Default: No + + CreateLinuxEC2DomainJoinResources: + Description: Create AWS resources (IAM role, instance profile, & secret) to support seamless domain join Linux EC2 instances + Type: String + AllowedValues: + - Yes + - No + Default: No + + CreateWindowsEC2DomainJoinResources: + Description: Create AWS resources (IAM role & instnace profile)to support seamless domain join Windows EC2 instances + Type: String + AllowedValues: + - Yes + - No + Default: No + + PrivateSubnet1ID: + Description: ID of the private subnet 1 in Availability Zone 1 (e.g., subnet-a0246dcd) + Type: AWS::EC2::Subnet::Id + + PrivateSubnet2ID: + Description: ID of the private subnet 2 in Availability Zone 2 (e.g., subnet-a0246dcd) + Type: AWS::EC2::Subnet::Id + + SecretsManagerDomainCredentialsSecretsKMSKey: + Description: (Optional) KMS Key ARN to use for encrypting the SecretsManager domain credentials secret. If empty, encryption is enabled with SecretsManager managing the server-side encryption keys. + Type: String + + SSMLogsBucketName: + Description: (Optional) SSM Logs bucket name for where Systems Manager logs should store log files. SSM Logs bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-). + Type: String + Default: "" + AllowedPattern: ^$|(?=^.{3,63}$)(?!.*[.-]{2})(?!.*[--]{2})(?!^(?:(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\.(?!$)|$)){4}$)(^(([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])\.)*([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])$) + ConstraintDescription: SSM Logs bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-). + + VPCID: + Description: ID of the VPC (e.g., vpc-0343606e) + Type: AWS::EC2::VPC::Id + +Conditions: + DHCPOptionSetCondition: !Equals + - !Ref CreateDHCPOptionSet + - Yes + + DomainMembersSGCondition: !Equals + - !Ref CreateDomainMembersSG + - Yes + + LinuxEC2DomainJoinResourcesCondition: !Equals + - !Ref CreateLinuxEC2DomainJoinResources + - Yes + + SecretsManagerDomainCredentialsSecretsKMSKeyCondition: !Not + - !Equals + - !Ref SecretsManagerDomainCredentialsSecretsKMSKey + - "" + + SSMLogsBucketNameCondition: !Not + - !Equals + - !Ref SSMLogsBucketName + - "" + + WindowsEC2DomainJoinResourcesCondition: !Equals + - !Ref CreateWindowsEC2DomainJoinResources + - Yes + +Resources: + AWSManagedAD: + Type: AWS::DirectoryService::MicrosoftAD + Properties: + Name: !Ref AWSManagedADDomainDNSName + ShortName: !Ref AWSManagedADDomainNetBiosName + Password: '{{resolve:secretsmanager:AWSManagedADAdminPassword:SecretString:password}}' + Edition: !Ref AWSManagedADEdition + VpcSettings: + SubnetIds: + - !Ref PrivateSubnet1ID + - !Ref PrivateSubnet2ID + VpcId: !Ref VPCID + + AWSManagedADDomainMembersSG: + Type: AWS::EC2::SecurityGroup + Metadata: + cfn_nag: + rules_to_suppress: + - id: W42 + reason: Allow all inbound communications from Private IP CIDRs (for Lab purposes) + - id: W40 + reason: Allow all outbound communications (for Lab purposes) + - id: W5 + reason: Allow all outbound communications (for Lab purposes) + - id: W9 + reason: Allow all inbound communications from Private IP CIDRs (for Lab purposes) + Properties: + GroupDescription: !Sub ${AWSManagedADDomainNetBiosName} Domain Members SG via AWS Managed Microsoft AD + VpcId: !Ref VPCID + SecurityGroupIngress: + - IpProtocol: "-1" + Description: LAB - Allow All Private IP Communications + CidrIp: 10.0.0.0/8 + - IpProtocol: "-1" + Description: LAB - Allow All Private IP Communications + CidrIp: 172.16.0.0/12 + - IpProtocol: "-1" + Description: LAB - Allow All Private IP Communications + CidrIp: 192.168.0.0/16 + SecurityGroupEgress: + - Description: Allow All Outbound Communications + IpProtocol: "-1" + CidrIp: 0.0.0.0/0 + Tags: + - Key: Name + Value: !Sub ${AWSManagedADDomainNetBiosName}-DomainMembersSG-AWSManagedAD + Condition: DomainMembersSGCondition + + AWSManagedADLinuxEC2DomainJoinInstanceProfile: + Type: AWS::IAM::InstanceProfile + Properties: + InstanceProfileName: !Ref AWSManagedADLinuxEC2DomainJoinRole + Path: / + Roles: + - !Ref AWSManagedADLinuxEC2DomainJoinRole + Condition: LinuxEC2DomainJoinResourcesCondition + + AWSManagedADLinuxEC2DomainJoinRole: + Type: AWS::IAM::Role + Metadata: + cfn_nag: + rules_to_suppress: + - id: W28 + reason: The role name is defined to identify automation resources + Properties: + RoleName: !Sub ${AWSManagedADDomainNetBiosName}-LinuxEC2DomainJoinRole-AWSManagedAD + Description: !Sub IAM Role to Seamlessly Join Linux EC2 Instances to ${AWSManagedADDomainNetBiosName} Domain via AWS Managed Microsoft AD + AssumeRolePolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: sts:AssumeRole + Principal: + Service: + - ec2.amazonaws.com + ManagedPolicyArns: + - !Sub arn:${AWS::Partition}:iam::aws:policy/AmazonSSMManagedInstanceCore + - !Sub arn:${AWS::Partition}:iam::aws:policy/AmazonSSMDirectoryServiceAccess + Path: / + Tags: + - Key: StackName + Value: !Ref AWS::StackName + Policies: + - PolicyName: SSMAgent + PolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: s3:GetObject + Resource: + - !Sub arn:${AWS::Partition}:s3:::aws-ssm-${AWS::Region}/* + - !Sub arn:${AWS::Partition}:s3:::aws-windows-downloads-${AWS::Region}/* + - !Sub arn:${AWS::Partition}:s3:::amazon-ssm-${AWS::Region}/* + - !Sub arn:${AWS::Partition}:s3:::amazon-ssm-packages-${AWS::Region}/* + - !Sub arn:${AWS::Partition}:s3:::${AWS::Region}-birdwatcher-prod/* + - !Sub arn:${AWS::Partition}:s3:::patch-baseline-snapshot-${AWS::Region}/* + - !Sub arn:${AWS::Partition}:s3:::aws-ssm-distributor-file-${AWS::Region}/* + - !Sub arn:${AWS::Partition}:s3:::aws-ssm-document-attachments-${AWS::Region}/* + - !If + - SSMLogsBucketNameCondition + - PolicyName: SsmLogs + PolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: + - s3:GetObject + - s3:PutObject + - s3:PutObjectAcl + - s3:GetEncryptionConfiguration + Resource: + - !Sub arn:${AWS::Partition}:s3:::${SSMLogsBucketName} + - !Sub arn:${AWS::Partition}:s3:::${SSMLogsBucketName}/* + - !Ref AWS::NoValue + - PolicyName: AWSManagedADLinuxEC2SeamlessDomainJoinSecret + PolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: + - secretsmanager:GetSecretValue + - secretsmanager:DescribeSecret + Resource: !Ref AWSManagedADLinuxEC2SeamlessDomainJoinSecret + - !If + - SecretsManagerDomainCredentialsSecretsKMSKeyCondition + - PolicyName: KMSKeyForSecret + PolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: kms:Decrypt + Resource: !Ref SecretsManagerDomainCredentialsSecretsKMSKey + - !Ref AWS::NoValue + Condition: LinuxEC2DomainJoinResourcesCondition + + AWSManagedADLinuxEC2SeamlessDomainJoinSecret: + Type: AWS::SecretsManager::Secret + Properties: + Name: !Sub aws/directory-services/${AWSManagedAD}/seamless-domain-join + Description: !Sub AD Credentials for Seamless Domain Join Windows/Linux EC2 instances to ${AWSManagedADDomainNetBiosName} Domain via AWS Managed Microsoft AD + SecretString: '{ "awsSeamlessDomainUsername" : "Admin", "awsSeamlessDomainPassword" : "{{resolve:secretsmanager:AWSManagedADAdminPassword:SecretString:password}}" }' + KmsKeyId: !If + - SecretsManagerDomainCredentialsSecretsKMSKeyCondition + - !Ref SecretsManagerDomainCredentialsSecretsKMSKey + - !Ref AWS::NoValue + Condition: LinuxEC2DomainJoinResourcesCondition + + AWSManagedADWindowsEC2DomainJoinInstanceProfile: + Type: AWS::IAM::InstanceProfile + Properties: + InstanceProfileName: !Ref AWSManagedADWindowsEC2DomainJoinRole + Path: / + Roles: + - !Ref AWSManagedADWindowsEC2DomainJoinRole + Condition: WindowsEC2DomainJoinResourcesCondition + + AWSManagedADWindowsEC2DomainJoinRole: + Type: AWS::IAM::Role + Metadata: + cfn_nag: + rules_to_suppress: + - id: W28 + reason: The role name is defined to identify automation resources + Properties: + RoleName: !Sub ${AWSManagedADDomainNetBiosName}-AWSManagedAD-WindowsEC2DomainJoinRole + Description: !Sub IAM Role to Seamlessly Join Windows EC2 Instances to ${AWSManagedADDomainDNSName} Domain via AWS Managed Microsoft AD + AssumeRolePolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: sts:AssumeRole + Principal: + Service: + - ec2.amazonaws.com + ManagedPolicyArns: + - !Sub arn:${AWS::Partition}:iam::aws:policy/AmazonSSMManagedInstanceCore + - !Sub arn:${AWS::Partition}:iam::aws:policy/AmazonSSMDirectoryServiceAccess + Path: / + Tags: + - Key: StackName + Value: !Ref AWS::StackName + Policies: + - PolicyName: SSMAgent + PolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: s3:GetObject + Resource: + - !Sub arn:${AWS::Partition}:s3:::aws-ssm-${AWS::Region}/* + - !Sub arn:${AWS::Partition}:s3:::aws-windows-downloads-${AWS::Region}/* + - !Sub arn:${AWS::Partition}:s3:::amazon-ssm-${AWS::Region}/* + - !Sub arn:${AWS::Partition}:s3:::amazon-ssm-packages-${AWS::Region}/* + - !Sub arn:${AWS::Partition}:s3:::${AWS::Region}-birdwatcher-prod/* + - !Sub arn:${AWS::Partition}:s3:::patch-baseline-snapshot-${AWS::Region}/* + - !Sub arn:${AWS::Partition}:s3:::aws-ssm-distributor-file-${AWS::Region}/* + - !Sub arn:${AWS::Partition}:s3:::aws-ssm-document-attachments-${AWS::Region}/* + - !If + - SSMLogsBucketNameCondition + - PolicyName: SsmLogs + PolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: + - s3:GetObject + - s3:PutObject + - s3:PutObjectAcl + - s3:GetEncryptionConfiguration + Resource: + - !Sub arn:${AWS::Partition}:s3:::${SSMLogsBucketName} + - !Sub arn:${AWS::Partition}:s3:::${SSMLogsBucketName}/* + - !Ref AWS::NoValue + Condition: WindowsEC2DomainJoinResourcesCondition + + DHCPOptions: + Type: AWS::EC2::DHCPOptions + Properties: + DomainName: !Ref AWSManagedADDomainDNSName + DomainNameServers: !GetAtt AWSManagedAD.DnsIpAddresses + Tags: + - Key: Name + Value: !Ref AWSManagedADDomainDNSName + Condition: DHCPOptionSetCondition + + DHCPOptionsVPCAssociation: + Type: AWS::EC2::VPCDHCPOptionsAssociation + Properties: + VpcId: !Ref VPCID + DhcpOptionsId: !Ref DHCPOptions + Condition: DHCPOptionSetCondition + +Outputs: + AWSManagedADDirectoryId: + Description: AWS Managed Microsoft AD Directory ID + Value: !Ref AWSManagedAD + Export: + Name: !Sub ${AWS::StackName}-AWSManagedADDirectoryId + + AWSManagedADDirectoryName: + Description: AWS Managed Microsoft AD Directory Name + Value: !Ref AWSManagedADDomainDNSName + Export: + Name: !Sub ${AWS::StackName}-AWSManagedADDirectoryName + + AWSManagedADAWSManagedADDomainMembersSG: + Description: AWS Managed Microsoft AD Domain Members Security Group + Value: !Ref AWSManagedADDomainMembersSG + Export: + Name: !Sub ${AWS::StackName}-${AWSManagedADDomainNetBiosName}-AWSManagedADDomainMembersSG + Condition: DomainMembersSGCondition + + AWSManagedADWindowsEC2SeamlessDomainJoinInstanceProfile: + Description: IAM Instance Profile with SSM Document Rights to Join Windows Computers via AWS Managed Microsoft AD + Value: !Ref AWSManagedADWindowsEC2DomainJoinInstanceProfile + Export: + Name: !Sub ${AWS::StackName}-${AWSManagedADDomainNetBiosName}-AWSManagedADWindowsEC2DomainJoinProfile + Condition: WindowsEC2DomainJoinResourcesCondition + + AWSManagedADWindowsEC2SeamlessDomainJoinRole: + Description: IAM Instance Profile with SSM Document Rights to Join Windows Computers via AWS Managed Microsoft AD + Value: !Ref AWSManagedADWindowsEC2DomainJoinRole + Export: + Name: !Sub ${AWS::StackName}-${AWSManagedADDomainNetBiosName}-AWSManagedADWindowsEC2DomainJoinRole + Condition: WindowsEC2DomainJoinResourcesCondition + + AWSManagedADLinuxEC2SeamlessDomainJoinInstanceProfile: + Description: IAM Instance Profile with SSM Document Rights to Join Linux Computers via AWS Managed Microsoft AD + Value: !Ref AWSManagedADLinuxEC2DomainJoinInstanceProfile + Export: + Name: !Sub ${AWS::StackName}-${AWSManagedADDomainNetBiosName}-AWSManagedADLinuxEC2DomainJoinProfile + Condition: LinuxEC2DomainJoinResourcesCondition + + AWSManagedADLinuxEC2SeamlessDomainJoinRole: + Description: IAM Instance Profile with SSM Document Rights to Join Linux Computers via AWS Managed Microsoft AD + Value: !Ref AWSManagedADLinuxEC2DomainJoinRole + Export: + Name: !Sub ${AWS::StackName}-${AWSManagedADDomainNetBiosName}-AWSManagedADLinuxEC2DomainJoinRole + Condition: LinuxEC2DomainJoinResourcesCondition diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/OperatingSystems/RHEL9_cfn-hup.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/OperatingSystems/RHEL9_cfn-hup.json new file mode 100644 index 0000000000000000000000000000000000000000..5ff480ae7b7abc747a9655234a217d4e08cfc32b --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/OperatingSystems/RHEL9_cfn-hup.json @@ -0,0 +1,392 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "Installing Cloudformation helper scripts in RHEL 9", + "Parameters": { + "KeyName": { + "Description": "Name of an existing EC2 KeyPair to enable SSH access to the instance", + "Type": "AWS::EC2::KeyPair::KeyName" + }, + "InstanceType": { + "Description": "WebServer EC2 instance type", + "Type": "String", + "AllowedValues": [ + "t1.micro", + "t2.nano", + "t2.micro", + "t2.small", + "t2.medium", + "t2.large", + "m1.small", + "m1.medium", + "m1.large", + "m1.xlarge", + "m2.xlarge", + "m2.2xlarge", + "m2.4xlarge", + "m3.medium", + "m3.large", + "m3.xlarge", + "m3.2xlarge", + "m4.large", + "m4.xlarge", + "m4.2xlarge", + "m4.4xlarge", + "m4.10xlarge", + "c1.medium", + "c1.xlarge", + "c3.large", + "c3.xlarge", + "c3.2xlarge", + "c3.4xlarge", + "c3.8xlarge", + "c4.large", + "c4.xlarge", + "c4.2xlarge", + "c4.4xlarge", + "c4.8xlarge", + "r3.large", + "r3.xlarge", + "r3.2xlarge", + "r3.4xlarge", + "r3.8xlarge", + "i2.xlarge", + "i2.2xlarge", + "i2.4xlarge", + "i2.8xlarge", + "d2.xlarge", + "d2.2xlarge", + "d2.4xlarge", + "d2.8xlarge", + "hs1.8xlarge", + "cr1.8xlarge", + "cc2.8xlarge" + ], + "Default": "t2.small", + "ConstraintDescription": "must be a valid EC2 instance type." + }, + "SSHLocation": { + "Description": "The IP address range that can be used to SSH to the EC2 instances", + "Type": "String", + "Default": "0.0.0.0/0", + "MinLength": "9", + "MaxLength": "18", + "AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})", + "ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x." + }, + "SubnetId": { + "Type": "AWS::EC2::Subnet::Id" + } + }, + "Mappings": { + "AWSInstanceType2Arch": { + "t1.micro": { + "Arch": "HVM64" + }, + "t2.nano": { + "Arch": "HVM64" + }, + "t2.micro": { + "Arch": "HVM64" + }, + "t2.small": { + "Arch": "HVM64" + }, + "t2.medium": { + "Arch": "HVM64" + }, + "t2.large": { + "Arch": "HVM64" + }, + "m1.small": { + "Arch": "HVM64" + }, + "m1.medium": { + "Arch": "HVM64" + }, + "m1.large": { + "Arch": "HVM64" + }, + "m1.xlarge": { + "Arch": "HVM64" + }, + "m2.xlarge": { + "Arch": "HVM64" + }, + "m2.2xlarge": { + "Arch": "HVM64" + }, + "m2.4xlarge": { + "Arch": "HVM64" + }, + "m3.medium": { + "Arch": "HVM64" + }, + "m3.large": { + "Arch": "HVM64" + }, + "m3.xlarge": { + "Arch": "HVM64" + }, + "m3.2xlarge": { + "Arch": "HVM64" + }, + "m4.large": { + "Arch": "HVM64" + }, + "m4.xlarge": { + "Arch": "HVM64" + }, + "m4.2xlarge": { + "Arch": "HVM64" + }, + "m4.4xlarge": { + "Arch": "HVM64" + }, + "m4.10xlarge": { + "Arch": "HVM64" + }, + "c1.medium": { + "Arch": "HVM64" + }, + "c1.xlarge": { + "Arch": "HVM64" + }, + "c3.large": { + "Arch": "HVM64" + }, + "c3.xlarge": { + "Arch": "HVM64" + }, + "c3.2xlarge": { + "Arch": "HVM64" + }, + "c3.4xlarge": { + "Arch": "HVM64" + }, + "c3.8xlarge": { + "Arch": "HVM64" + }, + "c4.large": { + "Arch": "HVM64" + }, + "c4.xlarge": { + "Arch": "HVM64" + }, + "c4.2xlarge": { + "Arch": "HVM64" + }, + "c4.4xlarge": { + "Arch": "HVM64" + }, + "c4.8xlarge": { + "Arch": "HVM64" + }, + "r3.large": { + "Arch": "HVM64" + }, + "r3.xlarge": { + "Arch": "HVM64" + }, + "r3.2xlarge": { + "Arch": "HVM64" + }, + "r3.4xlarge": { + "Arch": "HVM64" + }, + "r3.8xlarge": { + "Arch": "HVM64" + }, + "i2.xlarge": { + "Arch": "HVM64" + }, + "i2.2xlarge": { + "Arch": "HVM64" + }, + "i2.4xlarge": { + "Arch": "HVM64" + }, + "i2.8xlarge": { + "Arch": "HVM64" + }, + "d2.xlarge": { + "Arch": "HVM64" + }, + "d2.2xlarge": { + "Arch": "HVM64" + }, + "d2.4xlarge": { + "Arch": "HVM64" + }, + "d2.8xlarge": { + "Arch": "HVM64" + }, + "hi1.4xlarge": { + "Arch": "HVM64" + }, + "hs1.8xlarge": { + "Arch": "HVM64" + }, + "cr1.8xlarge": { + "Arch": "HVM64" + }, + "cc2.8xlarge": { + "Arch": "HVM64" + } + }, + "AWSRegionArch2AMI": { + "us-east-1": { + "HVM64": "ami-05723c3b9cf4bf4ff" + }, + "us-west-2": { + "HVM64": "ami-0b6ce9bcd0a2f720d" + }, + "us-west-1": { + "HVM64": "ami-029465c1f346dd34f" + }, + "eu-west-1": { + "HVM64": "ami-0f11fb3119dc9fc60" + }, + "eu-west-2": { + "HVM64": "ami-023cd3f0d10fb8a9c" + }, + "eu-west-3": { + "HVM64": "ami-0c226b3aa389adbef" + }, + "eu-central-1": { + "HVM64": "ami-0c0000ceb18c73b8a" + }, + "ap-northeast-1": { + "HVM64": "ami-083594d506bfbc152" + }, + "ap-northeast-2": { + "HVM64": "ami-07cc74f198bb9e86a" + }, + "ap-northeast-3": { + "HVM64": "ami-0ee7ab88ad9d14d40" + }, + "ap-southeast-1": { + "HVM64": "ami-0b2aec26bb1a5169d" + }, + "ap-southeast-2": { + "HVM64": "ami-003cf7280eac7a28a" + }, + "ap-south-1": { + "HVM64": "ami-069d9fecd19e7ed40" + }, + "us-east-2": { + "HVM64": "ami-08d616b7fbe4bb9d0" + }, + "ca-central-1": { + "HVM64": "ami-093dddc44bec52167" + }, + "sa-east-1": { + "HVM64": "ami-07509c78b1456cc84" + } + } + }, + "Resources": { + "EC2Instance": { + "CreationPolicy": { + "ResourceSignal": { + "Timeout": "PT10M", + "Count": "1" + } + }, + "Type": "AWS::EC2::Instance", + "Metadata": { + "AWS::CloudFormation::Init": { + "configSets": { + "full_install": [ + "install_and_enable_cfn_hup" + ] + }, + "install_and_enable_cfn_hup": { + "files": { + "/etc/cfn/cfn-hup.conf": { + "content": { + "Fn::Sub": "[main]\nstack=${AWS::StackId}\nregion=${AWS::Region}\n" + }, + "mode": "000400", + "owner": "root", + "group": "root" + }, + "/etc/cfn/hooks.d/cfn-auto-reloader.conf": { + "content": { + "Fn::Sub": "[cfn-auto-reloader-hook]\ntriggers=post.update\npath=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init\naction=/usr/local/bin/cfn-init -v --stack ${AWS::StackName} --resource EC2Instance --configsets full_install --region ${AWS::Region}\nrunas=root\n" + } + }, + "/lib/systemd/system/cfn-hup.service": { + "content": "[Unit]\nDescription=cfn-hup daemon\n\n[Service]\nType=simple\nExecStart=/usr/local/bin/cfn-hup\nRestart=always\n\n[Install]\nWantedBy=multi-user.target\n" + } + }, + "commands": { + "01enable_cfn_hup": { + "command": "systemctl enable cfn-hup.service" + }, + "02start_cfn_hup": { + "command": "systemctl start cfn-hup.service" + } + } + } + } + }, + "Properties": { + "InstanceType": { + "Ref": "InstanceType" + }, + "SubnetId": { + "Ref": "SubnetId" + }, + "SecurityGroupIds": [ + { + "Fn::GetAtt": [ + "InstanceSecurityGroup", + "GroupId" + ] + } + ], + "KeyName": { + "Ref": "KeyName" + }, + "ImageId": { + "Fn::FindInMap": [ + "AWSRegionArch2AMI", + { + "Ref": "AWS::Region" + }, + { + "Fn::FindInMap": [ + "AWSInstanceType2Arch", + { + "Ref": "InstanceType" + }, + "Arch" + ] + } + ] + }, + "UserData": { + "Fn::Base64": { + "Fn::Sub": "#!/bin/bash -xe\n\nsudo yum update -y\nsudo yum -y install python3-pip\nsudo pip3 install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz\n/usr/local/bin/cfn-init -v --stack ${AWS::StackName} --resource EC2Instance --configsets full_install --region ${AWS::Region} \n/usr/local/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource EC2Instance --region ${AWS::Region}\n" + } + } + } + }, + "InstanceSecurityGroup": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "Enable SSH access via port 22", + "SecurityGroupIngress": [ + { + "IpProtocol": "tcp", + "FromPort": "22", + "ToPort": "22", + "CidrIp": { + "Ref": "SSHLocation" + } + } + ] + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/OperatingSystems/RHEL9_cfn-hup.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/OperatingSystems/RHEL9_cfn-hup.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ca014d88bd0acfe7b522b89f4889678e3268fad5 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/OperatingSystems/RHEL9_cfn-hup.yaml @@ -0,0 +1,288 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: Installing Cloudformation helper scripts in RHEL 9 + +Parameters: + KeyName: + Description: Name of an existing EC2 KeyPair to enable SSH access to the instance + Type: AWS::EC2::KeyPair::KeyName + + InstanceType: + Description: WebServer EC2 instance type + Type: String + AllowedValues: + - t1.micro + - t2.nano + - t2.micro + - t2.small + - t2.medium + - t2.large + - m1.small + - m1.medium + - m1.large + - m1.xlarge + - m2.xlarge + - m2.2xlarge + - m2.4xlarge + - m3.medium + - m3.large + - m3.xlarge + - m3.2xlarge + - m4.large + - m4.xlarge + - m4.2xlarge + - m4.4xlarge + - m4.10xlarge + - c1.medium + - c1.xlarge + - c3.large + - c3.xlarge + - c3.2xlarge + - c3.4xlarge + - c3.8xlarge + - c4.large + - c4.xlarge + - c4.2xlarge + - c4.4xlarge + - c4.8xlarge + - r3.large + - r3.xlarge + - r3.2xlarge + - r3.4xlarge + - r3.8xlarge + - i2.xlarge + - i2.2xlarge + - i2.4xlarge + - i2.8xlarge + - d2.xlarge + - d2.2xlarge + - d2.4xlarge + - d2.8xlarge + - hs1.8xlarge + - cr1.8xlarge + - cc2.8xlarge + Default: t2.small + ConstraintDescription: must be a valid EC2 instance type. + + SSHLocation: + Description: The IP address range that can be used to SSH to the EC2 instances + Type: String + Default: 0.0.0.0/0 + MinLength: "9" + MaxLength: "18" + AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2}) + ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x. + + SubnetId: + Type: AWS::EC2::Subnet::Id + +Mappings: + AWSInstanceType2Arch: + t1.micro: + Arch: HVM64 + t2.nano: + Arch: HVM64 + t2.micro: + Arch: HVM64 + t2.small: + Arch: HVM64 + t2.medium: + Arch: HVM64 + t2.large: + Arch: HVM64 + m1.small: + Arch: HVM64 + m1.medium: + Arch: HVM64 + m1.large: + Arch: HVM64 + m1.xlarge: + Arch: HVM64 + m2.xlarge: + Arch: HVM64 + m2.2xlarge: + Arch: HVM64 + m2.4xlarge: + Arch: HVM64 + m3.medium: + Arch: HVM64 + m3.large: + Arch: HVM64 + m3.xlarge: + Arch: HVM64 + m3.2xlarge: + Arch: HVM64 + m4.large: + Arch: HVM64 + m4.xlarge: + Arch: HVM64 + m4.2xlarge: + Arch: HVM64 + m4.4xlarge: + Arch: HVM64 + m4.10xlarge: + Arch: HVM64 + c1.medium: + Arch: HVM64 + c1.xlarge: + Arch: HVM64 + c3.large: + Arch: HVM64 + c3.xlarge: + Arch: HVM64 + c3.2xlarge: + Arch: HVM64 + c3.4xlarge: + Arch: HVM64 + c3.8xlarge: + Arch: HVM64 + c4.large: + Arch: HVM64 + c4.xlarge: + Arch: HVM64 + c4.2xlarge: + Arch: HVM64 + c4.4xlarge: + Arch: HVM64 + c4.8xlarge: + Arch: HVM64 + r3.large: + Arch: HVM64 + r3.xlarge: + Arch: HVM64 + r3.2xlarge: + Arch: HVM64 + r3.4xlarge: + Arch: HVM64 + r3.8xlarge: + Arch: HVM64 + i2.xlarge: + Arch: HVM64 + i2.2xlarge: + Arch: HVM64 + i2.4xlarge: + Arch: HVM64 + i2.8xlarge: + Arch: HVM64 + d2.xlarge: + Arch: HVM64 + d2.2xlarge: + Arch: HVM64 + d2.4xlarge: + Arch: HVM64 + d2.8xlarge: + Arch: HVM64 + hi1.4xlarge: + Arch: HVM64 + hs1.8xlarge: + Arch: HVM64 + cr1.8xlarge: + Arch: HVM64 + cc2.8xlarge: + Arch: HVM64 + + AWSRegionArch2AMI: + us-east-1: + HVM64: ami-05723c3b9cf4bf4ff + us-west-2: + HVM64: ami-0b6ce9bcd0a2f720d + us-west-1: + HVM64: ami-029465c1f346dd34f + eu-west-1: + HVM64: ami-0f11fb3119dc9fc60 + eu-west-2: + HVM64: ami-023cd3f0d10fb8a9c + eu-west-3: + HVM64: ami-0c226b3aa389adbef + eu-central-1: + HVM64: ami-0c0000ceb18c73b8a + ap-northeast-1: + HVM64: ami-083594d506bfbc152 + ap-northeast-2: + HVM64: ami-07cc74f198bb9e86a + ap-northeast-3: + HVM64: ami-0ee7ab88ad9d14d40 + ap-southeast-1: + HVM64: ami-0b2aec26bb1a5169d + ap-southeast-2: + HVM64: ami-003cf7280eac7a28a + ap-south-1: + HVM64: ami-069d9fecd19e7ed40 + us-east-2: + HVM64: ami-08d616b7fbe4bb9d0 + ca-central-1: + HVM64: ami-093dddc44bec52167 + sa-east-1: + HVM64: ami-07509c78b1456cc84 + +Resources: + EC2Instance: + CreationPolicy: + ResourceSignal: + Timeout: PT10M + Count: "1" + Type: AWS::EC2::Instance + Metadata: + AWS::CloudFormation::Init: + configSets: + full_install: + - install_and_enable_cfn_hup + install_and_enable_cfn_hup: + files: + /etc/cfn/cfn-hup.conf: + content: !Sub | + [main] + stack=${AWS::StackId} + region=${AWS::Region} + mode: "000400" + owner: root + group: root + /etc/cfn/hooks.d/cfn-auto-reloader.conf: + content: !Sub | + [cfn-auto-reloader-hook] + triggers=post.update + path=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init + action=/usr/local/bin/cfn-init -v --stack ${AWS::StackName} --resource EC2Instance --configsets full_install --region ${AWS::Region} + runas=root + /lib/systemd/system/cfn-hup.service: + content: | + [Unit] + Description=cfn-hup daemon + + [Service] + Type=simple + ExecStart=/usr/local/bin/cfn-hup + Restart=always + + [Install] + WantedBy=multi-user.target + commands: + 01enable_cfn_hup: + command: systemctl enable cfn-hup.service + 02start_cfn_hup: + command: systemctl start cfn-hup.service + Properties: + InstanceType: !Ref InstanceType + SubnetId: !Ref SubnetId + SecurityGroupIds: + - !GetAtt InstanceSecurityGroup.GroupId + KeyName: !Ref KeyName + ImageId: !FindInMap + - AWSRegionArch2AMI + - !Ref AWS::Region + - !FindInMap + - AWSInstanceType2Arch + - !Ref InstanceType + - Arch + UserData: !Base64 + Fn::Sub: "#!/bin/bash -xe\n\nsudo yum update -y\nsudo yum -y install python3-pip\nsudo pip3 install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz\n/usr/local/bin/cfn-init -v --stack ${AWS::StackName} --resource EC2Instance --configsets full_install --region ${AWS::Region} \n/usr/local/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource EC2Instance --region ${AWS::Region}\n" + + InstanceSecurityGroup: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Enable SSH access via port 22 + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: "22" + ToPort: "22" + CidrIp: !Ref SSHLocation diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/OperatingSystems/Ubuntu22.04_cfn-hup.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/OperatingSystems/Ubuntu22.04_cfn-hup.json new file mode 100644 index 0000000000000000000000000000000000000000..8aced5655617901eae9dee0e55b4f15e57b220e3 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/OperatingSystems/Ubuntu22.04_cfn-hup.json @@ -0,0 +1,179 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "Installing Cloudformation helper scripts in Ubuntu 22.04 LTS", + "Parameters": { + "KeyName": { + "Description": "Name of an existing EC2 KeyPair to enable SSH access to the instance", + "Type": "AWS::EC2::KeyPair::KeyName" + }, + "InstanceType": { + "Description": "WebServer EC2 instance type", + "Type": "String", + "AllowedValues": [ + "t1.micro", + "t2.nano", + "t2.micro", + "t2.small", + "t2.medium", + "t2.large", + "m1.small", + "m1.medium", + "m1.large", + "m1.xlarge", + "m2.xlarge", + "m2.2xlarge", + "m2.4xlarge", + "m3.medium", + "m3.large", + "m3.xlarge", + "m3.2xlarge", + "m4.large", + "m4.xlarge", + "m4.2xlarge", + "m4.4xlarge", + "m4.10xlarge", + "c1.medium", + "c1.xlarge", + "c3.large", + "c3.xlarge", + "c3.2xlarge", + "c3.4xlarge", + "c3.8xlarge", + "c4.large", + "c4.xlarge", + "c4.2xlarge", + "c4.4xlarge", + "c4.8xlarge", + "r3.large", + "r3.xlarge", + "r3.2xlarge", + "r3.4xlarge", + "r3.8xlarge", + "i2.xlarge", + "i2.2xlarge", + "i2.4xlarge", + "i2.8xlarge", + "d2.xlarge", + "d2.2xlarge", + "d2.4xlarge", + "d2.8xlarge", + "hs1.8xlarge", + "cr1.8xlarge", + "cc2.8xlarge" + ], + "Default": "t2.small", + "ConstraintDescription": "must be a valid EC2 instance type." + }, + "SSHLocation": { + "Description": "The IP address range that can be used to SSH to the EC2 instances", + "Type": "String", + "Default": "0.0.0.0/0", + "MinLength": "9", + "MaxLength": "18", + "AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})", + "ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x." + }, + "SubnetId": { + "Type": "AWS::EC2::Subnet::Id" + }, + "InstanceAMI": { + "Description": "Managed AMI ID for EC2 Instance", + "Type": "AWS::SSM::Parameter::Value", + "Default": "/aws/service/canonical/ubuntu/eks-pro/22.04/1.29/stable/current/amd64/hvm/ebs-gp2/ami-id" + } + }, + "Resources": { + "EC2Instance": { + "CreationPolicy": { + "ResourceSignal": { + "Timeout": "PT10M", + "Count": "1" + } + }, + "Type": "AWS::EC2::Instance", + "Metadata": { + "AWS::CloudFormation::Init": { + "configSets": { + "full_install": [ + "install_and_enable_cfn_hup" + ] + }, + "install_and_enable_cfn_hup": { + "files": { + "/etc/cfn/cfn-hup.conf": { + "content": { + "Fn::Sub": "[main]\nstack=${AWS::StackId}\nregion=${AWS::Region}\n" + }, + "mode": "000400", + "owner": "root", + "group": "root" + }, + "/etc/cfn/hooks.d/cfn-auto-reloader.conf": { + "content": { + "Fn::Sub": "[cfn-auto-reloader-hook]\ntriggers=post.update\npath=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init\naction=/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource EC2Instance --configsets InstallAndRun --region ${AWS::Region}\nrunas=root\n" + }, + "mode": "000400", + "owner": "root", + "group": "root" + }, + "/lib/systemd/system/cfn-hup.service": { + "content": "[Unit]\nDescription=cfn-hup daemon\n[Service]\nType=simple\nExecStart=/usr/local/bin/cfn-hup\nRestart=always\n[Install]\nWantedBy=multi-user.target\n" + } + }, + "commands": { + "01enable_cfn_hup": { + "command": "systemctl enable cfn-hup.service" + }, + "02start_cfn_hup": { + "command": "systemctl start cfn-hup.service" + } + } + } + } + }, + "Properties": { + "InstanceType": { + "Ref": "InstanceType" + }, + "SubnetId": { + "Ref": "SubnetId" + }, + "SecurityGroupIds": [ + { + "Fn::GetAtt": [ + "InstanceSecurityGroup", + "GroupId" + ] + } + ], + "KeyName": { + "Ref": "KeyName" + }, + "ImageId": { + "Ref": "InstanceAMI" + }, + "UserData": { + "Fn::Base64": { + "Fn::Sub": "#!/bin/bash -xe\nsudo apt-get update -y\nsudo apt-get -y install python3-pip\nmkdir -p /opt/aws/\nsudo pip3 install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz\nsudo ln -s /usr/local/init/ubuntu/cfn-hup /etc/init.d/cfn-hup\n/usr/local/bin/cfn-init -v --stack ${AWS::StackName} --resource EC2Instance --configsets full_install --region ${AWS::Region}\n/usr/local/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource EC2Instance --region ${AWS::Region}\n" + } + } + } + }, + "InstanceSecurityGroup": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "Enable SSH access via port 22", + "SecurityGroupIngress": [ + { + "IpProtocol": "tcp", + "FromPort": "22", + "ToPort": "22", + "CidrIp": { + "Ref": "SSHLocation" + } + } + ] + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/OperatingSystems/Ubuntu22.04_cfn-hup.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/OperatingSystems/Ubuntu22.04_cfn-hup.yaml new file mode 100644 index 0000000000000000000000000000000000000000..afc7b4353aaa8cb3b99bc520add7e837135e5a67 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/OperatingSystems/Ubuntu22.04_cfn-hup.yaml @@ -0,0 +1,157 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: Installing Cloudformation helper scripts in Ubuntu 22.04 LTS + +Parameters: + KeyName: + Description: Name of an existing EC2 KeyPair to enable SSH access to the instance + Type: AWS::EC2::KeyPair::KeyName + + InstanceType: + Description: WebServer EC2 instance type + Type: String + AllowedValues: + - t1.micro + - t2.nano + - t2.micro + - t2.small + - t2.medium + - t2.large + - m1.small + - m1.medium + - m1.large + - m1.xlarge + - m2.xlarge + - m2.2xlarge + - m2.4xlarge + - m3.medium + - m3.large + - m3.xlarge + - m3.2xlarge + - m4.large + - m4.xlarge + - m4.2xlarge + - m4.4xlarge + - m4.10xlarge + - c1.medium + - c1.xlarge + - c3.large + - c3.xlarge + - c3.2xlarge + - c3.4xlarge + - c3.8xlarge + - c4.large + - c4.xlarge + - c4.2xlarge + - c4.4xlarge + - c4.8xlarge + - r3.large + - r3.xlarge + - r3.2xlarge + - r3.4xlarge + - r3.8xlarge + - i2.xlarge + - i2.2xlarge + - i2.4xlarge + - i2.8xlarge + - d2.xlarge + - d2.2xlarge + - d2.4xlarge + - d2.8xlarge + - hs1.8xlarge + - cr1.8xlarge + - cc2.8xlarge + Default: t2.small + ConstraintDescription: must be a valid EC2 instance type. + + SSHLocation: + Description: The IP address range that can be used to SSH to the EC2 instances + Type: String + Default: 0.0.0.0/0 + MinLength: "9" + MaxLength: "18" + AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2}) + ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x. + + SubnetId: + Type: AWS::EC2::Subnet::Id + + InstanceAMI: + Description: Managed AMI ID for EC2 Instance + Type: AWS::SSM::Parameter::Value + Default: /aws/service/canonical/ubuntu/eks-pro/22.04/1.29/stable/current/amd64/hvm/ebs-gp2/ami-id + +Resources: + EC2Instance: + CreationPolicy: + ResourceSignal: + Timeout: PT10M + Count: "1" + Type: AWS::EC2::Instance + Metadata: + AWS::CloudFormation::Init: + configSets: + full_install: + - install_and_enable_cfn_hup + install_and_enable_cfn_hup: + files: + /etc/cfn/cfn-hup.conf: + content: !Sub | + [main] + stack=${AWS::StackId} + region=${AWS::Region} + mode: "000400" + owner: root + group: root + /etc/cfn/hooks.d/cfn-auto-reloader.conf: + content: !Sub | + [cfn-auto-reloader-hook] + triggers=post.update + path=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init + action=/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource EC2Instance --configsets InstallAndRun --region ${AWS::Region} + runas=root + mode: "000400" + owner: root + group: root + /lib/systemd/system/cfn-hup.service: + content: | + [Unit] + Description=cfn-hup daemon + [Service] + Type=simple + ExecStart=/usr/local/bin/cfn-hup + Restart=always + [Install] + WantedBy=multi-user.target + commands: + 01enable_cfn_hup: + command: systemctl enable cfn-hup.service + 02start_cfn_hup: + command: systemctl start cfn-hup.service + Properties: + InstanceType: !Ref InstanceType + SubnetId: !Ref SubnetId + SecurityGroupIds: + - !GetAtt InstanceSecurityGroup.GroupId + KeyName: !Ref KeyName + ImageId: !Ref InstanceAMI + UserData: !Base64 + Fn::Sub: | + #!/bin/bash -xe + sudo apt-get update -y + sudo apt-get -y install python3-pip + mkdir -p /opt/aws/ + sudo pip3 install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz + sudo ln -s /usr/local/init/ubuntu/cfn-hup /etc/init.d/cfn-hup + /usr/local/bin/cfn-init -v --stack ${AWS::StackName} --resource EC2Instance --configsets full_install --region ${AWS::Region} + /usr/local/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource EC2Instance --region ${AWS::Region} + + InstanceSecurityGroup: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Enable SSH access via port 22 + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: "22" + ToPort: "22" + CidrIp: !Ref SSHLocation diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/OperatingSystems/ubuntu20.04_cfn-hup.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/OperatingSystems/ubuntu20.04_cfn-hup.json new file mode 100644 index 0000000000000000000000000000000000000000..a49a13ec918ca669abcbba5ff5509eab40a44259 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/OperatingSystems/ubuntu20.04_cfn-hup.json @@ -0,0 +1,395 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "Installing Cloudformation helper scripts in Ubuntu 20.04 LTS", + "Parameters": { + "KeyName": { + "Description": "Name of an existing EC2 KeyPair to enable SSH access to the instance", + "Type": "AWS::EC2::KeyPair::KeyName" + }, + "InstanceType": { + "Description": "WebServer EC2 instance type", + "Type": "String", + "AllowedValues": [ + "t1.micro", + "t2.nano", + "t2.micro", + "t2.small", + "t2.medium", + "t2.large", + "m1.small", + "m1.medium", + "m1.large", + "m1.xlarge", + "m2.xlarge", + "m2.2xlarge", + "m2.4xlarge", + "m3.medium", + "m3.large", + "m3.xlarge", + "m3.2xlarge", + "m4.large", + "m4.xlarge", + "m4.2xlarge", + "m4.4xlarge", + "m4.10xlarge", + "c1.medium", + "c1.xlarge", + "c3.large", + "c3.xlarge", + "c3.2xlarge", + "c3.4xlarge", + "c3.8xlarge", + "c4.large", + "c4.xlarge", + "c4.2xlarge", + "c4.4xlarge", + "c4.8xlarge", + "r3.large", + "r3.xlarge", + "r3.2xlarge", + "r3.4xlarge", + "r3.8xlarge", + "i2.xlarge", + "i2.2xlarge", + "i2.4xlarge", + "i2.8xlarge", + "d2.xlarge", + "d2.2xlarge", + "d2.4xlarge", + "d2.8xlarge", + "hs1.8xlarge", + "cr1.8xlarge", + "cc2.8xlarge" + ], + "Default": "t2.small", + "ConstraintDescription": "must be a valid EC2 instance type." + }, + "SSHLocation": { + "Description": "The IP address range that can be used to SSH to the EC2 instances", + "Type": "String", + "Default": "0.0.0.0/0", + "MinLength": "9", + "MaxLength": "18", + "AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})", + "ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x." + }, + "SubnetId": { + "Type": "AWS::EC2::Subnet::Id" + } + }, + "Mappings": { + "AWSInstanceType2Arch": { + "t1.micro": { + "Arch": "HVM64" + }, + "t2.nano": { + "Arch": "HVM64" + }, + "t2.micro": { + "Arch": "HVM64" + }, + "t2.small": { + "Arch": "HVM64" + }, + "t2.medium": { + "Arch": "HVM64" + }, + "t2.large": { + "Arch": "HVM64" + }, + "m1.small": { + "Arch": "HVM64" + }, + "m1.medium": { + "Arch": "HVM64" + }, + "m1.large": { + "Arch": "HVM64" + }, + "m1.xlarge": { + "Arch": "HVM64" + }, + "m2.xlarge": { + "Arch": "HVM64" + }, + "m2.2xlarge": { + "Arch": "HVM64" + }, + "m2.4xlarge": { + "Arch": "HVM64" + }, + "m3.medium": { + "Arch": "HVM64" + }, + "m3.large": { + "Arch": "HVM64" + }, + "m3.xlarge": { + "Arch": "HVM64" + }, + "m3.2xlarge": { + "Arch": "HVM64" + }, + "m4.large": { + "Arch": "HVM64" + }, + "m4.xlarge": { + "Arch": "HVM64" + }, + "m4.2xlarge": { + "Arch": "HVM64" + }, + "m4.4xlarge": { + "Arch": "HVM64" + }, + "m4.10xlarge": { + "Arch": "HVM64" + }, + "c1.medium": { + "Arch": "HVM64" + }, + "c1.xlarge": { + "Arch": "HVM64" + }, + "c3.large": { + "Arch": "HVM64" + }, + "c3.xlarge": { + "Arch": "HVM64" + }, + "c3.2xlarge": { + "Arch": "HVM64" + }, + "c3.4xlarge": { + "Arch": "HVM64" + }, + "c3.8xlarge": { + "Arch": "HVM64" + }, + "c4.large": { + "Arch": "HVM64" + }, + "c4.xlarge": { + "Arch": "HVM64" + }, + "c4.2xlarge": { + "Arch": "HVM64" + }, + "c4.4xlarge": { + "Arch": "HVM64" + }, + "c4.8xlarge": { + "Arch": "HVM64" + }, + "r3.large": { + "Arch": "HVM64" + }, + "r3.xlarge": { + "Arch": "HVM64" + }, + "r3.2xlarge": { + "Arch": "HVM64" + }, + "r3.4xlarge": { + "Arch": "HVM64" + }, + "r3.8xlarge": { + "Arch": "HVM64" + }, + "i2.xlarge": { + "Arch": "HVM64" + }, + "i2.2xlarge": { + "Arch": "HVM64" + }, + "i2.4xlarge": { + "Arch": "HVM64" + }, + "i2.8xlarge": { + "Arch": "HVM64" + }, + "d2.xlarge": { + "Arch": "HVM64" + }, + "d2.2xlarge": { + "Arch": "HVM64" + }, + "d2.4xlarge": { + "Arch": "HVM64" + }, + "d2.8xlarge": { + "Arch": "HVM64" + }, + "hi1.4xlarge": { + "Arch": "HVM64" + }, + "hs1.8xlarge": { + "Arch": "HVM64" + }, + "cr1.8xlarge": { + "Arch": "HVM64" + }, + "cc2.8xlarge": { + "Arch": "HVM64" + } + }, + "AWSRegionArch2AMI": { + "us-east-1": { + "HVM64": "ami-0149b2da6ceec4bb0" + }, + "us-west-2": { + "HVM64": "ami-0c09c7eb16d3e8e70" + }, + "us-west-1": { + "HVM64": "ami-03f6d497fceb40069" + }, + "eu-west-1": { + "HVM64": "ami-0fd8802f94ed1c969" + }, + "eu-west-2": { + "HVM64": "ami-04842bc62789b682e" + }, + "eu-west-3": { + "HVM64": "ami-064736ff8301af3ee" + }, + "eu-central-1": { + "HVM64": "ami-06148e0e81e5187c8" + }, + "ap-northeast-1": { + "HVM64": "ami-09b18720cb71042df" + }, + "ap-northeast-2": { + "HVM64": "ami-07d16c043aa8e5153" + }, + "ap-northeast-3": { + "HVM64": "ami-09d2f3a31110c6ad4" + }, + "ap-southeast-1": { + "HVM64": "ami-00e912d13fbb4f225" + }, + "ap-southeast-2": { + "HVM64": "ami-055166f8a8041fbf1" + }, + "ap-south-1": { + "HVM64": "ami-024c319d5d14b463e" + }, + "us-east-2": { + "HVM64": "ami-0d5bf08bc8017c83b" + }, + "ca-central-1": { + "HVM64": "ami-043a72cf696697251" + }, + "sa-east-1": { + "HVM64": "ami-00742e66d44c13cd9" + } + } + }, + "Resources": { + "EC2Instance": { + "CreationPolicy": { + "ResourceSignal": { + "Timeout": "PT10M", + "Count": "1" + } + }, + "Type": "AWS::EC2::Instance", + "Metadata": { + "AWS::CloudFormation::Init": { + "configSets": { + "full_install": [ + "install_and_enable_cfn_hup" + ] + }, + "install_and_enable_cfn_hup": { + "files": { + "/etc/cfn/cfn-hup.conf": { + "content": { + "Fn::Sub": "[main]\nstack=${AWS::StackId}\nregion=${AWS::Region}\n" + }, + "mode": "000400", + "owner": "root", + "group": "root" + }, + "/etc/cfn/hooks.d/cfn-auto-reloader.conf": { + "content": { + "Fn::Sub": "[cfn-auto-reloader-hook]\ntriggers=post.update\npath=Resources.WebServerInstance.Metadata.AWS::CloudFormation::Init\naction=/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource WebServerInstance --configsets InstallAndRun --region ${AWS::Region}\nrunas=root \n" + }, + "mode": "000400", + "owner": "root", + "group": "root" + }, + "/lib/systemd/system/cfn-hup.service": { + "content": "[Unit]\nDescription=cfn-hup daemon\n[Service]\nType=simple\nExecStart=/usr/local/bin/cfn-hup\nRestart=always\n[Install]\nWantedBy=multi-user.target\n" + } + }, + "commands": { + "01enable_cfn_hup": { + "command": "systemctl enable cfn-hup.service" + }, + "02start_cfn_hup": { + "command": "systemctl start cfn-hup.service" + } + } + } + } + }, + "Properties": { + "InstanceType": { + "Ref": "InstanceType" + }, + "SubnetId": { + "Ref": "SubnetId" + }, + "SecurityGroupIds": [ + { + "Fn::GetAtt": [ + "InstanceSecurityGroup", + "GroupId" + ] + } + ], + "KeyName": { + "Ref": "KeyName" + }, + "ImageId": { + "Fn::FindInMap": [ + "AWSRegionArch2AMI", + { + "Ref": "AWS::Region" + }, + { + "Fn::FindInMap": [ + "AWSInstanceType2Arch", + { + "Ref": "InstanceType" + }, + "Arch" + ] + } + ] + }, + "UserData": { + "Fn::Base64": { + "Fn::Sub": "#!/bin/bash -xe\nsudo apt-get update -y\nsudo apt-get -y install python3-pip\nmkdir -p /opt/aws/\nsudo pip3 install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz\nsudo ln -s /usr/local/init/ubuntu/cfn-hup /etc/init.d/cfn-hup\n/usr/local/bin/cfn-init -v --stack ${AWS::StackName} --resource EC2Instance --configsets full_install --region ${AWS::Region}\n/usr/local/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource EC2Instance --region ${AWS::Region}\n" + } + } + } + }, + "InstanceSecurityGroup": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "Enable SSH access via port 22", + "SecurityGroupIngress": [ + { + "IpProtocol": "tcp", + "FromPort": "22", + "ToPort": "22", + "CidrIp": { + "Ref": "SSHLocation" + } + } + ] + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/OperatingSystems/ubuntu20.04_cfn-hup.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/OperatingSystems/ubuntu20.04_cfn-hup.yaml new file mode 100644 index 0000000000000000000000000000000000000000..88913046a6d679358ed65ed931068fb36deefeb4 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/OperatingSystems/ubuntu20.04_cfn-hup.yaml @@ -0,0 +1,297 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: Installing Cloudformation helper scripts in Ubuntu 20.04 LTS + +Parameters: + KeyName: + Description: Name of an existing EC2 KeyPair to enable SSH access to the instance + Type: AWS::EC2::KeyPair::KeyName + + InstanceType: + Description: WebServer EC2 instance type + Type: String + AllowedValues: + - t1.micro + - t2.nano + - t2.micro + - t2.small + - t2.medium + - t2.large + - m1.small + - m1.medium + - m1.large + - m1.xlarge + - m2.xlarge + - m2.2xlarge + - m2.4xlarge + - m3.medium + - m3.large + - m3.xlarge + - m3.2xlarge + - m4.large + - m4.xlarge + - m4.2xlarge + - m4.4xlarge + - m4.10xlarge + - c1.medium + - c1.xlarge + - c3.large + - c3.xlarge + - c3.2xlarge + - c3.4xlarge + - c3.8xlarge + - c4.large + - c4.xlarge + - c4.2xlarge + - c4.4xlarge + - c4.8xlarge + - r3.large + - r3.xlarge + - r3.2xlarge + - r3.4xlarge + - r3.8xlarge + - i2.xlarge + - i2.2xlarge + - i2.4xlarge + - i2.8xlarge + - d2.xlarge + - d2.2xlarge + - d2.4xlarge + - d2.8xlarge + - hs1.8xlarge + - cr1.8xlarge + - cc2.8xlarge + Default: t2.small + ConstraintDescription: must be a valid EC2 instance type. + + SSHLocation: + Description: The IP address range that can be used to SSH to the EC2 instances + Type: String + Default: 0.0.0.0/0 + MinLength: "9" + MaxLength: "18" + AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2}) + ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x. + + SubnetId: + Type: AWS::EC2::Subnet::Id + +Mappings: + AWSInstanceType2Arch: + t1.micro: + Arch: HVM64 + t2.nano: + Arch: HVM64 + t2.micro: + Arch: HVM64 + t2.small: + Arch: HVM64 + t2.medium: + Arch: HVM64 + t2.large: + Arch: HVM64 + m1.small: + Arch: HVM64 + m1.medium: + Arch: HVM64 + m1.large: + Arch: HVM64 + m1.xlarge: + Arch: HVM64 + m2.xlarge: + Arch: HVM64 + m2.2xlarge: + Arch: HVM64 + m2.4xlarge: + Arch: HVM64 + m3.medium: + Arch: HVM64 + m3.large: + Arch: HVM64 + m3.xlarge: + Arch: HVM64 + m3.2xlarge: + Arch: HVM64 + m4.large: + Arch: HVM64 + m4.xlarge: + Arch: HVM64 + m4.2xlarge: + Arch: HVM64 + m4.4xlarge: + Arch: HVM64 + m4.10xlarge: + Arch: HVM64 + c1.medium: + Arch: HVM64 + c1.xlarge: + Arch: HVM64 + c3.large: + Arch: HVM64 + c3.xlarge: + Arch: HVM64 + c3.2xlarge: + Arch: HVM64 + c3.4xlarge: + Arch: HVM64 + c3.8xlarge: + Arch: HVM64 + c4.large: + Arch: HVM64 + c4.xlarge: + Arch: HVM64 + c4.2xlarge: + Arch: HVM64 + c4.4xlarge: + Arch: HVM64 + c4.8xlarge: + Arch: HVM64 + r3.large: + Arch: HVM64 + r3.xlarge: + Arch: HVM64 + r3.2xlarge: + Arch: HVM64 + r3.4xlarge: + Arch: HVM64 + r3.8xlarge: + Arch: HVM64 + i2.xlarge: + Arch: HVM64 + i2.2xlarge: + Arch: HVM64 + i2.4xlarge: + Arch: HVM64 + i2.8xlarge: + Arch: HVM64 + d2.xlarge: + Arch: HVM64 + d2.2xlarge: + Arch: HVM64 + d2.4xlarge: + Arch: HVM64 + d2.8xlarge: + Arch: HVM64 + hi1.4xlarge: + Arch: HVM64 + hs1.8xlarge: + Arch: HVM64 + cr1.8xlarge: + Arch: HVM64 + cc2.8xlarge: + Arch: HVM64 + + AWSRegionArch2AMI: + us-east-1: + HVM64: ami-0149b2da6ceec4bb0 + us-west-2: + HVM64: ami-0c09c7eb16d3e8e70 + us-west-1: + HVM64: ami-03f6d497fceb40069 + eu-west-1: + HVM64: ami-0fd8802f94ed1c969 + eu-west-2: + HVM64: ami-04842bc62789b682e + eu-west-3: + HVM64: ami-064736ff8301af3ee + eu-central-1: + HVM64: ami-06148e0e81e5187c8 + ap-northeast-1: + HVM64: ami-09b18720cb71042df + ap-northeast-2: + HVM64: ami-07d16c043aa8e5153 + ap-northeast-3: + HVM64: ami-09d2f3a31110c6ad4 + ap-southeast-1: + HVM64: ami-00e912d13fbb4f225 + ap-southeast-2: + HVM64: ami-055166f8a8041fbf1 + ap-south-1: + HVM64: ami-024c319d5d14b463e + us-east-2: + HVM64: ami-0d5bf08bc8017c83b + ca-central-1: + HVM64: ami-043a72cf696697251 + sa-east-1: + HVM64: ami-00742e66d44c13cd9 + +Resources: + EC2Instance: + CreationPolicy: + ResourceSignal: + Timeout: PT10M + Count: "1" + Type: AWS::EC2::Instance + Metadata: + AWS::CloudFormation::Init: + configSets: + full_install: + - install_and_enable_cfn_hup + install_and_enable_cfn_hup: + files: + /etc/cfn/cfn-hup.conf: + content: !Sub | + [main] + stack=${AWS::StackId} + region=${AWS::Region} + mode: "000400" + owner: root + group: root + /etc/cfn/hooks.d/cfn-auto-reloader.conf: + content: !Sub | + [cfn-auto-reloader-hook] + triggers=post.update + path=Resources.WebServerInstance.Metadata.AWS::CloudFormation::Init + action=/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource WebServerInstance --configsets InstallAndRun --region ${AWS::Region} + runas=root + mode: "000400" + owner: root + group: root + /lib/systemd/system/cfn-hup.service: + content: | + [Unit] + Description=cfn-hup daemon + [Service] + Type=simple + ExecStart=/usr/local/bin/cfn-hup + Restart=always + [Install] + WantedBy=multi-user.target + commands: + 01enable_cfn_hup: + command: systemctl enable cfn-hup.service + 02start_cfn_hup: + command: systemctl start cfn-hup.service + Properties: + InstanceType: !Ref InstanceType + SubnetId: !Ref SubnetId + SecurityGroupIds: + - !GetAtt InstanceSecurityGroup.GroupId + KeyName: !Ref KeyName + ImageId: !FindInMap + - AWSRegionArch2AMI + - !Ref AWS::Region + - !FindInMap + - AWSInstanceType2Arch + - !Ref InstanceType + - Arch + UserData: !Base64 + Fn::Sub: | + #!/bin/bash -xe + sudo apt-get update -y + sudo apt-get -y install python3-pip + mkdir -p /opt/aws/ + sudo pip3 install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz + sudo ln -s /usr/local/init/ubuntu/cfn-hup /etc/init.d/cfn-hup + /usr/local/bin/cfn-init -v --stack ${AWS::StackName} --resource EC2Instance --configsets full_install --region ${AWS::Region} + /usr/local/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource EC2Instance --region ${AWS::Region} + + InstanceSecurityGroup: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Enable SSH access via port 22 + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: "22" + ToPort: "22" + CidrIp: !Ref SSHLocation diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/S3CrossAccountReplicationWithKMS/README.md b/human_reference_dataset/aws-cloudformation-templates/Solutions/S3CrossAccountReplicationWithKMS/README.md new file mode 100644 index 0000000000000000000000000000000000000000..5757f6a9b0912613fbbba691a3ffa09c0a3651e0 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/S3CrossAccountReplicationWithKMS/README.md @@ -0,0 +1,40 @@ +# S3 Cross-Account Replication with KMS + +## Description + +Example of cross-account, same-region, S3 bucket replication (v2) using server-side encryption with customer-managed KMS keys. + +![Diagram](./images/s3-replication-diagram.png) + +## Notes + +- The source and destination resources should be deployed to the same region in different AWS Accounts. +- Deploy the destination account resources first. +- The destination S3 bucket must exist before configuring replication on the source bucket. +- CloudFormation stack name: replication-demo +- Source bucket name syntax: {stack-name}-{source-account}-bucket +- Destination bucket name syntax: {stack-name}-{destination-account}-bucket + +## Resources + +- [Amazon S3 - Replicating objects](https://docs.aws.amazon.com/AmazonS3/latest/userguide/replication.html) +- [Changing the replica owner](https://docs.aws.amazon.com/AmazonS3/latest/userguide/replication-change-owner.html) +- [Replicating objects created with server-side encryption (SSE) using KMS keys](https://docs.aws.amazon.com/AmazonS3/latest/userguide/replication-config-for-kms-objects.html) + +## Instructions + +1. The source and destination resources should be deployed to the same region in different AWS Accounts. +1. The CloudFormation stack names must be the same in both accounts. This is because of the resource naming convention used in the example templates. +1. Deploy the destination.yaml template by using CloudFormation in the destination account. The destination S3 bucket must exist before configuring a replication rule on the source bucket. + 1. Name the stack "replication-demo". + 1. Enter the AWS Account Id of the source account in the AccountIdSource parameter. + 1. The destination bucket will be named: replication-demo-{destination-account}-bucket +1. Deploy the source.yml template by using CloudFormation in the source account. + 1. Be sure to select the same region as the destination account resources. + 1. Name the stack "replication-demo". + 1. Enter the AWS Account Id of the destination account in the AccountIdDestination parameter. + 1. The source bucket will be named: replication-demo-{source-account}-bucket + +## Testing + +Upload objects to the source account S3 bucket. After a couple mins, the objects should be replicated to the destination account S3 bucket. diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/S3CrossAccountReplicationWithKMS/images/s3-replication-diagram.png b/human_reference_dataset/aws-cloudformation-templates/Solutions/S3CrossAccountReplicationWithKMS/images/s3-replication-diagram.png new file mode 100644 index 0000000000000000000000000000000000000000..8d790d908644e32ff552e1542df05330dee1185a --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/S3CrossAccountReplicationWithKMS/images/s3-replication-diagram.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1703698608ad2e62b1a1c247fedacac2feb7709dc0232a0700549eac318b32d3 +size 15300 diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/S3CrossAccountReplicationWithKMS/templates/destination.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/S3CrossAccountReplicationWithKMS/templates/destination.json new file mode 100644 index 0000000000000000000000000000000000000000..ffc5fe8dc5b96c80d10e13a5aceaf5264d96cdcd --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/S3CrossAccountReplicationWithKMS/templates/destination.json @@ -0,0 +1,174 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "Example of cross-account, same-region, S3 replication (v2) using server-side encryption with a customer-managed KMS key. Create a symmetric KMS key with an alias, and a destination S3 bucket with default encryption and versioning enabled. Allow the source account access to the destination S3 bucket and KMS key for replication.", + "Parameters": { + "AccountIdSource": { + "Description": "Account Id of the source AWS Account for replication (ie: 123456789012).", + "Type": "String" + } + }, + "Resources": { + "KmsKey": { + "Type": "AWS::KMS::Key", + "Properties": { + "EnableKeyRotation": true, + "KeyPolicy": { + "Version": "2012-10-17", + "Id": { + "Fn::Sub": "${AWS::StackName}-${AWS::AccountId}-key-policy" + }, + "Statement": [ + { + "Sid": "Allow destination account access to KMS key in destination account", + "Effect": "Allow", + "Principal": { + "AWS": { + "Fn::Sub": "arn:${AWS::Partition}:iam::${AWS::AccountId}:root" + } + }, + "Action": "kms:*", + "Resource": "*" + }, + { + "Sid": "Allow source account access to KMS key in destination account", + "Effect": "Allow", + "Principal": { + "AWS": { + "Fn::Sub": "arn:${AWS::Partition}:iam::${AccountIdSource}:root" + } + }, + "Action": [ + "kms:Encrypt", + "kms:ReEncrypt*", + "kms:GenerateDataKey*", + "kms:DescribeKey" + ], + "Resource": "*" + } + ] + } + } + }, + "KmsKeyAlias": { + "Type": "AWS::KMS::Alias", + "Properties": { + "AliasName": { + "Fn::Sub": "alias/${AWS::StackName}-${AWS::AccountId}-kms-key" + }, + "TargetKeyId": { + "Ref": "KmsKey" + } + } + }, + "S3BucketDestination": { + "DeletionPolicy": "Delete", + "Type": "AWS::S3::Bucket", + "Metadata": { + "guard": { + "SuppressedRules": [ + "S3_BUCKET_LOGGING_ENABLED", + "S3_BUCKET_REPLICATION_ENABLED", + "S3_BUCKET_DEFAULT_LOCK_ENABLED" + ] + } + }, + "Properties": { + "BucketName": { + "Fn::Sub": "${AWS::StackName}-${AWS::AccountId}-bucket" + }, + "BucketEncryption": { + "ServerSideEncryptionConfiguration": [ + { + "ServerSideEncryptionByDefault": { + "SSEAlgorithm": "aws:kms", + "KMSMasterKeyID": { + "Ref": "KmsKey" + } + }, + "BucketKeyEnabled": true + } + ] + }, + "PublicAccessBlockConfiguration": { + "BlockPublicAcls": true, + "BlockPublicPolicy": true, + "IgnorePublicAcls": true, + "RestrictPublicBuckets": true + }, + "VersioningConfiguration": { + "Status": "Enabled" + } + } + }, + "S3BucketDestinationPolicy": { + "Type": "AWS::S3::BucketPolicy", + "Properties": { + "Bucket": { + "Ref": "S3BucketDestination" + }, + "PolicyDocument": { + "Id": { + "Fn::Sub": "${AWS::StackName}-${AWS::AccountId}-bucket-policy" + }, + "Version": "2012-10-17", + "Statement": [ + { + "Sid": "Allow source account access to destination bucket", + "Effect": "Allow", + "Principal": { + "AWS": { + "Ref": "AccountIdSource" + } + }, + "Action": [ + "s3:ReplicateDelete", + "s3:ReplicateObject", + "s3:ReplicateTags", + "s3:GetObjectVersionTagging", + "s3:ObjectOwnerOverrideToBucketOwner" + ], + "Resource": { + "Fn::Sub": [ + "${varBucketArn}/*", + { + "varBucketArn": { + "Fn::GetAtt": [ + "S3BucketDestination", + "Arn" + ] + } + } + ] + } + }, + { + "Action": "s3:*", + "Condition": { + "Bool": { + "aws:SecureTransport": false + } + }, + "Effect": "Deny", + "Principal": { + "AWS": "*" + }, + "Resource": { + "Fn::Sub": [ + "${varBucketArn}/*", + { + "varBucketArn": { + "Fn::GetAtt": [ + "S3BucketDestination", + "Arn" + ] + } + } + ] + } + } + ] + } + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/S3CrossAccountReplicationWithKMS/templates/destination.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/S3CrossAccountReplicationWithKMS/templates/destination.yaml new file mode 100644 index 0000000000000000000000000000000000000000..9bb89d5609040994f97af92eefadfd41330e2ea2 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/S3CrossAccountReplicationWithKMS/templates/destination.yaml @@ -0,0 +1,102 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: Example of cross-account, same-region, S3 replication (v2) using server-side encryption with a customer-managed KMS key. Create a symmetric KMS key with an alias, and a destination S3 bucket with default encryption and versioning enabled. Allow the source account access to the destination S3 bucket and KMS key for replication. + +Parameters: + AccountIdSource: + Description: 'Account Id of the source AWS Account for replication (ie: 123456789012).' + Type: String + +Resources: + + # Create a customer managed, symmetric KMS Key used by the destination S3 bucket. + KmsKey: + Type: AWS::KMS::Key + Properties: + EnableKeyRotation: true + KeyPolicy: + Version: "2012-10-17" + Id: !Sub ${AWS::StackName}-${AWS::AccountId}-key-policy + Statement: + - Sid: Allow destination account access to KMS key in destination account + Effect: Allow + Principal: + AWS: !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:root + Action: kms:* + Resource: '*' + - Sid: Allow source account access to KMS key in destination account + Effect: Allow + Principal: + AWS: !Sub arn:${AWS::Partition}:iam::${AccountIdSource}:root + Action: + - kms:Encrypt + - kms:ReEncrypt* + - kms:GenerateDataKey* + - kms:DescribeKey + Resource: '*' + + # Create a KMS Key alias. + KmsKeyAlias: + Type: AWS::KMS::Alias + Properties: + AliasName: !Sub alias/${AWS::StackName}-${AWS::AccountId}-kms-key + TargetKeyId: !Ref KmsKey + + # Create an S3 bucket for the destination of S3 replication. + S3BucketDestination: + DeletionPolicy: Delete + Type: AWS::S3::Bucket + Metadata: + guard: + SuppressedRules: + - S3_BUCKET_LOGGING_ENABLED + - S3_BUCKET_REPLICATION_ENABLED + - S3_BUCKET_DEFAULT_LOCK_ENABLED + Properties: + BucketName: !Sub ${AWS::StackName}-${AWS::AccountId}-bucket + BucketEncryption: + ServerSideEncryptionConfiguration: + - ServerSideEncryptionByDefault: + SSEAlgorithm: aws:kms + KMSMasterKeyID: !Ref KmsKey + BucketKeyEnabled: true + PublicAccessBlockConfiguration: # Public access is not required for replication. + BlockPublicAcls: true + BlockPublicPolicy: true + IgnorePublicAcls: true + RestrictPublicBuckets: true + VersioningConfiguration: # Versioning must be enabled for replication. + Status: Enabled + + # S3 Bucket Policy to allow replication from source account. + S3BucketDestinationPolicy: + Type: AWS::S3::BucketPolicy + Properties: + Bucket: !Ref S3BucketDestination + PolicyDocument: + Id: !Sub ${AWS::StackName}-${AWS::AccountId}-bucket-policy + Version: "2012-10-17" + Statement: + - Sid: Allow source account access to destination bucket + Effect: Allow + Principal: + AWS: !Ref AccountIdSource + Action: + - s3:ReplicateDelete + - s3:ReplicateObject + - s3:ReplicateTags + - s3:GetObjectVersionTagging + - s3:ObjectOwnerOverrideToBucketOwner + Resource: !Sub + - ${varBucketArn}/* + - varBucketArn: !GetAtt S3BucketDestination.Arn + - Action: s3:* + Condition: + Bool: + aws:SecureTransport: false + Effect: Deny + Principal: + AWS: '*' + Resource: !Sub + - ${varBucketArn}/* + - varBucketArn: !GetAtt S3BucketDestination.Arn diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/S3CrossAccountReplicationWithKMS/templates/source.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/S3CrossAccountReplicationWithKMS/templates/source.json new file mode 100644 index 0000000000000000000000000000000000000000..13a119d83c4651f76c2cbe8bbb308f30f4b1791b --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/S3CrossAccountReplicationWithKMS/templates/source.json @@ -0,0 +1,224 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "Example of cross-account, same-region, S3 replication (v2) using server-side encryption with a customer-managed KMS key. Create a symmetric KMS key with an alias, and a source S3 bucket with default encryption and versioning enabled. Create an IAM role, used by a replication rule, to provide access to the source and destination buckets and KMS keys.", + "Parameters": { + "AccountIdDestination": { + "Description": "Account Id of the destination AWS Account for replication (ie: 123456789012).", + "Type": "String" + } + }, + "Resources": { + "KmsKey": { + "Type": "AWS::KMS::Key", + "Properties": { + "EnableKeyRotation": true, + "KeyPolicy": { + "Version": "2012-10-17", + "Id": { + "Fn::Sub": "${AWS::StackName}-${AWS::AccountId}-key-policy" + }, + "Statement": [ + { + "Sid": "Allow source account access to KMS key in source account", + "Effect": "Allow", + "Principal": { + "AWS": { + "Fn::Sub": "arn:${AWS::Partition}:iam::${AWS::AccountId}:root" + } + }, + "Action": "kms:*", + "Resource": "*" + } + ] + } + } + }, + "KmsKeyAlias": { + "Type": "AWS::KMS::Alias", + "Properties": { + "AliasName": { + "Fn::Sub": "alias/${AWS::StackName}-${AWS::AccountId}-kms-key" + }, + "TargetKeyId": { + "Ref": "KmsKey" + } + } + }, + "S3BucketSource": { + "DeletionPolicy": "Delete", + "Type": "AWS::S3::Bucket", + "Metadata": { + "guard": { + "SuppressedRules": [ + "S3_BUCKET_LOGGING_ENABLED", + "S3_BUCKET_REPLICATION_ENABLED", + "S3_BUCKET_DEFAULT_LOCK_ENABLED" + ] + } + }, + "Properties": { + "BucketName": { + "Fn::Sub": "${AWS::StackName}-${AWS::AccountId}-bucket" + }, + "BucketEncryption": { + "ServerSideEncryptionConfiguration": [ + { + "ServerSideEncryptionByDefault": { + "SSEAlgorithm": "aws:kms", + "KMSMasterKeyID": { + "Ref": "KmsKey" + } + }, + "BucketKeyEnabled": true + } + ] + }, + "PublicAccessBlockConfiguration": { + "BlockPublicAcls": true, + "BlockPublicPolicy": true, + "IgnorePublicAcls": true, + "RestrictPublicBuckets": true + }, + "VersioningConfiguration": { + "Status": "Enabled" + }, + "ReplicationConfiguration": { + "Role": { + "Fn::GetAtt": [ + "ReplicationRole", + "Arn" + ] + }, + "Rules": [ + { + "Id": "Rule1", + "Priority": 0, + "Status": "Enabled", + "Destination": { + "Account": { + "Ref": "AccountIdDestination" + }, + "Bucket": { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AWS::StackName}-${AccountIdDestination}-bucket" + }, + "EncryptionConfiguration": { + "ReplicaKmsKeyID": { + "Fn::Sub": "arn:${AWS::Partition}:kms:${AWS::Region}:${AccountIdDestination}:alias/${AWS::StackName}-${AccountIdDestination}-kms-key" + } + }, + "AccessControlTranslation": { + "Owner": "Destination" + } + }, + "Filter": { + "Prefix": "" + }, + "DeleteMarkerReplication": { + "Status": "Disabled" + }, + "SourceSelectionCriteria": { + "SseKmsEncryptedObjects": { + "Status": "Enabled" + } + } + } + ] + } + } + }, + "ReplicationRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "RoleName": { + "Fn::Sub": "${AWS::StackName}-${AccountIdDestination}-role" + }, + "Description": "IAM Role used by S3 bucket replication", + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Principal": { + "Service": "s3.amazonaws.com" + }, + "Action": "sts:AssumeRole" + } + ] + }, + "Policies": [ + { + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-${AccountIdDestination}-role-policy" + }, + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Sid": "AllowActionsOnSourceBucket", + "Action": [ + "s3:ListBucket", + "s3:GetReplicationConfiguration", + "s3:GetObjectVersionForReplication", + "s3:GetObjectVersionAcl" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AWS::StackName}-${AWS::AccountId}-bucket/*" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AWS::StackName}-${AWS::AccountId}-bucket" + } + ] + }, + { + "Sid": "AllowActionsOnDestinationBucket", + "Action": [ + "s3:ReplicateObject", + "s3:ReplicateDelete", + "s3:ReplicateTags", + "s3:GetObjectVersionTagging", + "s3:ObjectOwnerOverrideToBucketOwner" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AWS::StackName}-${AccountIdDestination}-bucket/*" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AWS::StackName}-${AccountIdDestination}-bucket" + } + ] + }, + { + "Sid": "AllowKmsDecryptOnSourceKey", + "Action": "kms:Decrypt", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "KmsKey", + "Arn" + ] + } + }, + { + "Sid": "AllowKmsEncryptOnDestinationKey", + "Action": "kms:Encrypt", + "Effect": "Allow", + "Resource": "*", + "Condition": { + "StringEquals": { + "kms:RequestAlias": { + "Fn::Sub": "alias/${AWS::StackName}-${AccountIdDestination}-kms-key" + } + } + } + } + ] + } + } + ] + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/S3CrossAccountReplicationWithKMS/templates/source.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/S3CrossAccountReplicationWithKMS/templates/source.yaml new file mode 100644 index 0000000000000000000000000000000000000000..25eb539630063518a68a553a13013dece680af5e --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/S3CrossAccountReplicationWithKMS/templates/source.yaml @@ -0,0 +1,128 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: Example of cross-account, same-region, S3 replication (v2) using server-side encryption with a customer-managed KMS key. Create a symmetric KMS key with an alias, and a source S3 bucket with default encryption and versioning enabled. Create an IAM role, used by a replication rule, to provide access to the source and destination buckets and KMS keys. + +Parameters: + AccountIdDestination: + Description: 'Account Id of the destination AWS Account for replication (ie: 123456789012).' + Type: String + +Resources: + + # A customer managed, symmetric KMS Key used by the source S3 bucket. + KmsKey: + Type: AWS::KMS::Key + Properties: + EnableKeyRotation: true + KeyPolicy: + Version: "2012-10-17" + Id: !Sub ${AWS::StackName}-${AWS::AccountId}-key-policy + Statement: + - Sid: Allow source account access to KMS key in source account + Effect: Allow + Principal: + AWS: !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:root + Action: kms:* + Resource: '*' + + KmsKeyAlias: + Type: AWS::KMS::Alias + Properties: + AliasName: !Sub alias/${AWS::StackName}-${AWS::AccountId}-kms-key + TargetKeyId: !Ref KmsKey + + # Create a source S3 bucket with a replication rule. + S3BucketSource: + DeletionPolicy: Delete + Type: AWS::S3::Bucket + Metadata: + guard: + SuppressedRules: + - S3_BUCKET_LOGGING_ENABLED + - S3_BUCKET_REPLICATION_ENABLED + - S3_BUCKET_DEFAULT_LOCK_ENABLED + Properties: + BucketName: !Sub ${AWS::StackName}-${AWS::AccountId}-bucket + BucketEncryption: + ServerSideEncryptionConfiguration: + - ServerSideEncryptionByDefault: + SSEAlgorithm: aws:kms + KMSMasterKeyID: !Ref KmsKey + BucketKeyEnabled: true + PublicAccessBlockConfiguration: # Public access is not required for replication. + BlockPublicAcls: true + BlockPublicPolicy: true + IgnorePublicAcls: true + RestrictPublicBuckets: true + VersioningConfiguration: # Versioning must be enabled for replication. + Status: Enabled + ReplicationConfiguration: + Role: !GetAtt ReplicationRole.Arn + Rules: + - Id: Rule1 + Priority: 0 + Status: Enabled + Destination: + Account: !Ref AccountIdDestination + Bucket: !Sub arn:${AWS::Partition}:s3:::${AWS::StackName}-${AccountIdDestination}-bucket + EncryptionConfiguration: + ReplicaKmsKeyID: !Sub arn:${AWS::Partition}:kms:${AWS::Region}:${AccountIdDestination}:alias/${AWS::StackName}-${AccountIdDestination}-kms-key + AccessControlTranslation: + Owner: Destination + Filter: + Prefix: "" + DeleteMarkerReplication: + Status: Disabled + SourceSelectionCriteria: + SseKmsEncryptedObjects: + Status: Enabled + + ReplicationRole: + Type: AWS::IAM::Role + Properties: + RoleName: !Sub ${AWS::StackName}-${AccountIdDestination}-role + Description: IAM Role used by S3 bucket replication + AssumeRolePolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Principal: + Service: s3.amazonaws.com + Action: sts:AssumeRole + Policies: + - PolicyName: !Sub ${AWS::StackName}-${AccountIdDestination}-role-policy + PolicyDocument: + Version: "2012-10-17" + Statement: + - Sid: AllowActionsOnSourceBucket + Action: + - s3:ListBucket + - s3:GetReplicationConfiguration + - s3:GetObjectVersionForReplication + - s3:GetObjectVersionAcl + Effect: Allow + Resource: + - !Sub arn:${AWS::Partition}:s3:::${AWS::StackName}-${AWS::AccountId}-bucket/* + - !Sub arn:${AWS::Partition}:s3:::${AWS::StackName}-${AWS::AccountId}-bucket + - Sid: AllowActionsOnDestinationBucket + Action: + - s3:ReplicateObject + - s3:ReplicateDelete + - s3:ReplicateTags + - s3:GetObjectVersionTagging + - s3:ObjectOwnerOverrideToBucketOwner + Effect: Allow + Resource: + - !Sub arn:${AWS::Partition}:s3:::${AWS::StackName}-${AccountIdDestination}-bucket/* + - !Sub arn:${AWS::Partition}:s3:::${AWS::StackName}-${AccountIdDestination}-bucket + - Sid: AllowKmsDecryptOnSourceKey + Action: kms:Decrypt + Effect: Allow + Resource: !GetAtt KmsKey.Arn + - Sid: AllowKmsEncryptOnDestinationKey + Action: kms:Encrypt + Effect: Allow + Resource: '*' + Condition: + StringEquals: + kms:RequestAlias: !Sub alias/${AWS::StackName}-${AccountIdDestination}-kms-key diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/TaggingRootVolumesInEC2/README.md b/human_reference_dataset/aws-cloudformation-templates/Solutions/TaggingRootVolumesInEC2/README.md new file mode 100644 index 0000000000000000000000000000000000000000..9a7bc5d899364aaf8cf9cf4a5f4362d5e1772939 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/TaggingRootVolumesInEC2/README.md @@ -0,0 +1,24 @@ +# Tag the EBS Root Volume through a CloudFormation Template. For Both Windows and Linux Systems + +CloudFormation template that will create a Linux and Windows Instance which will then tag the root volume of these instances. + +Template will invoke the following: + - Create a Windows and Linux EC2 Instance. + - The Template will use the UserData property of the EC2 Instance resource to tag the root volume. + - This is done through the AWS CLI commands which at base will tag the root volume with "--tags Key=MyRootTag,Value=MyRootVolumesValue" for the Windows and Linux AMIs. + - If the Windows AMI you are trying to utilize does not have the AWS CLI installed you can still utilize the base Windows commands within the template (This is the uncommented section of the Windows Instance). + - Create an IAM role to attach to the Instances which will give them permissions to tag the root volumes created. + +To Create the instances you can either utilize the AWS CLI command (Where the parameters will be needed to alter for your specific use case): + +```aws cloudformation create-stack --stack-name TaggingVolumes --template-body file://Tagging_Root_volume.json --parameters ParameterKey=KeyName,ParameterValue=TestKey ParameterKey=InstanceType,ParameterValue=t2.micro ParameterKey=InstanceAZ,ParameterValue=eu-west-1 ParameterKey=WindowsAMIID,ParameterValue=ami-0d138b26f46625e2f ParameterKey=LinuxAMIID,ParameterValue=ami-0fad7378adf284ce0``` + +If you do not wish to utilize the CLI you can also create the template through the Console by: + 1) Navigate to the CloudFormation console - https://console.aws.amazon.com/cloudformation/home + 2) Choose Create Stack, and then choose Design template. + 3) At the bottom of the page, choose the Template tab. + 4) Copy the sample template the portion which will alter depending on the operating system and different tagging options you use is the UserData property. + 5) Choose the Create stack icon, choose Next, and type a name for your CloudFormation Stack. + 6) For Parameters, enter the values such as the SSH keyname pair you wish to use, the InstanceType you want the instance to be and most importantly the AMI to be used (Please note that the default being used is for the eu-west-1 region). + 7) Choose Next, and then choose Next again. + 8) Just before the Create Stack option you will need to tick a box to confirm that the CloudFormation stack could create an IAM resource, for example the IAM role assigned to the instances. diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/TaggingRootVolumesInEC2/Tagging_Root_volume.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/TaggingRootVolumesInEC2/Tagging_Root_volume.json new file mode 100644 index 0000000000000000000000000000000000000000..bb37137d415ef0b2ea95eb98d3f3a57354f53941 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/TaggingRootVolumesInEC2/Tagging_Root_volume.json @@ -0,0 +1,211 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "AWS CloudFormation Sample Template Tagging Root Volumes of EC2 Instances: This template shows how to automatically tag the root volume of the EC2 instances which are created through the CloudFormation template. This is done through the UserData property of the AWS::EC2::Instance resource. **WARNING** This template creates two Amazon EC2 instances and an IAM Role. You will be billed for the AWS resources used if you create a stack from this template.", + "Parameters": { + "KeyName": { + "Description": "Name of an existing EC2 KeyPair to enable SSH access to the ECS instances.", + "Type": "AWS::EC2::KeyPair::KeyName" + }, + "InstanceType": { + "Description": "EC2 instance type", + "Type": "String", + "AllowedValues": [ + "t2.micro", + "t2.small", + "t2.medium", + "t2.large", + "m3.medium", + "m3.large", + "m3.xlarge", + "m3.2xlarge", + "m4.large", + "m4.xlarge", + "m4.2xlarge", + "m4.4xlarge", + "m4.10xlarge", + "c4.large", + "c4.xlarge", + "c4.2xlarge", + "c4.4xlarge", + "c4.8xlarge", + "c3.large", + "c3.xlarge", + "c3.2xlarge", + "c3.4xlarge", + "c3.8xlarge", + "r3.large", + "r3.xlarge", + "r3.2xlarge", + "r3.4xlarge", + "r3.8xlarge", + "i2.xlarge", + "i2.2xlarge", + "i2.4xlarge", + "i2.8xlarge" + ], + "Default": "t2.micro", + "ConstraintDescription": "Please choose a valid instance type." + }, + "InstanceAZ": { + "Description": "EC2 AZ.", + "Type": "AWS::EC2::AvailabilityZone::Name", + "ConstraintDescription": "Must be the name of an availabity zone." + }, + "WindowsAMIID": { + "Description": "The Latest Windows 2016 AMI taken from the public Systems Manager Parameter Store", + "Type": "AWS::SSM::Parameter::Value", + "Default": "/aws/service/ami-windows-latest/Windows_Server-2016-English-Full-Base" + }, + "LinuxAMIID": { + "Description": "The Latest Amazon Linux 2 AMI taken from the public Systems Manager Parameter Store", + "Type": "AWS::SSM::Parameter::Value", + "Default": "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2" + }, + "SubnetId": { + "Type": "AWS::EC2::Subnet::Id" + } + }, + "Resources": { + "WindowsInstance": { + "Type": "AWS::EC2::Instance", + "Properties": { + "ImageId": { + "Ref": "WindowsAMIID" + }, + "SubnetId": { + "Ref": "SubnetId" + }, + "InstanceType": { + "Ref": "InstanceType" + }, + "AvailabilityZone": { + "Ref": "InstanceAZ" + }, + "IamInstanceProfile": { + "Ref": "InstanceProfile" + }, + "KeyName": { + "Ref": "KeyName" + }, + "UserData": { + "Fn::Base64": "\n $AWS_AVAIL_ZONE=(curl http://169.254.169.254/latest/meta-data/placement/availability-zone).Content\n $AWS_REGION=$AWS_AVAIL_ZONE.Substring(0,$AWS_AVAIL_ZONE.length-1)\n $AWS_INSTANCE_ID=(curl http://169.254.169.254/latest/meta-data/instance-id).Content\n $ROOT_VOLUME_IDS=((Get-EC2Instance -Region $AWS_REGION -InstanceId $AWS_INSTANCE_ID).Instances.BlockDeviceMappings | where-object DeviceName -match '/dev/sda1').Ebs.VolumeId\n $tag = New-Object Amazon.EC2.Model.Tag\n $tag.key = \"MyRootTag\"\n $tag.value = \"MyRootVolumesValue\"\n New-EC2Tag -Resource $ROOT_VOLUME_IDS -Region $AWS_REGION -Tag $tag\n\n" + }, + "Tags": [ + { + "Key": "Name", + "Value": { + "Ref": "AWS::StackName" + } + } + ], + "BlockDeviceMappings": [ + { + "DeviceName": "/dev/sdm", + "Ebs": { + "VolumeType": "io1", + "Iops": "200", + "DeleteOnTermination": "true", + "VolumeSize": "10" + } + } + ] + } + }, + "LinuxInstance": { + "Type": "AWS::EC2::Instance", + "Properties": { + "ImageId": { + "Ref": "LinuxAMIID" + }, + "SubnetId": { + "Ref": "SubnetId" + }, + "InstanceType": { + "Ref": "InstanceType" + }, + "AvailabilityZone": { + "Ref": "InstanceAZ" + }, + "IamInstanceProfile": { + "Ref": "InstanceProfile" + }, + "KeyName": { + "Ref": "KeyName" + }, + "UserData": { + "Fn::Base64": "AWS_AVAIL_ZONE=$(curl http://169.254.169.254/latest/meta-data/placement/availability-zone)\nAWS_REGION=\"`echo \\\"$AWS_AVAIL_ZONE\\\" | sed 's/[a-z]$//'`\"\nAWS_INSTANCE_ID=$(curl http://169.254.169.254/latest/meta-data/instance-id)\nROOT_VOLUME_IDS=$(aws ec2 describe-instances --region $AWS_REGION --instance-id $AWS_INSTANCE_ID --output text --query Reservations[0].Instances[0].BlockDeviceMappings[0].Ebs.VolumeId)\naws ec2 create-tags --resources $ROOT_VOLUME_IDS --region $AWS_REGION --tags Key=MyRootTag,Value=MyRootVolumesValue\n" + }, + "Tags": [ + { + "Key": "Name", + "Value": { + "Ref": "AWS::StackName" + } + } + ], + "BlockDeviceMappings": [ + { + "DeviceName": "/dev/sdm", + "Ebs": { + "VolumeType": "io1", + "Iops": "200", + "DeleteOnTermination": "true", + "VolumeSize": "10" + } + } + ] + } + }, + "InstanceRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Principal": { + "Service": [ + "ec2.amazonaws.com" + ] + }, + "Action": [ + "sts:AssumeRole" + ] + } + ] + }, + "Path": "/", + "Policies": [ + { + "PolicyName": "taginstancepolicy", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "ec2:Describe*", + "ec2:CreateTags" + ], + "Resource": "*" + } + ] + } + } + ] + } + }, + "InstanceProfile": { + "Type": "AWS::IAM::InstanceProfile", + "Properties": { + "Path": "/", + "Roles": [ + { + "Ref": "InstanceRole" + } + ] + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/TaggingRootVolumesInEC2/Tagging_Root_volume.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/TaggingRootVolumesInEC2/Tagging_Root_volume.yaml new file mode 100644 index 0000000000000000000000000000000000000000..37d8d014edf09068f54ad2de75df9e8f042dd84e --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/TaggingRootVolumesInEC2/Tagging_Root_volume.yaml @@ -0,0 +1,154 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: 'AWS CloudFormation Sample Template Tagging Root Volumes of EC2 Instances: This template shows how to automatically tag the root volume of the EC2 instances which are created through the CloudFormation template. This is done through the UserData property of the AWS::EC2::Instance resource. **WARNING** This template creates two Amazon EC2 instances and an IAM Role. You will be billed for the AWS resources used if you create a stack from this template.' + +Parameters: + KeyName: + Description: Name of an existing EC2 KeyPair to enable SSH access to the ECS instances. + Type: AWS::EC2::KeyPair::KeyName + + InstanceType: + Description: EC2 instance type + Type: String + AllowedValues: + - t2.micro + - t2.small + - t2.medium + - t2.large + - m3.medium + - m3.large + - m3.xlarge + - m3.2xlarge + - m4.large + - m4.xlarge + - m4.2xlarge + - m4.4xlarge + - m4.10xlarge + - c4.large + - c4.xlarge + - c4.2xlarge + - c4.4xlarge + - c4.8xlarge + - c3.large + - c3.xlarge + - c3.2xlarge + - c3.4xlarge + - c3.8xlarge + - r3.large + - r3.xlarge + - r3.2xlarge + - r3.4xlarge + - r3.8xlarge + - i2.xlarge + - i2.2xlarge + - i2.4xlarge + - i2.8xlarge + Default: t2.micro + ConstraintDescription: Please choose a valid instance type. + + InstanceAZ: + Description: EC2 AZ. + Type: AWS::EC2::AvailabilityZone::Name + ConstraintDescription: Must be the name of an availabity zone. + + WindowsAMIID: + Description: The Latest Windows 2016 AMI taken from the public Systems Manager Parameter Store + Type: AWS::SSM::Parameter::Value + Default: /aws/service/ami-windows-latest/Windows_Server-2016-English-Full-Base + + LinuxAMIID: + Description: The Latest Amazon Linux 2 AMI taken from the public Systems Manager Parameter Store + Type: AWS::SSM::Parameter::Value + Default: /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2 + + SubnetId: + Type: AWS::EC2::Subnet::Id + +Resources: + WindowsInstance: + Type: AWS::EC2::Instance + Properties: + ImageId: !Ref WindowsAMIID + SubnetId: !Ref SubnetId + InstanceType: !Ref InstanceType + AvailabilityZone: !Ref InstanceAZ + IamInstanceProfile: !Ref InstanceProfile + KeyName: !Ref KeyName + UserData: !Base64 | + + $AWS_AVAIL_ZONE=(curl http://169.254.169.254/latest/meta-data/placement/availability-zone).Content + $AWS_REGION=$AWS_AVAIL_ZONE.Substring(0,$AWS_AVAIL_ZONE.length-1) + $AWS_INSTANCE_ID=(curl http://169.254.169.254/latest/meta-data/instance-id).Content + $ROOT_VOLUME_IDS=((Get-EC2Instance -Region $AWS_REGION -InstanceId $AWS_INSTANCE_ID).Instances.BlockDeviceMappings | where-object DeviceName -match '/dev/sda1').Ebs.VolumeId + $tag = New-Object Amazon.EC2.Model.Tag + $tag.key = "MyRootTag" + $tag.value = "MyRootVolumesValue" + New-EC2Tag -Resource $ROOT_VOLUME_IDS -Region $AWS_REGION -Tag $tag + + Tags: + - Key: Name + Value: !Ref AWS::StackName + BlockDeviceMappings: + - DeviceName: /dev/sdm + Ebs: + VolumeType: io1 + Iops: "200" + DeleteOnTermination: "true" + VolumeSize: "10" + + LinuxInstance: + Type: AWS::EC2::Instance + Properties: + ImageId: !Ref LinuxAMIID + SubnetId: !Ref SubnetId + InstanceType: !Ref InstanceType + AvailabilityZone: !Ref InstanceAZ + IamInstanceProfile: !Ref InstanceProfile + KeyName: !Ref KeyName + UserData: !Base64 | + AWS_AVAIL_ZONE=$(curl http://169.254.169.254/latest/meta-data/placement/availability-zone) + AWS_REGION="`echo \"$AWS_AVAIL_ZONE\" | sed 's/[a-z]$//'`" + AWS_INSTANCE_ID=$(curl http://169.254.169.254/latest/meta-data/instance-id) + ROOT_VOLUME_IDS=$(aws ec2 describe-instances --region $AWS_REGION --instance-id $AWS_INSTANCE_ID --output text --query Reservations[0].Instances[0].BlockDeviceMappings[0].Ebs.VolumeId) + aws ec2 create-tags --resources $ROOT_VOLUME_IDS --region $AWS_REGION --tags Key=MyRootTag,Value=MyRootVolumesValue + Tags: + - Key: Name + Value: !Ref AWS::StackName + BlockDeviceMappings: + - DeviceName: /dev/sdm + Ebs: + VolumeType: io1 + Iops: "200" + DeleteOnTermination: "true" + VolumeSize: "10" + + InstanceRole: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Principal: + Service: + - ec2.amazonaws.com + Action: + - sts:AssumeRole + Path: / + Policies: + - PolicyName: taginstancepolicy + PolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: + - ec2:Describe* + - ec2:CreateTags + Resource: '*' + + InstanceProfile: + Type: AWS::IAM::InstanceProfile + Properties: + Path: / + Roles: + - !Ref InstanceRole diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCFlowLogs/README.md b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCFlowLogs/README.md new file mode 100644 index 0000000000000000000000000000000000000000..09d6e7f2ea6003163998b116efa8aa86edf3504e --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCFlowLogs/README.md @@ -0,0 +1,33 @@ +# VPCFlowLogs + +This solution lets you enable Flow Logs for a VPC, and publish the flow log data to either Amazon CloudWatch Logs, Amazon S3, or both. + +This solution can be implemented as individual templates accordingly, or leveraging the nested stacks `main` templates. + +## Notes + +- VPC flow log settings are parameterized, so they can be customized as needed. +- Supports publishing VPC flow log data to `Amazon S3` using an existing S3 bucket, or having a new S3 bucket created with encryption. + - Amazon S3 bucket using Amazon managed server-side encryption. Optionally, a KMS CMK can be used. + - If using a KMS CMK, an option is provided to enable the use of an + [Amazon S3 Bucket Key](https://docs.aws.amazon.com/AmazonS3/latest/user-guide/enable-bucket-key.html). +- Supports publishing VPC flow log data to `Amazon CloudWatch Logs` + - Lets you set the log retention for the log group being used for VPC flow logs. + - CloudWatch Logs Log Group uses Amazon managed server-side encryption. Optionally, a KMS CMK can be used. + +## Resources + +- [Publishing flow logs to CloudWatch Logs](https://docs.aws.amazon.com/vpc/latest/userguide/flow-logs-cwl.html) +- [Publishing flow logs to Amazon S3](https://docs.aws.amazon.com/vpc/latest/userguide/flow-logs-s3.html) + +## Instructions (Individual Stacks) + +1. Launch the AWS CloudFormation stack using the [VPCFlowLogsCloudWatch.cfn.yaml](templates/VPCFlowLogsCloudWatch.cfn.yaml) template file as the + source, to publish logs to Amazon CloudWatch Logs. +2. Launch the AWS CloudFormation stack using the [VPCFlowLogsS3.cfn.yaml](templates/VPCFlowLogsS3.cfn.yaml) template file as the source, to publish + logs to Amazon S3. + +## Instructions (Nested Stacks) + +1. Launch the AWS CloudFormation root stack using the [VPCFlowLogs-main.cfn.yaml](templates/VPCFlowLogs-main.cfn.yaml) template file as the source, to + publish logs to Amazon CloudWatch Logs and/or Amazon S3. diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCFlowLogs/templates/VPCFlowLogs-main.cfn.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCFlowLogs/templates/VPCFlowLogs-main.cfn.json new file mode 100644 index 0000000000000000000000000000000000000000..dbf8e3625cf5063c85bfeb86e3aed86c24cfcfad --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCFlowLogs/templates/VPCFlowLogs-main.cfn.json @@ -0,0 +1,332 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "This template enables VPC Flow Logs to CloudWatch, S3, or both.", + "Metadata": { + "AWS::CloudFormation::Interface": { + "ParameterGroups": [ + { + "Label": { + "default": "Network Configuration" + }, + "Parameters": [ + "VPCID" + ] + }, + { + "Label": { + "default": "VPC Flow Logs Configuration" + }, + "Parameters": [ + "VPCFlowLogsLogFormat", + "VPCFlowLogsMaxAggregationInterval", + "VPCFlowLogsTrafficType" + ] + }, + { + "Label": { + "default": "VPC Flow Logs to CloudWatch Configuration" + }, + "Parameters": [ + "CreateVPCFlowLogsToCloudWatch", + "VPCFlowLogsLogGroupRetention", + "VPCFlowLogsCloudWatchKMSKey" + ] + }, + { + "Label": { + "default": "VPC Flow Logs to S3 Configuration" + }, + "Parameters": [ + "CreateVPCFlowLogsToS3", + "VPCFlowLogsBucketName", + "VPCFlowLogsBucketKMSKey", + "VPCFlowLogsBucketKeyEnabled", + "S3AccessLogsBucketName" + ] + }, + { + "Label": { + "default": "Templates Configuration" + }, + "Parameters": [ + "TemplatesS3BucketName", + "TemplatesS3BucketRegion" + ] + } + ], + "ParameterLabels": { + "CreateVPCFlowLogsToCloudWatch": { + "default": "Create VPC Flow Logs (CloudWatch)" + }, + "CreateVPCFlowLogsToS3": { + "default": "Create VPC Flow Logs (S3)" + }, + "S3AccessLogsBucketName": { + "default": "S3 Access Logs Bucket Name" + }, + "TemplatesS3BucketName": { + "default": "Templates S3 Bucket Name" + }, + "TemplatesS3BucketRegion": { + "default": "Templates S3 Bucket Region" + }, + "VPCFlowLogsBucketKeyEnabled": { + "default": "VPC Flow Logs Bucket Key Enabled" + }, + "VPCFlowLogsBucketKMSKey": { + "default": "VPC Flow Logs Bucket KMS Key" + }, + "VPCFlowLogsBucketName": { + "default": "VPC Flow Logs Bucket Name" + }, + "VPCFlowLogsCloudWatchKMSKey": { + "default": "CloudWatch Logs KMS Key for VPC flow logs" + }, + "VPCFlowLogsLogFormat": { + "default": "VPC Flow Logs - Log Format" + }, + "VPCFlowLogsLogGroupRetention": { + "default": "CloudWatch log retention days for VPC flow logs" + }, + "VPCFlowLogsMaxAggregationInterval": { + "default": "VPC Flow Logs - Max Aggregation Interval" + }, + "VPCFlowLogsTrafficType": { + "default": "VPC Flow Logs - Traffic Type" + }, + "VPCID": { + "default": "VPC ID" + } + } + } + }, + "Parameters": { + "CreateVPCFlowLogsToCloudWatch": { + "Description": "Create VPC flow logs for the VPC and publish them to CloudWatch", + "Type": "String", + "AllowedValues": [ + "Yes", + "No" + ], + "Default": "No" + }, + "CreateVPCFlowLogsToS3": { + "Description": "Create VPC flow logs for the VPC and publish them to S3", + "Type": "String", + "AllowedValues": [ + "Yes", + "No" + ], + "Default": "No" + }, + "S3AccessLogsBucketName": { + "Description": "(Optional) S3 Server Access Logs bucket name for where Amazon S3 should store server access log files. S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-). If empty, a new S3 bucket will be created as a destination for S3 server access logs, it will follow the format, aws-s3-access-logs--", + "Type": "String", + "AllowedPattern": "^$|^(?=^.{3,63}$)(?!.*[.-]{2})(?!.*[--]{2})(?!^(?:(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\\.(?!$)|$)){4}$)(^(([a-z0-9]|[a-z0-9][a-z0-9\\-]*[a-z0-9])\\.)*([a-z0-9]|[a-z0-9][a-z0-9\\-]*[a-z0-9])$)", + "ConstraintDescription": "S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-)." + }, + "TemplatesS3BucketName": { + "Description": "Templates S3 bucket name for the CloudFormation templates. S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-).", + "Type": "String", + "AllowedPattern": "^(?=^.{3,63}$)(?!.*[.-]{2})(?!.*[--]{2})(?!^(?:(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\\.(?!$)|$)){4}$)(^(([a-z0-9]|[a-z0-9][a-z0-9\\-]*[a-z0-9])\\.)*([a-z0-9]|[a-z0-9][a-z0-9\\-]*[a-z0-9])$)", + "ConstraintDescription": "Templates S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-)." + }, + "TemplatesS3BucketRegion": { + "Description": "The AWS Region where the Templates S3 bucket (TemplatesS3BucketName) is hosted.", + "Type": "String" + }, + "VPCFlowLogsBucketKeyEnabled": { + "Description": "Set to true to have Amazon S3 use an S3 Bucket Key with server-side encryption using KMS (SSE-KMS). If false, S3 Bucket Key is not enabled. Note, will only be set if KMS Key parameter, \"VPCFlowLogsBucketKMSKey\", was provided.", + "Type": "String", + "AllowedValues": [ + true, + false + ], + "Default": false + }, + "VPCFlowLogsBucketKMSKey": { + "Description": "(Optional) KMS Key ID or ARN to use for the default encryption. If empty, server-side encryption with Amazon S3-managed encryption keys (SSE-S3) will be used. Note, will only be set if S3 Bucket parameter, \"VPCFlowLogsBucketName\", was not provided, thus a new S3 bucket is being created.", + "Type": "String", + "AllowedPattern": "^$|^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$|^arn:(aws[a-zA-Z-]*)?:kms:[a-z0-9-]+:\\d{12}:key\\/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$", + "ConstraintDescription": "Key ID example: 1234abcd-12ab-34cd-56ef-1234567890ab Key ARN examlpe: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab" + }, + "VPCFlowLogsBucketName": { + "Description": "(Optional) S3 bucket name where VPC Flow Log data can be published. S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-). If empty, a new S3 bucket will be created for VPC Flow Log data to be published.", + "Type": "String", + "AllowedPattern": "^$|^(?=^.{3,63}$)(?!.*[.-]{2})(?!.*[--]{2})(?!^(?:(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\\.(?!$)|$)){4}$)(^(([a-z0-9]|[a-z0-9][a-z0-9\\-]*[a-z0-9])\\.)*([a-z0-9]|[a-z0-9][a-z0-9\\-]*[a-z0-9])$)", + "ConstraintDescription": "S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-)." + }, + "VPCFlowLogsCloudWatchKMSKey": { + "Description": "(Optional) KMS Key ARN to use for encrypting the VPC flow logs data. If empty, encryption is enabled with CloudWatch Logs managing the server-side encryption keys.", + "Type": "String", + "AllowedPattern": "^$|^arn:(aws[a-zA-Z-]*)?:kms:[a-z0-9-]+:\\d{12}:key\\/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$", + "ConstraintDescription": "Key ARN example: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab" + }, + "VPCFlowLogsLogFormat": { + "Description": "The fields to include in the flow log record, in the order in which they should appear. Specify the fields using the ${field-id} format, separated by spaces. Using the Default Format as the default value.", + "Type": "String", + "Default": "${version} ${account-id} ${interface-id} ${srcaddr} ${dstaddr} ${srcport} ${dstport} ${protocol} ${packets} ${bytes} ${start} ${end} ${action} ${log-status}", + "AllowedPattern": "^(\\$\\{[a-z-]+\\})$|^((\\$\\{[a-z-]+\\} )*\\$\\{[a-z-]+\\})$" + }, + "VPCFlowLogsLogGroupRetention": { + "Description": "Number of days to retain the VPC Flow Logs in CloudWatch", + "Type": "String", + "AllowedValues": [ + 1, + 3, + 5, + 7, + 14, + 30, + 60, + 90, + 120, + 150, + 180, + 365, + 400, + 545, + 731, + 1827, + 3653 + ], + "Default": 14 + }, + "VPCFlowLogsMaxAggregationInterval": { + "Description": "The maximum interval of time during which a flow of packets is captured and aggregated into a flow log record. You can specify 60 seconds (1 minute) or 600 seconds (10 minutes).", + "Type": "String", + "AllowedValues": [ + 60, + 600 + ], + "Default": 600 + }, + "VPCFlowLogsTrafficType": { + "Description": "The type of traffic to log. You can log traffic that the resource accepts or rejects, or all traffic.", + "Type": "String", + "AllowedValues": [ + "ACCEPT", + "ALL", + "REJECT" + ], + "Default": "REJECT" + }, + "VPCID": { + "Description": "ID of the VPC (e.g., vpc-0343606e)", + "Type": "AWS::EC2::VPC::Id" + } + }, + "Rules": { + "CreateVPCFlowLogs": { + "Assertions": [ + { + "Assert": { + "Fn::Or": [ + { + "Fn::Equals": [ + { + "Ref": "CreateVPCFlowLogsToCloudWatch" + }, + "Yes" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "CreateVPCFlowLogsToS3" + }, + "Yes" + ] + } + ] + }, + "AssertDescription": "To create VPC Flow Logs, you must have AWS CloudFormation parameters, 'CreateVPCFlowLogsToCloudWatch' and/or 'CreateVPCFlowLogsToS3' set to 'Yes'" + } + ] + } + }, + "Conditions": { + "VPCFlowLogsToCloudWatchCondition": { + "Fn::Equals": [ + { + "Ref": "CreateVPCFlowLogsToCloudWatch" + }, + "Yes" + ] + }, + "VPCFlowLogsToS3Condition": { + "Fn::Equals": [ + { + "Ref": "CreateVPCFlowLogsToS3" + }, + "Yes" + ] + } + }, + "Resources": { + "VPCFlowLogsCloudWatchStack": { + "Type": "AWS::CloudFormation::Stack", + "Properties": { + "TemplateURL": { + "Fn::Sub": "https://${TemplatesS3BucketName}.s3.${TemplatesS3BucketRegion}.${AWS::URLSuffix}/templates/VPCFlowLogsCloudWatch.cfn.yaml" + }, + "Parameters": { + "VPCFlowLogsCloudWatchKMSKey": { + "Ref": "VPCFlowLogsCloudWatchKMSKey" + }, + "VPCFlowLogsLogFormat": { + "Ref": "VPCFlowLogsLogFormat" + }, + "VPCFlowLogsLogGroupRetention": { + "Ref": "VPCFlowLogsLogGroupRetention" + }, + "VPCFlowLogsMaxAggregationInterval": { + "Ref": "VPCFlowLogsMaxAggregationInterval" + }, + "VPCFlowLogsTrafficType": { + "Ref": "VPCFlowLogsTrafficType" + }, + "VPCID": { + "Ref": "VPCID" + } + } + }, + "Condition": "VPCFlowLogsToCloudWatchCondition" + }, + "VPCFlowLogsS3Stack": { + "Type": "AWS::CloudFormation::Stack", + "Properties": { + "TemplateURL": { + "Fn::Sub": "https://${TemplatesS3BucketName}.s3.${TemplatesS3BucketRegion}.${AWS::URLSuffix}/templates/VPCFlowLogsS3.cfn.yaml" + }, + "Parameters": { + "S3AccessLogsBucketName": { + "Ref": "S3AccessLogsBucketName" + }, + "VPCFlowLogsBucketKeyEnabled": { + "Ref": "VPCFlowLogsBucketKeyEnabled" + }, + "VPCFlowLogsBucketKMSKey": { + "Ref": "VPCFlowLogsBucketKMSKey" + }, + "VPCFlowLogsBucketName": { + "Ref": "VPCFlowLogsBucketName" + }, + "VPCFlowLogsLogFormat": { + "Ref": "VPCFlowLogsLogFormat" + }, + "VPCFlowLogsMaxAggregationInterval": { + "Ref": "VPCFlowLogsMaxAggregationInterval" + }, + "VPCFlowLogsTrafficType": { + "Ref": "VPCFlowLogsTrafficType" + }, + "VPCID": { + "Ref": "VPCID" + } + } + }, + "Condition": "VPCFlowLogsToS3Condition" + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCFlowLogs/templates/VPCFlowLogs-main.cfn.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCFlowLogs/templates/VPCFlowLogs-main.cfn.yaml new file mode 100644 index 0000000000000000000000000000000000000000..4f100e348caacb9de18293ec30b8afe12f55dc79 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCFlowLogs/templates/VPCFlowLogs-main.cfn.yaml @@ -0,0 +1,224 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: This template enables VPC Flow Logs to CloudWatch, S3, or both. + +Metadata: + AWS::CloudFormation::Interface: + ParameterGroups: + - Label: + default: Network Configuration + Parameters: + - VPCID + - Label: + default: VPC Flow Logs Configuration + Parameters: + - VPCFlowLogsLogFormat + - VPCFlowLogsMaxAggregationInterval + - VPCFlowLogsTrafficType + - Label: + default: VPC Flow Logs to CloudWatch Configuration + Parameters: + - CreateVPCFlowLogsToCloudWatch + - VPCFlowLogsLogGroupRetention + - VPCFlowLogsCloudWatchKMSKey + - Label: + default: VPC Flow Logs to S3 Configuration + Parameters: + - CreateVPCFlowLogsToS3 + - VPCFlowLogsBucketName + - VPCFlowLogsBucketKMSKey + - VPCFlowLogsBucketKeyEnabled + - S3AccessLogsBucketName + - Label: + default: Templates Configuration + Parameters: + - TemplatesS3BucketName + - TemplatesS3BucketRegion + ParameterLabels: + CreateVPCFlowLogsToCloudWatch: + default: Create VPC Flow Logs (CloudWatch) + CreateVPCFlowLogsToS3: + default: Create VPC Flow Logs (S3) + S3AccessLogsBucketName: + default: S3 Access Logs Bucket Name + TemplatesS3BucketName: + default: Templates S3 Bucket Name + TemplatesS3BucketRegion: + default: Templates S3 Bucket Region + VPCFlowLogsBucketKeyEnabled: + default: VPC Flow Logs Bucket Key Enabled + VPCFlowLogsBucketKMSKey: + default: VPC Flow Logs Bucket KMS Key + VPCFlowLogsBucketName: + default: VPC Flow Logs Bucket Name + VPCFlowLogsCloudWatchKMSKey: + default: CloudWatch Logs KMS Key for VPC flow logs + VPCFlowLogsLogFormat: + default: VPC Flow Logs - Log Format + VPCFlowLogsLogGroupRetention: + default: CloudWatch log retention days for VPC flow logs + VPCFlowLogsMaxAggregationInterval: + default: VPC Flow Logs - Max Aggregation Interval + VPCFlowLogsTrafficType: + default: VPC Flow Logs - Traffic Type + VPCID: + default: VPC ID + +Parameters: + CreateVPCFlowLogsToCloudWatch: + Description: Create VPC flow logs for the VPC and publish them to CloudWatch + Type: String + AllowedValues: + - Yes + - No + Default: No + + CreateVPCFlowLogsToS3: + Description: Create VPC flow logs for the VPC and publish them to S3 + Type: String + AllowedValues: + - Yes + - No + Default: No + + S3AccessLogsBucketName: + Description: (Optional) S3 Server Access Logs bucket name for where Amazon S3 should store server access log files. S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-). If empty, a new S3 bucket will be created as a destination for S3 server access logs, it will follow the format, aws-s3-access-logs-- + Type: String + AllowedPattern: ^$|^(?=^.{3,63}$)(?!.*[.-]{2})(?!.*[--]{2})(?!^(?:(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\.(?!$)|$)){4}$)(^(([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])\.)*([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])$) + ConstraintDescription: S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-). + + TemplatesS3BucketName: + Description: Templates S3 bucket name for the CloudFormation templates. S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-). + Type: String + AllowedPattern: ^(?=^.{3,63}$)(?!.*[.-]{2})(?!.*[--]{2})(?!^(?:(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\.(?!$)|$)){4}$)(^(([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])\.)*([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])$) + ConstraintDescription: Templates S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-). + + TemplatesS3BucketRegion: + Description: The AWS Region where the Templates S3 bucket (TemplatesS3BucketName) is hosted. + Type: String + + VPCFlowLogsBucketKeyEnabled: + Description: Set to true to have Amazon S3 use an S3 Bucket Key with server-side encryption using KMS (SSE-KMS). If false, S3 Bucket Key is not enabled. Note, will only be set if KMS Key parameter, "VPCFlowLogsBucketKMSKey", was provided. + Type: String + AllowedValues: + - true + - false + Default: false + + VPCFlowLogsBucketKMSKey: + Description: (Optional) KMS Key ID or ARN to use for the default encryption. If empty, server-side encryption with Amazon S3-managed encryption keys (SSE-S3) will be used. Note, will only be set if S3 Bucket parameter, "VPCFlowLogsBucketName", was not provided, thus a new S3 bucket is being created. + Type: String + AllowedPattern: ^$|^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$|^arn:(aws[a-zA-Z-]*)?:kms:[a-z0-9-]+:\d{12}:key\/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$ + ConstraintDescription: 'Key ID example: 1234abcd-12ab-34cd-56ef-1234567890ab Key ARN examlpe: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab' + + VPCFlowLogsBucketName: + Description: (Optional) S3 bucket name where VPC Flow Log data can be published. S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-). If empty, a new S3 bucket will be created for VPC Flow Log data to be published. + Type: String + AllowedPattern: ^$|^(?=^.{3,63}$)(?!.*[.-]{2})(?!.*[--]{2})(?!^(?:(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\.(?!$)|$)){4}$)(^(([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])\.)*([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])$) + ConstraintDescription: S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-). + + VPCFlowLogsCloudWatchKMSKey: + Description: (Optional) KMS Key ARN to use for encrypting the VPC flow logs data. If empty, encryption is enabled with CloudWatch Logs managing the server-side encryption keys. + Type: String + AllowedPattern: ^$|^arn:(aws[a-zA-Z-]*)?:kms:[a-z0-9-]+:\d{12}:key\/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$ + ConstraintDescription: 'Key ARN example: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab' + + VPCFlowLogsLogFormat: + Description: The fields to include in the flow log record, in the order in which they should appear. Specify the fields using the ${field-id} format, separated by spaces. Using the Default Format as the default value. + Type: String + Default: ${version} ${account-id} ${interface-id} ${srcaddr} ${dstaddr} ${srcport} ${dstport} ${protocol} ${packets} ${bytes} ${start} ${end} ${action} ${log-status} + AllowedPattern: ^(\$\{[a-z-]+\})$|^((\$\{[a-z-]+\} )*\$\{[a-z-]+\})$ + + VPCFlowLogsLogGroupRetention: + Description: Number of days to retain the VPC Flow Logs in CloudWatch + Type: String + AllowedValues: + - 1 + - 3 + - 5 + - 7 + - 14 + - 30 + - 60 + - 90 + - 120 + - 150 + - 180 + - 365 + - 400 + - 545 + - 731 + - 1827 + - 3653 + Default: 14 + + VPCFlowLogsMaxAggregationInterval: + Description: The maximum interval of time during which a flow of packets is captured and aggregated into a flow log record. You can specify 60 seconds (1 minute) or 600 seconds (10 minutes). + Type: String + AllowedValues: + - 60 + - 600 + Default: 600 + + VPCFlowLogsTrafficType: + Description: The type of traffic to log. You can log traffic that the resource accepts or rejects, or all traffic. + Type: String + AllowedValues: + - ACCEPT + - ALL + - REJECT + Default: REJECT + + VPCID: + Description: ID of the VPC (e.g., vpc-0343606e) + Type: AWS::EC2::VPC::Id + +Rules: + CreateVPCFlowLogs: + Assertions: + - Assert: !Or + - !Equals + - !Ref CreateVPCFlowLogsToCloudWatch + - Yes + - !Equals + - !Ref CreateVPCFlowLogsToS3 + - Yes + AssertDescription: To create VPC Flow Logs, you must have AWS CloudFormation parameters, 'CreateVPCFlowLogsToCloudWatch' and/or 'CreateVPCFlowLogsToS3' set to 'Yes' + +Conditions: + VPCFlowLogsToCloudWatchCondition: !Equals + - !Ref CreateVPCFlowLogsToCloudWatch + - Yes + + VPCFlowLogsToS3Condition: !Equals + - !Ref CreateVPCFlowLogsToS3 + - Yes + +Resources: + VPCFlowLogsCloudWatchStack: + Type: AWS::CloudFormation::Stack + Properties: + TemplateURL: !Sub https://${TemplatesS3BucketName}.s3.${TemplatesS3BucketRegion}.${AWS::URLSuffix}/templates/VPCFlowLogsCloudWatch.cfn.yaml + Parameters: + VPCFlowLogsCloudWatchKMSKey: !Ref VPCFlowLogsCloudWatchKMSKey + VPCFlowLogsLogFormat: !Ref VPCFlowLogsLogFormat + VPCFlowLogsLogGroupRetention: !Ref VPCFlowLogsLogGroupRetention + VPCFlowLogsMaxAggregationInterval: !Ref VPCFlowLogsMaxAggregationInterval + VPCFlowLogsTrafficType: !Ref VPCFlowLogsTrafficType + VPCID: !Ref VPCID + Condition: VPCFlowLogsToCloudWatchCondition + + VPCFlowLogsS3Stack: + Type: AWS::CloudFormation::Stack + Properties: + TemplateURL: !Sub https://${TemplatesS3BucketName}.s3.${TemplatesS3BucketRegion}.${AWS::URLSuffix}/templates/VPCFlowLogsS3.cfn.yaml + Parameters: + S3AccessLogsBucketName: !Ref S3AccessLogsBucketName + VPCFlowLogsBucketKeyEnabled: !Ref VPCFlowLogsBucketKeyEnabled + VPCFlowLogsBucketKMSKey: !Ref VPCFlowLogsBucketKMSKey + VPCFlowLogsBucketName: !Ref VPCFlowLogsBucketName + VPCFlowLogsLogFormat: !Ref VPCFlowLogsLogFormat + VPCFlowLogsMaxAggregationInterval: !Ref VPCFlowLogsMaxAggregationInterval + VPCFlowLogsTrafficType: !Ref VPCFlowLogsTrafficType + VPCID: !Ref VPCID + Condition: VPCFlowLogsToS3Condition diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCFlowLogs/templates/VPCFlowLogsCloudWatch.cfn.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCFlowLogs/templates/VPCFlowLogsCloudWatch.cfn.json new file mode 100644 index 0000000000000000000000000000000000000000..109e361e10d0276a12c9e22034fdb8ba71384cd6 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCFlowLogs/templates/VPCFlowLogsCloudWatch.cfn.json @@ -0,0 +1,243 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "This template enables VPC Flow Logs to CloudWatch.", + "Metadata": { + "AWS::CloudFormation::Interface": { + "ParameterGroups": [ + { + "Label": { + "default": "Network Configuration" + }, + "Parameters": [ + "VPCID" + ] + }, + { + "Label": { + "default": "VPC Flow Logs Configuration" + }, + "Parameters": [ + "VPCFlowLogsLogFormat", + "VPCFlowLogsMaxAggregationInterval", + "VPCFlowLogsTrafficType", + "VPCFlowLogsLogGroupRetention", + "VPCFlowLogsCloudWatchKMSKey" + ] + } + ], + "ParameterLabels": { + "VPCFlowLogsCloudWatchKMSKey": { + "default": "CloudWatch Logs KMS Key for VPC flow logs" + }, + "VPCFlowLogsLogFormat": { + "default": "VPC Flow Logs - Log Format" + }, + "VPCFlowLogsLogGroupRetention": { + "default": "CloudWatch log retention days for VPC flow logs" + }, + "VPCFlowLogsMaxAggregationInterval": { + "default": "VPC Flow Logs - Max Aggregation Interval" + }, + "VPCFlowLogsTrafficType": { + "default": "VPC Flow Logs - Traffic Type" + }, + "VPCID": { + "default": "VPC ID" + } + } + } + }, + "Parameters": { + "VPCFlowLogsCloudWatchKMSKey": { + "Description": "(Optional) KMS Key ARN to use for encrypting the VPC flow logs data. If empty, encryption is enabled with CloudWatch Logs managing the server-side encryption keys.", + "Type": "String", + "AllowedPattern": "^$|^arn:(aws[a-zA-Z-]*)?:kms:[a-z0-9-]+:\\d{12}:key\\/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$", + "ConstraintDescription": "Key ARN example: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab" + }, + "VPCFlowLogsLogFormat": { + "Description": "The fields to include in the flow log record, in the order in which they should appear. Specify the fields using the ${field-id} format, separated by spaces. Using the Default Format as the default value.", + "Type": "String", + "Default": "${version} ${account-id} ${interface-id} ${srcaddr} ${dstaddr} ${srcport} ${dstport} ${protocol} ${packets} ${bytes} ${start} ${end} ${action} ${log-status}", + "AllowedPattern": "^(\\$\\{[a-z-]+\\})$|^((\\$\\{[a-z-]+\\} )*\\$\\{[a-z-]+\\})$" + }, + "VPCFlowLogsLogGroupRetention": { + "Description": "Number of days to retain the VPC Flow Logs in CloudWatch", + "Type": "String", + "AllowedValues": [ + 1, + 3, + 5, + 7, + 14, + 30, + 60, + 90, + 120, + 150, + 180, + 365, + 400, + 545, + 731, + 1827, + 3653 + ], + "Default": 14 + }, + "VPCFlowLogsMaxAggregationInterval": { + "Description": "The maximum interval of time during which a flow of packets is captured and aggregated into a flow log record. You can specify 60 seconds (1 minute) or 600 seconds (10 minutes).", + "Type": "String", + "AllowedValues": [ + 60, + 600 + ], + "Default": 600 + }, + "VPCFlowLogsTrafficType": { + "Description": "The type of traffic to log. You can log traffic that the resource accepts or rejects, or all traffic.", + "Type": "String", + "AllowedValues": [ + "ACCEPT", + "ALL", + "REJECT" + ], + "Default": "REJECT" + }, + "VPCID": { + "Description": "ID of the VPC (e.g., vpc-0343606e)", + "Type": "AWS::EC2::VPC::Id" + } + }, + "Conditions": { + "VPCFlowLogsCloudWatchKMSKeyCondition": { + "Fn::Not": [ + { + "Fn::Equals": [ + { + "Ref": "VPCFlowLogsCloudWatchKMSKey" + }, + "" + ] + } + ] + } + }, + "Resources": { + "VPCFlowLogsRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "Description": "Rights to Publish VPC Flow Logs to CloudWatch Logs", + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": "sts:AssumeRole", + "Principal": { + "Service": [ + "vpc-flow-logs.amazonaws.com" + ] + } + } + ] + }, + "Path": "/", + "Tags": [ + { + "Key": "StackName", + "Value": { + "Ref": "AWS::StackName" + } + } + ], + "Policies": [ + { + "PolicyName": "CloudWatchLogGroup", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Sid": "CloudWatchLogs", + "Effect": "Allow", + "Action": [ + "logs:CreateLogStream", + "logs:PutLogEvents", + "logs:DescribeLogGroups", + "logs:DescribeLogStreams" + ], + "Resource": { + "Fn::GetAtt": [ + "VPCFlowLogsLogGroup", + "Arn" + ] + } + } + ] + } + } + ] + } + }, + "VPCFlowLogsLogGroup": { + "Type": "AWS::Logs::LogGroup", + "Properties": { + "RetentionInDays": { + "Ref": "VPCFlowLogsLogGroupRetention" + }, + "KmsKeyId": { + "Fn::If": [ + "VPCFlowLogsCloudWatchKMSKeyCondition", + { + "Ref": "VPCFlowLogsCloudWatchKMSKey" + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + }, + "VPCFlowLogsToCloudWatch": { + "Type": "AWS::EC2::FlowLog", + "Properties": { + "LogDestinationType": "cloud-watch-logs", + "LogGroupName": { + "Ref": "VPCFlowLogsLogGroup" + }, + "DeliverLogsPermissionArn": { + "Fn::GetAtt": [ + "VPCFlowLogsRole", + "Arn" + ] + }, + "LogFormat": { + "Ref": "VPCFlowLogsLogFormat" + }, + "MaxAggregationInterval": { + "Ref": "VPCFlowLogsMaxAggregationInterval" + }, + "ResourceId": { + "Ref": "VPCID" + }, + "ResourceType": "VPC", + "TrafficType": { + "Ref": "VPCFlowLogsTrafficType" + }, + "Tags": [ + { + "Key": "Name", + "Value": "VPC Flow Logs CloudWatch" + } + ] + } + } + }, + "Outputs": { + "VPCFlowLogsLogGroup": { + "Description": "CloudWatch Log Group where VPC Flow Log data will be published", + "Value": { + "Ref": "VPCFlowLogsLogGroup" + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCFlowLogs/templates/VPCFlowLogsCloudWatch.cfn.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCFlowLogs/templates/VPCFlowLogsCloudWatch.cfn.yaml new file mode 100644 index 0000000000000000000000000000000000000000..0a025aa2a0e1241b7e841bff3e2593e3648de25c --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCFlowLogs/templates/VPCFlowLogsCloudWatch.cfn.yaml @@ -0,0 +1,155 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: This template enables VPC Flow Logs to CloudWatch. + +Metadata: + AWS::CloudFormation::Interface: + ParameterGroups: + - Label: + default: Network Configuration + Parameters: + - VPCID + - Label: + default: VPC Flow Logs Configuration + Parameters: + - VPCFlowLogsLogFormat + - VPCFlowLogsMaxAggregationInterval + - VPCFlowLogsTrafficType + - VPCFlowLogsLogGroupRetention + - VPCFlowLogsCloudWatchKMSKey + ParameterLabels: + VPCFlowLogsCloudWatchKMSKey: + default: CloudWatch Logs KMS Key for VPC flow logs + VPCFlowLogsLogFormat: + default: VPC Flow Logs - Log Format + VPCFlowLogsLogGroupRetention: + default: CloudWatch log retention days for VPC flow logs + VPCFlowLogsMaxAggregationInterval: + default: VPC Flow Logs - Max Aggregation Interval + VPCFlowLogsTrafficType: + default: VPC Flow Logs - Traffic Type + VPCID: + default: VPC ID + +Parameters: + VPCFlowLogsCloudWatchKMSKey: + Description: (Optional) KMS Key ARN to use for encrypting the VPC flow logs data. If empty, encryption is enabled with CloudWatch Logs managing the server-side encryption keys. + Type: String + AllowedPattern: ^$|^arn:(aws[a-zA-Z-]*)?:kms:[a-z0-9-]+:\d{12}:key\/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$ + ConstraintDescription: 'Key ARN example: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab' + + VPCFlowLogsLogFormat: + Description: The fields to include in the flow log record, in the order in which they should appear. Specify the fields using the ${field-id} format, separated by spaces. Using the Default Format as the default value. + Type: String + Default: ${version} ${account-id} ${interface-id} ${srcaddr} ${dstaddr} ${srcport} ${dstport} ${protocol} ${packets} ${bytes} ${start} ${end} ${action} ${log-status} + AllowedPattern: ^(\$\{[a-z-]+\})$|^((\$\{[a-z-]+\} )*\$\{[a-z-]+\})$ + + VPCFlowLogsLogGroupRetention: + Description: Number of days to retain the VPC Flow Logs in CloudWatch + Type: String + AllowedValues: + - 1 + - 3 + - 5 + - 7 + - 14 + - 30 + - 60 + - 90 + - 120 + - 150 + - 180 + - 365 + - 400 + - 545 + - 731 + - 1827 + - 3653 + Default: 14 + + VPCFlowLogsMaxAggregationInterval: + Description: The maximum interval of time during which a flow of packets is captured and aggregated into a flow log record. You can specify 60 seconds (1 minute) or 600 seconds (10 minutes). + Type: String + AllowedValues: + - 60 + - 600 + Default: 600 + + VPCFlowLogsTrafficType: + Description: The type of traffic to log. You can log traffic that the resource accepts or rejects, or all traffic. + Type: String + AllowedValues: + - ACCEPT + - ALL + - REJECT + Default: REJECT + + VPCID: + Description: ID of the VPC (e.g., vpc-0343606e) + Type: AWS::EC2::VPC::Id + +Conditions: + VPCFlowLogsCloudWatchKMSKeyCondition: !Not + - !Equals + - !Ref VPCFlowLogsCloudWatchKMSKey + - "" + +Resources: + VPCFlowLogsRole: + Type: AWS::IAM::Role + Properties: + Description: Rights to Publish VPC Flow Logs to CloudWatch Logs + AssumeRolePolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: sts:AssumeRole + Principal: + Service: + - vpc-flow-logs.amazonaws.com + Path: / + Tags: + - Key: StackName + Value: !Ref AWS::StackName + Policies: + - PolicyName: CloudWatchLogGroup + PolicyDocument: + Version: "2012-10-17" + Statement: + - Sid: CloudWatchLogs + Effect: Allow + Action: + - logs:CreateLogStream + - logs:PutLogEvents + - logs:DescribeLogGroups + - logs:DescribeLogStreams + Resource: !GetAtt VPCFlowLogsLogGroup.Arn + + VPCFlowLogsLogGroup: + Type: AWS::Logs::LogGroup + Properties: + RetentionInDays: !Ref VPCFlowLogsLogGroupRetention + KmsKeyId: !If + - VPCFlowLogsCloudWatchKMSKeyCondition + - !Ref VPCFlowLogsCloudWatchKMSKey + - !Ref AWS::NoValue + + VPCFlowLogsToCloudWatch: + Type: AWS::EC2::FlowLog + Properties: + LogDestinationType: cloud-watch-logs + LogGroupName: !Ref VPCFlowLogsLogGroup + DeliverLogsPermissionArn: !GetAtt VPCFlowLogsRole.Arn + LogFormat: !Ref VPCFlowLogsLogFormat + MaxAggregationInterval: !Ref VPCFlowLogsMaxAggregationInterval + ResourceId: !Ref VPCID + ResourceType: VPC + TrafficType: !Ref VPCFlowLogsTrafficType + Tags: + - Key: Name + Value: VPC Flow Logs CloudWatch + +Outputs: + VPCFlowLogsLogGroup: + Description: CloudWatch Log Group where VPC Flow Log data will be published + Value: !Ref VPCFlowLogsLogGroup diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCFlowLogs/templates/VPCFlowLogsS3.cfn.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCFlowLogs/templates/VPCFlowLogsS3.cfn.json new file mode 100644 index 0000000000000000000000000000000000000000..93b4427ba042e02de930cf9101c616a57c14b89a --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCFlowLogs/templates/VPCFlowLogsS3.cfn.json @@ -0,0 +1,343 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "This template enables VPC Flow Logs to S3. An option is provided to create an Amazon S3 bucket with encryption to host the flow logs.", + "Metadata": { + "AWS::CloudFormation::Interface": { + "ParameterGroups": [ + { + "Label": { + "default": "Network Configuration" + }, + "Parameters": [ + "VPCID" + ] + }, + { + "Label": { + "default": "VPC Flow Logs Configuration" + }, + "Parameters": [ + "VPCFlowLogsLogFormat", + "VPCFlowLogsMaxAggregationInterval", + "VPCFlowLogsTrafficType", + "VPCFlowLogsBucketName", + "VPCFlowLogsBucketKMSKey", + "VPCFlowLogsBucketKeyEnabled", + "S3AccessLogsBucketName" + ] + } + ], + "ParameterLabels": { + "S3AccessLogsBucketName": { + "default": "S3 Server Access Logs Bucket Name" + }, + "VPCFlowLogsBucketKeyEnabled": { + "default": "VPC Flow Logs Bucket Key Enabled" + }, + "VPCFlowLogsBucketKMSKey": { + "default": "VPC Flow Logs Bucket KMS Key" + }, + "VPCFlowLogsBucketName": { + "default": "VPC Flow Logs Bucket Name" + }, + "VPCFlowLogsLogFormat": { + "default": "VPC Flow Logs - Log Format" + }, + "VPCFlowLogsMaxAggregationInterval": { + "default": "VPC Flow Logs - Max Aggregation Interval" + }, + "VPCFlowLogsTrafficType": { + "default": "VPC Flow Logs - Traffic Type" + }, + "VPCID": { + "default": "VPC ID" + } + } + } + }, + "Parameters": { + "S3AccessLogsBucketName": { + "Description": "(Optional) S3 Server Access Logs bucket name for where Amazon S3 should store server access log files. S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-). If empty, a new S3 bucket will be created as a destination for S3 server access logs, it will follow the format, aws-s3-access-logs--", + "Type": "String", + "AllowedPattern": "^$|^(?=^.{3,63}$)(?!.*[.-]{2})(?!.*[--]{2})(?!^(?:(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\\.(?!$)|$)){4}$)(^(([a-z0-9]|[a-z0-9][a-z0-9\\-]*[a-z0-9])\\.)*([a-z0-9]|[a-z0-9][a-z0-9\\-]*[a-z0-9])$)", + "ConstraintDescription": "S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-)." + }, + "VPCFlowLogsBucketKeyEnabled": { + "Description": "Set to true to have Amazon S3 use an S3 Bucket Key with server-side encryption using KMS (SSE-KMS). If false, S3 Bucket Key is not enabled. Note, will only be set if KMS Key parameter, 'VPCFlowLogsBucketKMSKey', was provided.", + "Type": "String", + "AllowedValues": [ + true, + false + ], + "Default": false + }, + "VPCFlowLogsBucketKMSKey": { + "Description": "(Optional) KMS Key ID or ARN to use for the default encryption. If empty, server-side encryption with Amazon S3-managed encryption keys (SSE-S3) will be used. Note, will only be set if S3 Bucket parameter, 'VPCFlowLogsBucketName', was not provided, thus a new S3 bucket is being created.", + "Type": "String", + "AllowedPattern": "^$|^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$|^arn:(aws[a-zA-Z-]*)?:kms:[a-z0-9-]+:\\d{12}:key\\/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$", + "ConstraintDescription": "Key ID example: 1234abcd-12ab-34cd-56ef-1234567890ab Key ARN example: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab" + }, + "VPCFlowLogsBucketName": { + "Description": "(Optional) S3 bucket name where VPC Flow Log data can be published. S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-). If empty, a new S3 bucket will be created for VPC Flow Log data to be published.", + "Type": "String", + "AllowedPattern": "^$|^(?=^.{3,63}$)(?!.*[.-]{2})(?!.*[--]{2})(?!^(?:(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\\.(?!$)|$)){4}$)(^(([a-z0-9]|[a-z0-9][a-z0-9\\-]*[a-z0-9])\\.)*([a-z0-9]|[a-z0-9][a-z0-9\\-]*[a-z0-9])$)", + "ConstraintDescription": "S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-)." + }, + "VPCFlowLogsLogFormat": { + "Description": "The fields to include in the flow log record, in the order in which they should appear. Specify the fields using the ${field-id} format, separated by spaces. Using the Default Format as the default value.", + "Type": "String", + "Default": "${version} ${account-id} ${interface-id} ${srcaddr} ${dstaddr} ${srcport} ${dstport} ${protocol} ${packets} ${bytes} ${start} ${end} ${action} ${log-status}", + "AllowedPattern": "^(\\$\\{[a-z-]+\\})$|^((\\$\\{[a-z-]+\\} )*\\$\\{[a-z-]+\\})$" + }, + "VPCFlowLogsMaxAggregationInterval": { + "Description": "The maximum interval of time during which a flow of packets is captured and aggregated into a flow log record. You can specify 60 seconds (1 minute) or 600 seconds (10 minutes).", + "Type": "String", + "AllowedValues": [ + 60, + 600 + ], + "Default": 600 + }, + "VPCFlowLogsTrafficType": { + "Description": "The type of traffic to log. You can log traffic that the resource accepts or rejects, or all traffic.", + "Type": "String", + "AllowedValues": [ + "ACCEPT", + "ALL", + "REJECT" + ], + "Default": "REJECT" + }, + "VPCID": { + "Description": "ID of the VPC (e.g., vpc-0343606e)", + "Type": "AWS::EC2::VPC::Id" + } + }, + "Conditions": { + "S3AccessLogsCondition": { + "Fn::Not": [ + { + "Fn::Equals": [ + { + "Ref": "S3AccessLogsBucketName" + }, + "" + ] + } + ] + }, + "VPCFlowLogsNewBucketCondition": { + "Fn::Equals": [ + { + "Ref": "VPCFlowLogsBucketName" + }, + "" + ] + }, + "VPCFlowLogsBucketKMSKeyCondition": { + "Fn::Not": [ + { + "Fn::Equals": [ + { + "Ref": "VPCFlowLogsBucketKMSKey" + }, + "" + ] + } + ] + } + }, + "Resources": { + "VPCFlowLogstoS3": { + "Type": "AWS::EC2::FlowLog", + "Properties": { + "LogDestinationType": "s3", + "LogDestination": { + "Fn::If": [ + "VPCFlowLogsNewBucketCondition", + { + "Fn::GetAtt": [ + "VPCFlowLogsBucket", + "Arn" + ] + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${VPCFlowLogsBucketName}" + } + ] + }, + "LogFormat": { + "Ref": "VPCFlowLogsLogFormat" + }, + "MaxAggregationInterval": { + "Ref": "VPCFlowLogsMaxAggregationInterval" + }, + "ResourceId": { + "Ref": "VPCID" + }, + "ResourceType": "VPC", + "TrafficType": { + "Ref": "VPCFlowLogsTrafficType" + }, + "Tags": [ + { + "Key": "Name", + "Value": "VPC Flow Logs S3" + } + ] + } + }, + "VPCFlowLogsBucket": { + "Type": "AWS::S3::Bucket", + "Metadata": { + "guard": { + "SuppressedRules": [ + "S3_BUCKET_SERVER_SIDE_ENCRYPTION_ENABLED", + "S3_BUCKET_DEFAULT_LOCK_ENABLED", + "S3_BUCKET_REPLICATION_ENABLED" + ] + } + }, + "Properties": { + "BucketName": { + "Fn::Sub": "aws-vpcflowlogs-${AWS::AccountId}-${AWS::Region}" + }, + "PublicAccessBlockConfiguration": { + "BlockPublicAcls": true, + "BlockPublicPolicy": true, + "IgnorePublicAcls": true, + "RestrictPublicBuckets": true + }, + "BucketEncryption": { + "ServerSideEncryptionConfiguration": [ + { + "ServerSideEncryptionByDefault": { + "SSEAlgorithm": { + "Fn::If": [ + "VPCFlowLogsBucketKMSKeyCondition", + "aws:kms", + "AES256" + ] + }, + "KMSMasterKeyID": { + "Fn::If": [ + "VPCFlowLogsBucketKMSKeyCondition", + { + "Ref": "VPCFlowLogsBucketKMSKey" + }, + { + "Ref": "AWS::NoValue" + } + ] + } + }, + "BucketKeyEnabled": { + "Fn::If": [ + "VPCFlowLogsBucketKMSKeyCondition", + { + "Ref": "VPCFlowLogsBucketKeyEnabled" + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + ] + }, + "LoggingConfiguration": { + "Fn::If": [ + "S3AccessLogsCondition", + { + "DestinationBucketName": { + "Ref": "S3AccessLogsBucketName" + } + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + "VersioningConfiguration": { + "Status": "Enabled" + } + }, + "Condition": "VPCFlowLogsNewBucketCondition" + }, + "VPCFlowLogsBucketPolicy": { + "Type": "AWS::S3::BucketPolicy", + "Properties": { + "Bucket": { + "Ref": "VPCFlowLogsBucket" + }, + "PolicyDocument": { + "Statement": [ + { + "Sid": "AWSLogDeliveryWrite", + "Effect": "Allow", + "Action": "s3:PutObject", + "Resource": { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${VPCFlowLogsBucket}/*" + }, + "Principal": { + "Service": "delivery.logs.amazonaws.com" + }, + "Condition": { + "StringEquals": { + "s3:x-amz-acl": "bucket-owner-full-control" + } + } + }, + { + "Sid": "AWSLogDeliveryAclCheck", + "Effect": "Allow", + "Action": "s3:GetBucketAcl", + "Resource": { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${VPCFlowLogsBucket}" + }, + "Principal": { + "Service": "delivery.logs.amazonaws.com" + } + }, + { + "Sid": "DenyNonSSLRequests", + "Effect": "Deny", + "Action": "s3:*", + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${VPCFlowLogsBucket}" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${VPCFlowLogsBucket}/*" + } + ], + "Principal": "*", + "Condition": { + "Bool": { + "aws:SecureTransport": false + } + } + } + ] + } + }, + "Condition": "VPCFlowLogsNewBucketCondition" + } + }, + "Outputs": { + "VPCFlowLogsBucket": { + "Description": "S3 bucket name where VPC Flow Log data will be published", + "Value": { + "Fn::If": [ + "VPCFlowLogsNewBucketCondition", + { + "Ref": "VPCFlowLogsBucket" + }, + { + "Ref": "VPCFlowLogsBucketName" + } + ] + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCFlowLogs/templates/VPCFlowLogsS3.cfn.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCFlowLogs/templates/VPCFlowLogsS3.cfn.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b06c1b8cef501e1e79943cd91568c02360c6a2f4 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCFlowLogs/templates/VPCFlowLogsS3.cfn.yaml @@ -0,0 +1,204 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: This template enables VPC Flow Logs to S3. An option is provided to create an Amazon S3 bucket with encryption to host the flow logs. + +Metadata: + AWS::CloudFormation::Interface: + ParameterGroups: + - Label: + default: Network Configuration + Parameters: + - VPCID + - Label: + default: VPC Flow Logs Configuration + Parameters: + - VPCFlowLogsLogFormat + - VPCFlowLogsMaxAggregationInterval + - VPCFlowLogsTrafficType + - VPCFlowLogsBucketName + - VPCFlowLogsBucketKMSKey + - VPCFlowLogsBucketKeyEnabled + - S3AccessLogsBucketName + ParameterLabels: + S3AccessLogsBucketName: + default: S3 Server Access Logs Bucket Name + VPCFlowLogsBucketKeyEnabled: + default: VPC Flow Logs Bucket Key Enabled + VPCFlowLogsBucketKMSKey: + default: VPC Flow Logs Bucket KMS Key + VPCFlowLogsBucketName: + default: VPC Flow Logs Bucket Name + VPCFlowLogsLogFormat: + default: VPC Flow Logs - Log Format + VPCFlowLogsMaxAggregationInterval: + default: VPC Flow Logs - Max Aggregation Interval + VPCFlowLogsTrafficType: + default: VPC Flow Logs - Traffic Type + VPCID: + default: VPC ID + +Parameters: + S3AccessLogsBucketName: + Description: (Optional) S3 Server Access Logs bucket name for where Amazon S3 should store server access log files. S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-). If empty, a new S3 bucket will be created as a destination for S3 server access logs, it will follow the format, aws-s3-access-logs-- + Type: String + AllowedPattern: ^$|^(?=^.{3,63}$)(?!.*[.-]{2})(?!.*[--]{2})(?!^(?:(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\.(?!$)|$)){4}$)(^(([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])\.)*([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])$) + ConstraintDescription: S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-). + + VPCFlowLogsBucketKeyEnabled: + Description: Set to true to have Amazon S3 use an S3 Bucket Key with server-side encryption using KMS (SSE-KMS). If false, S3 Bucket Key is not enabled. Note, will only be set if KMS Key parameter, 'VPCFlowLogsBucketKMSKey', was provided. + Type: String + AllowedValues: + - true + - false + Default: false + + VPCFlowLogsBucketKMSKey: + Description: (Optional) KMS Key ID or ARN to use for the default encryption. If empty, server-side encryption with Amazon S3-managed encryption keys (SSE-S3) will be used. Note, will only be set if S3 Bucket parameter, 'VPCFlowLogsBucketName', was not provided, thus a new S3 bucket is being created. + Type: String + AllowedPattern: ^$|^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$|^arn:(aws[a-zA-Z-]*)?:kms:[a-z0-9-]+:\d{12}:key\/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$ + ConstraintDescription: 'Key ID example: 1234abcd-12ab-34cd-56ef-1234567890ab Key ARN example: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab' + + VPCFlowLogsBucketName: + Description: (Optional) S3 bucket name where VPC Flow Log data can be published. S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-). If empty, a new S3 bucket will be created for VPC Flow Log data to be published. + Type: String + AllowedPattern: ^$|^(?=^.{3,63}$)(?!.*[.-]{2})(?!.*[--]{2})(?!^(?:(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\.(?!$)|$)){4}$)(^(([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])\.)*([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])$) + ConstraintDescription: S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-). + + VPCFlowLogsLogFormat: + Description: The fields to include in the flow log record, in the order in which they should appear. Specify the fields using the ${field-id} format, separated by spaces. Using the Default Format as the default value. + Type: String + Default: ${version} ${account-id} ${interface-id} ${srcaddr} ${dstaddr} ${srcport} ${dstport} ${protocol} ${packets} ${bytes} ${start} ${end} ${action} ${log-status} + AllowedPattern: ^(\$\{[a-z-]+\})$|^((\$\{[a-z-]+\} )*\$\{[a-z-]+\})$ + + VPCFlowLogsMaxAggregationInterval: + Description: The maximum interval of time during which a flow of packets is captured and aggregated into a flow log record. You can specify 60 seconds (1 minute) or 600 seconds (10 minutes). + Type: String + AllowedValues: + - 60 + - 600 + Default: 600 + + VPCFlowLogsTrafficType: + Description: The type of traffic to log. You can log traffic that the resource accepts or rejects, or all traffic. + Type: String + AllowedValues: + - ACCEPT + - ALL + - REJECT + Default: REJECT + + VPCID: + Description: ID of the VPC (e.g., vpc-0343606e) + Type: AWS::EC2::VPC::Id + +Conditions: + S3AccessLogsCondition: !Not + - !Equals + - !Ref S3AccessLogsBucketName + - "" + + VPCFlowLogsNewBucketCondition: !Equals + - !Ref VPCFlowLogsBucketName + - "" + + VPCFlowLogsBucketKMSKeyCondition: !Not + - !Equals + - !Ref VPCFlowLogsBucketKMSKey + - "" + +Resources: + VPCFlowLogstoS3: + Type: AWS::EC2::FlowLog + Properties: + LogDestinationType: s3 + LogDestination: !If + - VPCFlowLogsNewBucketCondition + - !GetAtt VPCFlowLogsBucket.Arn + - !Sub arn:${AWS::Partition}:s3:::${VPCFlowLogsBucketName} + LogFormat: !Ref VPCFlowLogsLogFormat + MaxAggregationInterval: !Ref VPCFlowLogsMaxAggregationInterval + ResourceId: !Ref VPCID + ResourceType: VPC + TrafficType: !Ref VPCFlowLogsTrafficType + Tags: + - Key: Name + Value: VPC Flow Logs S3 + + VPCFlowLogsBucket: + Type: AWS::S3::Bucket + Metadata: + guard: + SuppressedRules: + - S3_BUCKET_SERVER_SIDE_ENCRYPTION_ENABLED + - S3_BUCKET_DEFAULT_LOCK_ENABLED + - S3_BUCKET_REPLICATION_ENABLED + Properties: + BucketName: !Sub aws-vpcflowlogs-${AWS::AccountId}-${AWS::Region} + PublicAccessBlockConfiguration: + BlockPublicAcls: true + BlockPublicPolicy: true + IgnorePublicAcls: true + RestrictPublicBuckets: true + BucketEncryption: + ServerSideEncryptionConfiguration: + - ServerSideEncryptionByDefault: + SSEAlgorithm: !If + - VPCFlowLogsBucketKMSKeyCondition + - aws:kms + - AES256 + KMSMasterKeyID: !If + - VPCFlowLogsBucketKMSKeyCondition + - !Ref VPCFlowLogsBucketKMSKey + - !Ref AWS::NoValue + BucketKeyEnabled: !If + - VPCFlowLogsBucketKMSKeyCondition + - !Ref VPCFlowLogsBucketKeyEnabled + - !Ref AWS::NoValue + LoggingConfiguration: !If + - S3AccessLogsCondition + - DestinationBucketName: !Ref S3AccessLogsBucketName + - !Ref AWS::NoValue + VersioningConfiguration: + Status: Enabled + Condition: VPCFlowLogsNewBucketCondition + + VPCFlowLogsBucketPolicy: + Type: AWS::S3::BucketPolicy + Properties: + Bucket: !Ref VPCFlowLogsBucket + PolicyDocument: + Statement: + - Sid: AWSLogDeliveryWrite + Effect: Allow + Action: s3:PutObject + Resource: !Sub arn:${AWS::Partition}:s3:::${VPCFlowLogsBucket}/* + Principal: + Service: delivery.logs.amazonaws.com + Condition: + StringEquals: + s3:x-amz-acl: bucket-owner-full-control + - Sid: AWSLogDeliveryAclCheck + Effect: Allow + Action: s3:GetBucketAcl + Resource: !Sub arn:${AWS::Partition}:s3:::${VPCFlowLogsBucket} + Principal: + Service: delivery.logs.amazonaws.com + - Sid: DenyNonSSLRequests + Effect: Deny + Action: s3:* + Resource: + - !Sub arn:${AWS::Partition}:s3:::${VPCFlowLogsBucket} + - !Sub arn:${AWS::Partition}:s3:::${VPCFlowLogsBucket}/* + Principal: '*' + Condition: + Bool: + aws:SecureTransport: false + Condition: VPCFlowLogsNewBucketCondition + +Outputs: + VPCFlowLogsBucket: + Description: S3 bucket name where VPC Flow Log data will be published + Value: !If + - VPCFlowLogsNewBucketCondition + - !Ref VPCFlowLogsBucket + - !Ref VPCFlowLogsBucketName diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/README.md b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/README.md new file mode 100644 index 0000000000000000000000000000000000000000..16b3160458cc2647e3649130c187fb4274a48546 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/README.md @@ -0,0 +1,58 @@ +# VPCPeering + +This solution lets you peer with another VPC in the same or different AWS account. After creating VPC peering connection, additional templates can be +deployed to: + +- Apply a `Name` tag for the VPC peering connection in the accepter account using a python CloudFormation custom resource. +- Update specified Route Tables & Security Groups +- Supports a comma-delimited list with validation for below parameters: + - AWS accounts authorized for VPC peering connections + - Route Tables, to be updated to allow communications via VPC peering connection. + +This solution can be implemented as individual templates accordingly, or leveraging the nested stacks `main` templates. + +## Notes + +- CloudWatch Logs Log Group uses Amazon managed server-side encryption. Optionally, a KMS CMK can be used. +- Amazon S3 Buckets using Amazon managed server-side encryption. Optionally, a KMS CMK can be used. +- **NOTE** Security Group rules are configured to allow all inbound communications from the `VPC Peer CIDR`, this is used as an **EXAMPLE**, however, + all security group rules can be locked down based on the requirements. +- **NOTE** Route Table routes are configured to allow all inbound communications from the `VPC Peer CIDR`, this is used as an **EXAMPLE**, however, + all security group rules can be locked down based on the requirements. + +## Resources + +- [What is VPC Peering?](https://docs.aws.amazon.com/vpc/latest/peering/what-is-vpc-peering.html) +- [VPC Peering Basics](https://docs.aws.amazon.com/vpc/latest/peering/vpc-peering-basics.html) +- [Walkthrough: Peer with an Amazon VPC in another AWS account](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/peer-with-vpc-in-another-account.html) + +## Instructions (Individual Stacks) + +1. Launch the AWS CloudFormation stack using the [VPCPeering-Accepter-Role.cfn.yaml](templates/VPCPeering-Accepter-Role.cfn.yaml) template file as the + source, to create the assumable role in the accepter account that will be used by the requester account. **Note:** If VPC peering connection being + done between 2 VPCs in the same AWS account, then this step can be skipped. +2. Launch the AWS CloudFormation stack using the [VPCPeering-Requester-Setup.cfn.yaml](templates/VPCPeering-Requester-Setup.cfn.yaml) template file as + the source, to create the VPC peering connection in the requester account. +3. Launch the AWS CloudFormation stack using the [VPCPeering-Accepter-Tag.cfn.yaml](templates/VPCPeering-Accepter-Tag.cfn.yaml) template file as the + source, to apply a name tag on the VPC peering connection in the accepter account. +4. Launch the AWS CloudFormation stack using the [VPCPeering-Updates.cfn.yaml](templates/VPCPeering-Updates.cfn.yaml) template file as the source, to + update the specified route tables & security groups for communications with the VPC peering connection in the requester account. +5. Launch the AWS CloudFormation stack using the [VPCPeering-Updates.cfn.yaml](templates/VPCPeering-Updates.cfn.yaml) template file as the source, to + update the specified route tables & security groups for communications with the VPC peering connection in the accepter account. + +## Instructions (Nested Stacks) + +1. Launch the AWS CloudFormation stack using the [VPCPeering-Accepter-Role.cfn.yaml](templates/VPCPeering-Accepter-Role.cfn.yaml) template file as the + source, to create the assumable role in the accepter account. **Note:** If VPC peering connection being done between 2 VPCs in the same AWS + account, then this step can be skipped. +2. Launch the AWS CloudFormation root stack using the [VPCPeering-Requester.main.cfn.yaml](templates/VPCPeering-Requester.main.cfn.yaml) template file + as the source, to the requester account. +3. Launch the AWS CloudFormation root stack using the [VPCPeering-Accepter.main.cfn.yaml](templates/VPCPeering-Accepter.main.cfn.yaml) template file + as the source, to the accepter account. + +## Creating more VPC peering connections from different AWS accounts with same accepter account + +1. Launch the AWS CloudFormation stack using the [VPCPeering-Accepter-Role.cfn.yaml](templates/VPCPeering-Accepter-Role.cfn.yaml) template file as the + source, with the AWS account of the additional requester accounts you will be creating VPC peering connections with. +2. Continue with Step 2 from the [Individual Stacks Instructions](#instructions-individual-stacks) or the + [Nested Stack Instructions](#instructions-nested-stacks) instructions. diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Accepter-Role.cfn.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Accepter-Role.cfn.json new file mode 100644 index 0000000000000000000000000000000000000000..553fac4421adbf2df2215f2bf6a9b79d35746314 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Accepter-Role.cfn.json @@ -0,0 +1,101 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "This template creates an assumable role to be used by the requester account to accept the VPC peering connection. (Accepter Account)", + "Metadata": { + "AWS::CloudFormation::Interface": { + "ParameterGroups": [ + { + "Label": { + "default": "VPC Peering Configuration" + }, + "Parameters": [ + "PeerOwnerIds" + ] + } + ], + "ParameterLabels": { + "PeerOwnerIds": { + "default": "Peer Owner IDs" + } + } + } + }, + "Parameters": { + "PeerOwnerIds": { + "Description": "AWS account IDs (comma-separated) of the owners of the requester VPCs. (i.e., 123456789012,4567890123)", + "Type": "String", + "AllowedPattern": "^(\\d{12})$|^((\\d{12}(,|, ))*\\d{12})$", + "ConstraintDescription": "Must be 12 digits. Additional accounts can be provided, separated by a \"comma\"" + } + }, + "Resources": { + "PeerRole": { + "Type": "AWS::IAM::Role", + "Metadata": { + "cfn_nag": { + "rules_to_suppress": [ + { + "id": "W11", + "reason": "Allow * in resource, as only allowed AWS accounts can assume this role" + } + ] + } + }, + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Effect": "Allow", + "Action": "sts:AssumeRole", + "Principal": { + "AWS": { + "Fn::Split": [ + ",", + { + "Ref": "PeerOwnerIds" + } + ] + } + } + } + ] + }, + "Path": "/", + "Tags": [ + { + "Key": "StackName", + "Value": { + "Ref": "AWS::StackName" + } + } + ], + "Policies": [ + { + "PolicyName": "AcceptVPCPeering", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": "ec2:AcceptVpcPeeringConnection", + "Resource": "*" + } + ] + } + } + ] + } + } + }, + "Outputs": { + "PeerRoleARN": { + "Description": "VPC Peer Role ARN", + "Value": { + "Fn::GetAtt": [ + "PeerRole", + "Arn" + ] + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Accepter-Role.cfn.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Accepter-Role.cfn.yaml new file mode 100644 index 0000000000000000000000000000000000000000..2fc68b93c042de95fb59ee5c4f26deff2e6c31f8 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Accepter-Role.cfn.yaml @@ -0,0 +1,56 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: This template creates an assumable role to be used by the requester account to accept the VPC peering connection. (Accepter Account) + +Metadata: + AWS::CloudFormation::Interface: + ParameterGroups: + - Label: + default: VPC Peering Configuration + Parameters: + - PeerOwnerIds + ParameterLabels: + PeerOwnerIds: + default: Peer Owner IDs + +Parameters: + PeerOwnerIds: + Description: AWS account IDs (comma-separated) of the owners of the requester VPCs. (i.e., 123456789012,4567890123) + Type: String + AllowedPattern: ^(\d{12})$|^((\d{12}(,|, ))*\d{12})$ + ConstraintDescription: Must be 12 digits. Additional accounts can be provided, separated by a "comma" + +Resources: + PeerRole: + Type: AWS::IAM::Role + Metadata: + cfn_nag: + rules_to_suppress: + - id: W11 + reason: Allow * in resource, as only allowed AWS accounts can assume this role + Properties: + AssumeRolePolicyDocument: + Statement: + - Effect: Allow + Action: sts:AssumeRole + Principal: + AWS: !Split + - ',' + - !Ref PeerOwnerIds + Path: / + Tags: + - Key: StackName + Value: !Ref AWS::StackName + Policies: + - PolicyName: AcceptVPCPeering + PolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: ec2:AcceptVpcPeeringConnection + Resource: '*' + +Outputs: + PeerRoleARN: + Description: VPC Peer Role ARN + Value: !GetAtt PeerRole.Arn diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Accepter-Tag.cfn.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Accepter-Tag.cfn.json new file mode 100644 index 0000000000000000000000000000000000000000..0cdea77a7574baa4a173d44f573179c498084b1c --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Accepter-Tag.cfn.json @@ -0,0 +1,298 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "This template uses a custom resource Lambda to apply a Name tag to the VPC peering connection on the Accepter Account.", + "Metadata": { + "AWS::CloudFormation::Interface": { + "ParameterGroups": [ + { + "Label": { + "default": "VPC Peering Configuration" + }, + "Parameters": [ + "PeerName", + "VPCPeeringConnectionId" + ] + }, + { + "Label": { + "default": "Lambda Function" + }, + "Parameters": [ + "LambdaLogLevel", + "LambdaFunctionName", + "LambdaLogsLogGroupRetention", + "LambdaLogsCloudWatchKMSKey" + ] + } + ], + "ParameterLabels": { + "LambdaFunctionName": { + "default": "Lambda Function Name" + }, + "LambdaLogLevel": { + "default": "Lambda Log Level" + }, + "LambdaLogsCloudWatchKMSKey": { + "default": "CloudWatch Logs KMS Key for Lambda logs" + }, + "LambdaLogsLogGroupRetention": { + "default": "Lambda Log Group Retention" + }, + "PeerName": { + "default": "Peer Name" + }, + "VPCPeeringConnectionId": { + "default": "VPC Peering Connection ID" + } + } + } + }, + "Parameters": { + "LambdaFunctionName": { + "Description": "Lambda Function Name for Custom Resource", + "Type": "String", + "Default": "CR-TagVpcPeeringConnections", + "AllowedPattern": "^[\\w-]{1,64}$", + "ConstraintDescription": "Max 64 alphanumeric characters. Also special characters supported [_, -]" + }, + "LambdaLogLevel": { + "Description": "Lambda logging level", + "Type": "String", + "AllowedValues": [ + "INFO", + "DEBUG" + ], + "Default": "INFO" + }, + "LambdaLogsCloudWatchKMSKey": { + "Description": "(Optional) KMS Key ARN to use for encrypting the Lambda logs data. If empty, encryption is enabled with CloudWatch Logs managing the server-side encryption keys.", + "Type": "String", + "AllowedPattern": "^$|^arn:(aws[a-zA-Z-]*)?:kms:[a-z0-9-]+:\\d{12}:key\\/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$", + "ConstraintDescription": "Key ARN example: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab" + }, + "LambdaLogsLogGroupRetention": { + "Description": "Specifies the number of days you want to retain Lambda log events in the CloudWatch Logs", + "Type": "String", + "AllowedValues": [ + 1, + 3, + 5, + 7, + 14, + 30, + 60, + 90, + 120, + 150, + 180, + 365, + 400, + 545, + 731, + 1827, + 3653 + ], + "Default": 14 + }, + "PeerName": { + "Description": "Name of the VPC Peer", + "Type": "String", + "MaxLength": 255 + }, + "VPCPeeringConnectionId": { + "Description": "ID of the VPC Peering Connection", + "Type": "String", + "AllowedPattern": "^pcx-[0-9a-f]{17}$", + "ConstraintDescription": "Must have a prefix of \"pcx-\". Followed by 17 characters (numbers, letters \"a-f\")" + } + }, + "Conditions": { + "LambdaLogsCloudWatchKMSKeyCondition": { + "Fn::Not": [ + { + "Fn::Equals": [ + { + "Ref": "LambdaLogsCloudWatchKMSKey" + }, + "" + ] + } + ] + } + }, + "Resources": { + "TagVpcPeeringConnectionsLambdaLogsLogGroup": { + "Type": "AWS::Logs::LogGroup", + "Properties": { + "LogGroupName": { + "Fn::Sub": "/aws/lambda/${LambdaFunctionName}" + }, + "RetentionInDays": { + "Ref": "LambdaLogsLogGroupRetention" + }, + "KmsKeyId": { + "Fn::If": [ + "LambdaLogsCloudWatchKMSKeyCondition", + { + "Ref": "LambdaLogsCloudWatchKMSKey" + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + }, + "TagVpcPeeringConnectionsLambdaRole": { + "Type": "AWS::IAM::Role", + "Metadata": { + "cfn_nag": { + "rules_to_suppress": [ + { + "id": "W28", + "reason": "The role name is defined to identify automation resources" + } + ] + } + }, + "Properties": { + "RoleName": { + "Fn::Sub": "${LambdaFunctionName}-LambdaRole" + }, + "Description": "Rights to Tag VPC Peering Connection", + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": "sts:AssumeRole", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "Path": "/", + "Tags": [ + { + "Key": "StackName", + "Value": { + "Ref": "AWS::StackName" + } + } + ], + "Policies": [ + { + "PolicyName": "CloudWatchLogGroup", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Sid": "CreateLogGroup", + "Effect": "Allow", + "Action": "logs:CreateLogGroup", + "Resource": { + "Fn::Sub": "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:${TagVpcPeeringConnectionsLambdaLogsLogGroup}" + } + }, + { + "Sid": "CreateLogStreamAndEvents", + "Effect": "Allow", + "Action": [ + "logs:CreateLogStream", + "logs:PutLogEvents" + ], + "Resource": { + "Fn::Sub": "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:${TagVpcPeeringConnectionsLambdaLogsLogGroup}:log-stream:*" + } + } + ] + } + }, + { + "PolicyName": "TagVpcPeeringConnections", + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Sid": "Tagging", + "Effect": "Allow", + "Action": [ + "ec2:CreateTags", + "ec2:DeleteTags" + ], + "Resource": { + "Fn::Sub": "arn:${AWS::Partition}:ec2:${AWS::Region}:${AWS::AccountId}:vpc-peering-connection/*" + } + } + ] + } + } + ] + } + }, + "TagVpcPeeringConnectionsLambdaFunction": { + "Type": "AWS::Lambda::Function", + "Metadata": { + "cfn_nag": { + "rules_to_suppress": [ + { + "id": "W58", + "reason": "Permissions to write to CloudWatch Logs provided by the attached IAM role." + } + ] + }, + "guard": { + "SuppressedRules": [ + "LAMBDA_INSIDE_VPC" + ] + } + }, + "Properties": { + "FunctionName": { + "Ref": "LambdaFunctionName" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "TagVpcPeeringConnectionsLambdaRole", + "Arn" + ] + }, + "Runtime": "python3.12", + "MemorySize": 128, + "Timeout": 120, + "Environment": { + "Variables": { + "LOG_LEVEL": { + "Ref": "LambdaLogLevel" + } + } + }, + "Code": { + "ZipFile": "import cfnresponse, json, os, logging, boto3\n\nLOGGER = logging.getLogger()\nLOGGER.setLevel(logging.INFO)\n\ntry:\n logging.getLogger(\"boto3\").setLevel(logging.CRITICAL)\n\n # Process Environment Variables\n LOGGER.setLevel(os.environ.get(\"LOG_LEVEL\", logging.ERROR))\n\n ec2_client = boto3.client(\"ec2\")\nexcept Exception as error:\n LOGGER.error(error)\n cfnresponse.send(event, context, cfnresponse.FAILED, {})\n raise\n\n\ndef apply_name_tag(resource, name):\n return ec2_client.create_tags(Resources=[resource], Tags=[{\"Key\": \"Name\", \"Value\": name}])\n\n\ndef delete_name_tag(resource):\n return ec2_client.delete_tags(Resources=[resource], Tags=[{\"Key\": \"Name\"}])\n\n\ndef handler(event, context):\n try:\n LOGGER.info(f\"REQUEST RECEIVED: {json.dumps(event, default=str)}\")\n response_data = {}\n physical_resource_id = event.get(\"PhysicalResourceId\")\n resource = event[\"ResourceProperties\"].get(\"Resource\")\n name = event[\"ResourceProperties\"].get(\"Name\")\n\n if event.get(\"RequestType\") in [\"Create\", \"Update\"]:\n response = apply_name_tag(resource, name)\n LOGGER.info(f\"response = {json.dumps(response, default=str)}\")\n if event.get(\"RequestType\") == \"Delete\":\n response = delete_name_tag(resource)\n LOGGER.info(f\"response = {json.dumps(response, default=str)}\")\n\n LOGGER.info(\"Sending Custom Resource Response\")\n cfnresponse.send(event, context, cfnresponse.SUCCESS, response_data, physical_resource_id)\n return\n except Exception as error:\n LOGGER.error(error)\n cfnresponse.send(event, context, cfnresponse.FAILED, {})\n return\n" + } + } + }, + "TagVpcPeeringConnectionsResource": { + "Type": "Custom::TagVpcPeeringConnection", + "Properties": { + "ServiceToken": { + "Fn::GetAtt": [ + "TagVpcPeeringConnectionsLambdaFunction", + "Arn" + ] + }, + "Resource": { + "Ref": "VPCPeeringConnectionId" + }, + "Name": { + "Ref": "PeerName" + } + }, + "Version": "1.0" + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Accepter-Tag.cfn.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Accepter-Tag.cfn.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1580662a00e20a696fce21004c1855aeaac7a471 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Accepter-Tag.cfn.yaml @@ -0,0 +1,232 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: This template uses a custom resource Lambda to apply a Name tag to the VPC peering connection on the Accepter Account. + +Metadata: + AWS::CloudFormation::Interface: + ParameterGroups: + - Label: + default: VPC Peering Configuration + Parameters: + - PeerName + - VPCPeeringConnectionId + - Label: + default: Lambda Function + Parameters: + - LambdaLogLevel + - LambdaFunctionName + - LambdaLogsLogGroupRetention + - LambdaLogsCloudWatchKMSKey + ParameterLabels: + LambdaFunctionName: + default: Lambda Function Name + LambdaLogLevel: + default: Lambda Log Level + LambdaLogsCloudWatchKMSKey: + default: CloudWatch Logs KMS Key for Lambda logs + LambdaLogsLogGroupRetention: + default: Lambda Log Group Retention + PeerName: + default: Peer Name + VPCPeeringConnectionId: + default: VPC Peering Connection ID + +Parameters: + LambdaFunctionName: + Description: Lambda Function Name for Custom Resource + Type: String + Default: CR-TagVpcPeeringConnections + AllowedPattern: ^[\w-]{1,64}$ + ConstraintDescription: Max 64 alphanumeric characters. Also special characters supported [_, -] + + LambdaLogLevel: + Description: Lambda logging level + Type: String + AllowedValues: + - INFO + - DEBUG + Default: INFO + + LambdaLogsCloudWatchKMSKey: + Description: (Optional) KMS Key ARN to use for encrypting the Lambda logs data. If empty, encryption is enabled with CloudWatch Logs managing the server-side encryption keys. + Type: String + AllowedPattern: ^$|^arn:(aws[a-zA-Z-]*)?:kms:[a-z0-9-]+:\d{12}:key\/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$ + ConstraintDescription: 'Key ARN example: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab' + + LambdaLogsLogGroupRetention: + Description: Specifies the number of days you want to retain Lambda log events in the CloudWatch Logs + Type: String + AllowedValues: + - 1 + - 3 + - 5 + - 7 + - 14 + - 30 + - 60 + - 90 + - 120 + - 150 + - 180 + - 365 + - 400 + - 545 + - 731 + - 1827 + - 3653 + Default: 14 + + PeerName: + Description: Name of the VPC Peer + Type: String + MaxLength: 255 + + VPCPeeringConnectionId: + Description: ID of the VPC Peering Connection + Type: String + AllowedPattern: ^pcx-[0-9a-f]{17}$ + ConstraintDescription: Must have a prefix of "pcx-". Followed by 17 characters (numbers, letters "a-f") + +Conditions: + LambdaLogsCloudWatchKMSKeyCondition: !Not + - !Equals + - !Ref LambdaLogsCloudWatchKMSKey + - "" + +Resources: + TagVpcPeeringConnectionsLambdaLogsLogGroup: + Type: AWS::Logs::LogGroup + Properties: + LogGroupName: !Sub /aws/lambda/${LambdaFunctionName} + RetentionInDays: !Ref LambdaLogsLogGroupRetention + KmsKeyId: !If + - LambdaLogsCloudWatchKMSKeyCondition + - !Ref LambdaLogsCloudWatchKMSKey + - !Ref AWS::NoValue + + TagVpcPeeringConnectionsLambdaRole: + Type: AWS::IAM::Role + Metadata: + cfn_nag: + rules_to_suppress: + - id: W28 + reason: The role name is defined to identify automation resources + Properties: + RoleName: !Sub ${LambdaFunctionName}-LambdaRole + Description: Rights to Tag VPC Peering Connection + AssumeRolePolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: sts:AssumeRole + Principal: + Service: + - lambda.amazonaws.com + Path: / + Tags: + - Key: StackName + Value: !Ref AWS::StackName + Policies: + - PolicyName: CloudWatchLogGroup + PolicyDocument: + Version: "2012-10-17" + Statement: + - Sid: CreateLogGroup + Effect: Allow + Action: logs:CreateLogGroup + Resource: !Sub arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:${TagVpcPeeringConnectionsLambdaLogsLogGroup} + - Sid: CreateLogStreamAndEvents + Effect: Allow + Action: + - logs:CreateLogStream + - logs:PutLogEvents + Resource: !Sub arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:${TagVpcPeeringConnectionsLambdaLogsLogGroup}:log-stream:* + - PolicyName: TagVpcPeeringConnections + PolicyDocument: + Version: "2012-10-17" + Statement: + - Sid: Tagging + Effect: Allow + Action: + - ec2:CreateTags + - ec2:DeleteTags + Resource: !Sub arn:${AWS::Partition}:ec2:${AWS::Region}:${AWS::AccountId}:vpc-peering-connection/* + + TagVpcPeeringConnectionsLambdaFunction: + Type: AWS::Lambda::Function + Metadata: + cfn_nag: + rules_to_suppress: + - id: W58 + reason: Permissions to write to CloudWatch Logs provided by the attached IAM role. + guard: + SuppressedRules: + - LAMBDA_INSIDE_VPC + Properties: + FunctionName: !Ref LambdaFunctionName + Handler: index.handler + Role: !GetAtt TagVpcPeeringConnectionsLambdaRole.Arn + Runtime: python3.12 + MemorySize: 128 + Timeout: 120 + Environment: + Variables: + LOG_LEVEL: !Ref LambdaLogLevel + Code: + ZipFile: | + import cfnresponse, json, os, logging, boto3 + + LOGGER = logging.getLogger() + LOGGER.setLevel(logging.INFO) + + try: + logging.getLogger("boto3").setLevel(logging.CRITICAL) + + # Process Environment Variables + LOGGER.setLevel(os.environ.get("LOG_LEVEL", logging.ERROR)) + + ec2_client = boto3.client("ec2") + except Exception as error: + LOGGER.error(error) + cfnresponse.send(event, context, cfnresponse.FAILED, {}) + raise + + + def apply_name_tag(resource, name): + return ec2_client.create_tags(Resources=[resource], Tags=[{"Key": "Name", "Value": name}]) + + + def delete_name_tag(resource): + return ec2_client.delete_tags(Resources=[resource], Tags=[{"Key": "Name"}]) + + + def handler(event, context): + try: + LOGGER.info(f"REQUEST RECEIVED: {json.dumps(event, default=str)}") + response_data = {} + physical_resource_id = event.get("PhysicalResourceId") + resource = event["ResourceProperties"].get("Resource") + name = event["ResourceProperties"].get("Name") + + if event.get("RequestType") in ["Create", "Update"]: + response = apply_name_tag(resource, name) + LOGGER.info(f"response = {json.dumps(response, default=str)}") + if event.get("RequestType") == "Delete": + response = delete_name_tag(resource) + LOGGER.info(f"response = {json.dumps(response, default=str)}") + + LOGGER.info("Sending Custom Resource Response") + cfnresponse.send(event, context, cfnresponse.SUCCESS, response_data, physical_resource_id) + return + except Exception as error: + LOGGER.error(error) + cfnresponse.send(event, context, cfnresponse.FAILED, {}) + return + + TagVpcPeeringConnectionsResource: + Type: Custom::TagVpcPeeringConnection + Properties: + ServiceToken: !GetAtt TagVpcPeeringConnectionsLambdaFunction.Arn + Resource: !Ref VPCPeeringConnectionId + Name: !Ref PeerName + Version: "1.0" diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Accepter.main.cfn.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Accepter.main.cfn.json new file mode 100644 index 0000000000000000000000000000000000000000..d58ec664e6d8100f412d6c998d7b83483db92361 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Accepter.main.cfn.json @@ -0,0 +1,315 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "This template accomplishes the following tasks: (1) applies a name tag to the specified VPC peering connection. (2) updates the specified route tables and security groups to allow communications via the VPC peering connection. Note, this is for the VPC Peering Accepter account.", + "Metadata": { + "AWS::CloudFormation::Interface": { + "ParameterGroups": [ + { + "Label": { + "default": "Network Configuration" + }, + "Parameters": [ + "RouteTableIds", + "NumberOfRouteTables", + "VPCPeeringConnectionId" + ] + }, + { + "Label": { + "default": "Security Groups Configuration" + }, + "Parameters": [ + "SecurityGroupIds", + "NumberOfSecurityGroups" + ] + }, + { + "Label": { + "default": "VPC Peering Configuration" + }, + "Parameters": [ + "PeerName", + "PeerVPCCIDR" + ] + }, + { + "Label": { + "default": "Lambda Function" + }, + "Parameters": [ + "LambdaLogLevel", + "LambdaRoleName", + "LambdaFunctionName", + "LambdaLogsLogGroupRetention", + "LambdaLogsCloudWatchKMSKey" + ] + } + ], + "ParameterLabels": { + "LambdaFunctionName": { + "default": "Lambda Function Name" + }, + "LambdaLogLevel": { + "default": "Lambda Log Level" + }, + "LambdaLogsCloudWatchKMSKey": { + "default": "CloudWatch Logs KMS Key for Lambda logs" + }, + "LambdaLogsLogGroupRetention": { + "default": "Lambda Log Group Retention" + }, + "LambdaRoleName": { + "default": "Lambda Role Name" + }, + "NumberOfRouteTables": { + "default": "Number of Route Tables" + }, + "NumberOfSecurityGroups": { + "default": "Number of Security Groups" + }, + "PeerName": { + "default": "Peer Name" + }, + "PeerVPCCIDR": { + "default": "Peer VPC CIDR" + }, + "RouteTableIds": { + "default": "Route Table IDs" + }, + "SecurityGroupIds": { + "default": "Security Group IDs" + }, + "TemplatesS3BucketName": { + "default": "Templates S3 Bucket Name" + }, + "TemplatesS3BucketRegion": { + "default": "Templates S3 bucket region" + }, + "TemplatesS3KeyPrefix": { + "default": "Templates S3 Key Prefix" + }, + "VPCPeeringConnectionId": { + "default": "VPC Peering Connection ID" + } + } + } + }, + "Parameters": { + "LambdaFunctionName": { + "Description": "Lambda Function Name for Custom Resource", + "Type": "String", + "Default": "CR-TagVpcPeeringConnections", + "AllowedPattern": "^[\\w-]{1,64}$", + "ConstraintDescription": "Max 64 alphanumeric characters. Also special characters supported [_, -]" + }, + "LambdaLogLevel": { + "Type": "String", + "AllowedValues": [ + "INFO", + "DEBUG" + ], + "Default": "INFO" + }, + "LambdaLogsCloudWatchKMSKey": { + "Description": "(Optional) KMS Key ARN to use for encrypting the Lambda logs data. If empty, encryption is enabled with CloudWatch Logs managing the server-side encryption keys.", + "Type": "String", + "Default": "", + "AllowedPattern": "^$|^arn:(aws[a-zA-Z-]*)?:kms:[a-z0-9-]+:\\d{12}:key\\/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$", + "ConstraintDescription": "Key ARN example: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab" + }, + "LambdaLogsLogGroupRetention": { + "Description": "Specifies the number of days you want to retain Lambda log events in the CloudWatch Logs", + "Type": "String", + "AllowedValues": [ + 1, + 3, + 5, + 7, + 14, + 30, + 60, + 90, + 120, + 150, + 180, + 365, + 400, + 545, + 731, + 1827, + 3653 + ], + "Default": 14 + }, + "LambdaRoleName": { + "Description": "Lambda Execution Role Name for the Custom Resource to Tag VPC Peering Connections", + "Type": "String", + "Default": "Lambda-Role-CR-TagVpcPeeringConnections", + "AllowedPattern": "^[\\w+=,.@-]{1,64}$", + "ConstraintDescription": "Max 64 alphanumeric characters. Also special characters supported [+, =, ., @, -]" + }, + "NumberOfRouteTables": { + "Description": "Number of Route Table IDs to update. This must match your items in the comma-separated list of RouteTableIds parameter.", + "Type": "String", + "AllowedValues": [ + 1, + 2, + 3, + 4, + 5, + 6 + ] + }, + "NumberOfSecurityGroups": { + "Description": "Number of Security Group IDs. This must match your selections in the list of SecurityGroupIds parameter.", + "Type": "String", + "AllowedValues": [ + 1, + 2, + 3, + 4, + 5, + 6 + ] + }, + "PeerName": { + "Description": "Name of the VPC Peer", + "Type": "String", + "MaxLength": 255 + }, + "PeerVPCCIDR": { + "Description": "CIDR of the VPC Peer", + "Type": "String", + "AllowedPattern": "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\\/(1[6-9]|2[0-8]))$", + "ConstraintDescription": "CIDR block parameter must be in the form x.x.x.x/16-28" + }, + "RouteTableIds": { + "Description": "Route Table IDs that will be updated to allow communications via the VPC peering connection. Note, the logical order is preserved.", + "Type": "String", + "AllowedPattern": "^(rtb-[0-9a-f]{17})$|^((rtb-[0-9a-f]{17}(,|, ))*rtb-[0-9a-f]{17})$", + "ConstraintDescription": "Must have a prefix of \"rtb-\". Followed by 17 characters (numbers, letters \"a-f\"). Additional route tables can be provided, separated by a \"comma\"." + }, + "SecurityGroupIds": { + "Description": "Security Group IDs that will be updated to allow communications via the VPC peering connection. Note, the logical order is preserved.", + "Type": "List" + }, + "TemplatesS3BucketName": { + "Description": "Templates S3 bucket name for the CloudFormation templates. S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-).", + "Type": "String", + "AllowedPattern": "^(?=^.{3,63}$)(?!.*[.-]{2})(?!.*[--]{2})(?!^(?:(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\\.(?!$)|$)){4}$)(^(([a-z0-9]|[a-z0-9][a-z0-9\\-]*[a-z0-9])\\.)*([a-z0-9]|[a-z0-9][a-z0-9\\-]*[a-z0-9])$)", + "ConstraintDescription": "Templates S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-)." + }, + "TemplatesS3BucketRegion": { + "Description": "AWS Region where the S3 bucket (TemplatesS3BucketName) is hosted.", + "Type": "String" + }, + "TemplatesS3KeyPrefix": { + "Description": "S3 key prefix for the AWS CloudFormation templates. Key prefix can include numbers, lowercase letters, uppercase letters, hyphens (-), and forward slash (/).", + "Type": "String", + "AllowedPattern": "^[0-9a-zA-Z-/]*$", + "ConstraintDescription": "Templates key prefix can include numbers, lowercase letters, uppercase letters, hyphens (-), and forward slash (/)." + }, + "VPCPeeringConnectionId": { + "Description": "ID of the VPC Peering Connection", + "Type": "String", + "AllowedPattern": "^pcx-[0-9a-f]{17}$", + "ConstraintDescription": "Must have a prefix of \"pcx-\". Followed by 17 characters (numbers, letters \"a-f\")" + } + }, + "Resources": { + "VPCPeeringAccepterTagStack": { + "Type": "AWS::CloudFormation::Stack", + "Properties": { + "TemplateURL": { + "Fn::Sub": [ + "https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${S3KeyPrefix}templates/VPCPeering-Accepter-Tag.cfn.yaml", + { + "S3Bucket": { + "Ref": "TemplatesS3BucketName" + }, + "S3KeyPrefix": { + "Ref": "TemplatesS3KeyPrefix" + }, + "S3Region": { + "Ref": "TemplatesS3BucketRegion" + } + } + ] + }, + "Parameters": { + "LambdaFunctionName": { + "Ref": "LambdaFunctionName" + }, + "LambdaLogLevel": { + "Ref": "LambdaLogLevel" + }, + "LambdaLogsCloudWatchKMSKey": { + "Ref": "LambdaLogsCloudWatchKMSKey" + }, + "LambdaLogsLogGroupRetention": { + "Ref": "LambdaLogsLogGroupRetention" + }, + "LambdaRoleName": { + "Ref": "LambdaRoleName" + }, + "PeerName": { + "Ref": "PeerName" + }, + "VPCPeeringConnectionId": { + "Ref": "VPCPeeringConnectionId" + } + } + } + }, + "VPCPeeringUpdatesStack": { + "Type": "AWS::CloudFormation::Stack", + "DependsOn": "VPCPeeringAccepterTagStack", + "Properties": { + "TemplateURL": { + "Fn::Sub": [ + "https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${S3KeyPrefix}templates/VPCPeering-Updates.cfn.yaml", + { + "S3Bucket": { + "Ref": "TemplatesS3BucketName" + }, + "S3KeyPrefix": { + "Ref": "TemplatesS3KeyPrefix" + }, + "S3Region": { + "Ref": "TemplatesS3BucketRegion" + } + } + ] + }, + "Parameters": { + "NumberOfRouteTables": { + "Ref": "NumberOfRouteTables" + }, + "NumberOfSecurityGroups": { + "Ref": "NumberOfSecurityGroups" + }, + "PeerName": { + "Ref": "PeerName" + }, + "PeerVPCCIDR": { + "Ref": "PeerVPCCIDR" + }, + "RouteTableIds": { + "Ref": "RouteTableIds" + }, + "SecurityGroupIds": { + "Fn::Join": [ + ",", + { + "Ref": "SecurityGroupIds" + } + ] + }, + "VPCPeeringConnectionId": { + "Ref": "VPCPeeringConnectionId" + } + } + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Accepter.main.cfn.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Accepter.main.cfn.yaml new file mode 100644 index 0000000000000000000000000000000000000000..0de1ecaf00956447d323be9b2c2d765989a8a8ea --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Accepter.main.cfn.yaml @@ -0,0 +1,217 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: 'This template accomplishes the following tasks: (1) applies a name tag to the specified VPC peering connection. (2) updates the specified route tables and security groups to allow communications via the VPC peering connection. Note, this is for the VPC Peering Accepter account.' + +Metadata: + AWS::CloudFormation::Interface: + ParameterGroups: + - Label: + default: Network Configuration + Parameters: + - RouteTableIds + - NumberOfRouteTables + - VPCPeeringConnectionId + - Label: + default: Security Groups Configuration + Parameters: + - SecurityGroupIds + - NumberOfSecurityGroups + - Label: + default: VPC Peering Configuration + Parameters: + - PeerName + - PeerVPCCIDR + - Label: + default: Lambda Function + Parameters: + - LambdaLogLevel + - LambdaRoleName + - LambdaFunctionName + - LambdaLogsLogGroupRetention + - LambdaLogsCloudWatchKMSKey + ParameterLabels: + LambdaFunctionName: + default: Lambda Function Name + LambdaLogLevel: + default: Lambda Log Level + LambdaLogsCloudWatchKMSKey: + default: CloudWatch Logs KMS Key for Lambda logs + LambdaLogsLogGroupRetention: + default: Lambda Log Group Retention + LambdaRoleName: + default: Lambda Role Name + NumberOfRouteTables: + default: Number of Route Tables + NumberOfSecurityGroups: + default: Number of Security Groups + PeerName: + default: Peer Name + PeerVPCCIDR: + default: Peer VPC CIDR + RouteTableIds: + default: Route Table IDs + SecurityGroupIds: + default: Security Group IDs + TemplatesS3BucketName: + default: Templates S3 Bucket Name + TemplatesS3BucketRegion: + default: Templates S3 bucket region + TemplatesS3KeyPrefix: + default: Templates S3 Key Prefix + VPCPeeringConnectionId: + default: VPC Peering Connection ID + +Parameters: + LambdaFunctionName: + Description: Lambda Function Name for Custom Resource + Type: String + Default: CR-TagVpcPeeringConnections + AllowedPattern: ^[\w-]{1,64}$ + ConstraintDescription: Max 64 alphanumeric characters. Also special characters supported [_, -] + + LambdaLogLevel: + Type: String + AllowedValues: + - INFO + - DEBUG + Default: INFO + + LambdaLogsCloudWatchKMSKey: + Description: (Optional) KMS Key ARN to use for encrypting the Lambda logs data. If empty, encryption is enabled with CloudWatch Logs managing the server-side encryption keys. + Type: String + Default: "" + AllowedPattern: ^$|^arn:(aws[a-zA-Z-]*)?:kms:[a-z0-9-]+:\d{12}:key\/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$ + ConstraintDescription: 'Key ARN example: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab' + + LambdaLogsLogGroupRetention: + Description: Specifies the number of days you want to retain Lambda log events in the CloudWatch Logs + Type: String + AllowedValues: + - 1 + - 3 + - 5 + - 7 + - 14 + - 30 + - 60 + - 90 + - 120 + - 150 + - 180 + - 365 + - 400 + - 545 + - 731 + - 1827 + - 3653 + Default: 14 + + LambdaRoleName: + Description: Lambda Execution Role Name for the Custom Resource to Tag VPC Peering Connections + Type: String + Default: Lambda-Role-CR-TagVpcPeeringConnections + AllowedPattern: ^[\w+=,.@-]{1,64}$ + ConstraintDescription: Max 64 alphanumeric characters. Also special characters supported [+, =, ., @, -] + + NumberOfRouteTables: + Description: Number of Route Table IDs to update. This must match your items in the comma-separated list of RouteTableIds parameter. + Type: String + AllowedValues: + - 1 + - 2 + - 3 + - 4 + - 5 + - 6 + + NumberOfSecurityGroups: + Description: Number of Security Group IDs. This must match your selections in the list of SecurityGroupIds parameter. + Type: String + AllowedValues: + - 1 + - 2 + - 3 + - 4 + - 5 + - 6 + + PeerName: + Description: Name of the VPC Peer + Type: String + MaxLength: 255 + + PeerVPCCIDR: + Description: CIDR of the VPC Peer + Type: String + AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(1[6-9]|2[0-8]))$ + ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28 + + RouteTableIds: + Description: Route Table IDs that will be updated to allow communications via the VPC peering connection. Note, the logical order is preserved. + Type: String + AllowedPattern: ^(rtb-[0-9a-f]{17})$|^((rtb-[0-9a-f]{17}(,|, ))*rtb-[0-9a-f]{17})$ + ConstraintDescription: Must have a prefix of "rtb-". Followed by 17 characters (numbers, letters "a-f"). Additional route tables can be provided, separated by a "comma". + + SecurityGroupIds: + Description: Security Group IDs that will be updated to allow communications via the VPC peering connection. Note, the logical order is preserved. + Type: List + + TemplatesS3BucketName: + Description: Templates S3 bucket name for the CloudFormation templates. S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-). + Type: String + AllowedPattern: ^(?=^.{3,63}$)(?!.*[.-]{2})(?!.*[--]{2})(?!^(?:(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\.(?!$)|$)){4}$)(^(([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])\.)*([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])$) + ConstraintDescription: Templates S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-). + + TemplatesS3BucketRegion: + Description: AWS Region where the S3 bucket (TemplatesS3BucketName) is hosted. + Type: String + + TemplatesS3KeyPrefix: + Description: S3 key prefix for the AWS CloudFormation templates. Key prefix can include numbers, lowercase letters, uppercase letters, hyphens (-), and forward slash (/). + Type: String + AllowedPattern: ^[0-9a-zA-Z-/]*$ + ConstraintDescription: Templates key prefix can include numbers, lowercase letters, uppercase letters, hyphens (-), and forward slash (/). + + VPCPeeringConnectionId: + Description: ID of the VPC Peering Connection + Type: String + AllowedPattern: ^pcx-[0-9a-f]{17}$ + ConstraintDescription: Must have a prefix of "pcx-". Followed by 17 characters (numbers, letters "a-f") + +Resources: + VPCPeeringAccepterTagStack: + Type: AWS::CloudFormation::Stack + Properties: + TemplateURL: !Sub + - https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${S3KeyPrefix}templates/VPCPeering-Accepter-Tag.cfn.yaml + - S3Bucket: !Ref TemplatesS3BucketName + S3KeyPrefix: !Ref TemplatesS3KeyPrefix + S3Region: !Ref TemplatesS3BucketRegion + Parameters: + LambdaFunctionName: !Ref LambdaFunctionName + LambdaLogLevel: !Ref LambdaLogLevel + LambdaLogsCloudWatchKMSKey: !Ref LambdaLogsCloudWatchKMSKey + LambdaLogsLogGroupRetention: !Ref LambdaLogsLogGroupRetention + LambdaRoleName: !Ref LambdaRoleName + PeerName: !Ref PeerName + VPCPeeringConnectionId: !Ref VPCPeeringConnectionId + + VPCPeeringUpdatesStack: + Type: AWS::CloudFormation::Stack + DependsOn: VPCPeeringAccepterTagStack + Properties: + TemplateURL: !Sub + - https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${S3KeyPrefix}templates/VPCPeering-Updates.cfn.yaml + - S3Bucket: !Ref TemplatesS3BucketName + S3KeyPrefix: !Ref TemplatesS3KeyPrefix + S3Region: !Ref TemplatesS3BucketRegion + Parameters: + NumberOfRouteTables: !Ref NumberOfRouteTables + NumberOfSecurityGroups: !Ref NumberOfSecurityGroups + PeerName: !Ref PeerName + PeerVPCCIDR: !Ref PeerVPCCIDR + RouteTableIds: !Ref RouteTableIds + SecurityGroupIds: !Join + - ',' + - !Ref SecurityGroupIds + VPCPeeringConnectionId: !Ref VPCPeeringConnectionId diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Requester-Setup.cfn.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Requester-Setup.cfn.json new file mode 100644 index 0000000000000000000000000000000000000000..87f80a9056183ad9c383fa3b4cd13b2a772e0bc0 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Requester-Setup.cfn.json @@ -0,0 +1,158 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "This templates creates a VPC Peering connection. (Requester Account)", + "Metadata": { + "AWS::CloudFormation::Interface": { + "ParameterGroups": [ + { + "Label": { + "default": "Network Configuration" + }, + "Parameters": [ + "VPCID" + ] + }, + { + "Label": { + "default": "VPC Peering Configuration" + }, + "Parameters": [ + "PeerName", + "PeerOwnerId", + "PeerRoleARN", + "PeerVPCID" + ] + } + ], + "ParameterLabels": { + "PeerName": { + "default": "Peer Name" + }, + "PeerOwnerId": { + "default": "Peer Owner ID" + }, + "PeerRoleARN": { + "default": "Peer Role ARN" + }, + "PeerVPCID": { + "default": "Peer VPC ID" + }, + "VPCID": { + "default": "VPC ID" + } + } + } + }, + "Parameters": { + "PeerName": { + "Description": "Name of the VPC Peer", + "Type": "String", + "MaxLength": 255 + }, + "PeerOwnerId": { + "Description": "AWS account ID of the owner of the accepter VPC", + "Type": "String", + "AllowedPattern": "^\\d{12}$", + "ConstraintDescription": "Must be 12 digits." + }, + "PeerRoleARN": { + "Description": "ARN of the VPC peer role for the peering connection in another AWS account. Required when you are peering a VPC in a different AWS account.", + "Type": "String", + "AllowedPattern": "^arn:(aws[a-zA-Z-]*)?:iam::\\d{12}:role\\/([\\w+=,.@-]*\\/)*[\\w+=,.@-]+" + }, + "PeerVPCID": { + "Description": "ID of the VPC with which you are creating the VPC peering connection", + "Type": "String", + "AllowedPattern": "^vpc-[0-9a-f]{17}$", + "ConstraintDescription": "Must have a prefix of \"vpc-\". Followed by 17 characters (numbers, letters \"a-f\")" + }, + "VPCID": { + "Description": "ID of the VPC", + "Type": "AWS::EC2::VPC::Id" + } + }, + "Rules": { + "PeerRoleValidation": { + "RuleCondition": { + "Fn::Equals": [ + { + "Ref": "PeerRoleARN" + }, + "" + ] + }, + "Assertions": [ + { + "AssetDescription": "ARN of the VPC peer role is required when you are peering a VPC in a different AWS account.", + "Assert": { + "Fn::Equals": [ + { + "Ref": "PeerOwnerId" + }, + { + "Ref": "AWS::AccountId" + } + ] + } + } + ] + } + }, + "Conditions": { + "PeerRoleCondition": { + "Fn::Not": [ + { + "Fn::Equals": [ + { + "Ref": "PeerRoleARN" + }, + "" + ] + } + ] + } + }, + "Resources": { + "VPCPeeringConnection": { + "Type": "AWS::EC2::VPCPeeringConnection", + "Properties": { + "VpcId": { + "Ref": "VPCID" + }, + "PeerVpcId": { + "Ref": "PeerVPCID" + }, + "PeerOwnerId": { + "Ref": "PeerOwnerId" + }, + "PeerRoleArn": { + "Fn::If": [ + "PeerRoleCondition", + { + "Ref": "PeerRoleARN" + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + "Tags": [ + { + "Key": "Name", + "Value": { + "Ref": "PeerName" + } + } + ] + } + } + }, + "Outputs": { + "VPCPeeringConnectionId": { + "Description": "VPC Peering Connection ID", + "Value": { + "Ref": "VPCPeeringConnection" + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Requester-Setup.cfn.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Requester-Setup.cfn.yaml new file mode 100644 index 0000000000000000000000000000000000000000..5e899b6edd367538788555803e4749d9cd9824bf --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Requester-Setup.cfn.yaml @@ -0,0 +1,93 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: This templates creates a VPC Peering connection. (Requester Account) + +Metadata: + AWS::CloudFormation::Interface: + ParameterGroups: + - Label: + default: Network Configuration + Parameters: + - VPCID + - Label: + default: VPC Peering Configuration + Parameters: + - PeerName + - PeerOwnerId + - PeerRoleARN + - PeerVPCID + ParameterLabels: + PeerName: + default: Peer Name + PeerOwnerId: + default: Peer Owner ID + PeerRoleARN: + default: Peer Role ARN + PeerVPCID: + default: Peer VPC ID + VPCID: + default: VPC ID + +Parameters: + PeerName: + Description: Name of the VPC Peer + Type: String + MaxLength: 255 + + PeerOwnerId: + Description: AWS account ID of the owner of the accepter VPC + Type: String + AllowedPattern: ^\d{12}$ + ConstraintDescription: Must be 12 digits. + + PeerRoleARN: + Description: ARN of the VPC peer role for the peering connection in another AWS account. Required when you are peering a VPC in a different AWS account. + Type: String + AllowedPattern: ^arn:(aws[a-zA-Z-]*)?:iam::\d{12}:role\/([\w+=,.@-]*\/)*[\w+=,.@-]+ + + PeerVPCID: + Description: ID of the VPC with which you are creating the VPC peering connection + Type: String + AllowedPattern: ^vpc-[0-9a-f]{17}$ + ConstraintDescription: Must have a prefix of "vpc-". Followed by 17 characters (numbers, letters "a-f") + + VPCID: + Description: ID of the VPC + Type: AWS::EC2::VPC::Id + +Rules: + PeerRoleValidation: + RuleCondition: !Equals + - !Ref PeerRoleARN + - "" + Assertions: + - AssetDescription: ARN of the VPC peer role is required when you are peering a VPC in a different AWS account. + Assert: !Equals + - !Ref PeerOwnerId + - !Ref AWS::AccountId + +Conditions: + PeerRoleCondition: !Not + - !Equals + - !Ref PeerRoleARN + - "" + +Resources: + VPCPeeringConnection: + Type: AWS::EC2::VPCPeeringConnection + Properties: + VpcId: !Ref VPCID + PeerVpcId: !Ref PeerVPCID + PeerOwnerId: !Ref PeerOwnerId + PeerRoleArn: !If + - PeerRoleCondition + - !Ref PeerRoleARN + - !Ref AWS::NoValue + Tags: + - Key: Name + Value: !Ref PeerName + +Outputs: + VPCPeeringConnectionId: + Description: VPC Peering Connection ID + Value: !Ref VPCPeeringConnection diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Requester.main.cfn.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Requester.main.cfn.json new file mode 100644 index 0000000000000000000000000000000000000000..e8d8dfb95d03a71d4d63c2b1a53b38873c9858d7 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Requester.main.cfn.json @@ -0,0 +1,285 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "This template accomplishes the following tasks: (1) creates a VPC peering connection. (2) updates the specified route tables and security groups to allow communications via the VPC peering connection. Note, this is for the VPC Peering Requester account.", + "Metadata": { + "AWS::CloudFormation::Interface": { + "ParameterGroups": [ + { + "Label": { + "default": "Network Configuration" + }, + "Parameters": [ + "RouteTableIds", + "NumberOfRouteTables", + "VPCID" + ] + }, + { + "Label": { + "default": "Security Groups Configuration" + }, + "Parameters": [ + "SecurityGroupIds", + "NumberOfSecurityGroups" + ] + }, + { + "Label": { + "default": "VPC Peering Configuration" + }, + "Parameters": [ + "PeerName", + "PeerOwnerId", + "PeerRoleARN", + "PeerVPCID", + "PeerVPCCIDR" + ] + } + ], + "ParameterLabels": { + "NumberOfRouteTables": { + "default": "Number of Route Tables" + }, + "NumberOfSecurityGroups": { + "default": "Number of Security Groups" + }, + "PeerName": { + "default": "Peer Name" + }, + "PeerOwnerId": { + "default": "Peer Owner ID" + }, + "PeerRoleARN": { + "default": "Peer Role ARN" + }, + "PeerVPCCIDR": { + "default": "Peer VPC CIDR" + }, + "PeerVPCID": { + "default": "Peer VPC ID" + }, + "RouteTableIds": { + "default": "Route Table IDs" + }, + "SecurityGroupIds": { + "default": "Security Group IDs" + }, + "TemplatesS3BucketName": { + "default": "Templates S3 Bucket Name" + }, + "TemplatesS3BucketRegion": { + "default": "Templates S3 bucket region" + }, + "TemplatesS3KeyPrefix": { + "default": "Templates S3 Key Prefix" + }, + "VPCID": { + "default": "VPC ID" + } + } + } + }, + "Parameters": { + "NumberOfRouteTables": { + "Description": "Number of Route Table IDs to update. This must match your items in the comma-separated list of RouteTableIds parameter.", + "Type": "String", + "AllowedValues": [ + 1, + 2, + 3, + 4, + 5, + 6 + ] + }, + "NumberOfSecurityGroups": { + "Description": "Number of Security Group IDs. This must match your selections in the list of SecurityGroupIds parameter.", + "Type": "String", + "AllowedValues": [ + 1, + 2, + 3, + 4, + 5, + 6 + ] + }, + "PeerName": { + "Description": "Name of the VPC Peer", + "Type": "String", + "MaxLength": 255 + }, + "PeerOwnerId": { + "Description": "AWS account ID of the owner of the accepter VPC", + "Type": "String", + "AllowedPattern": "^\\d{12}$", + "ConstraintDescription": "Must be 12 digits." + }, + "PeerRoleARN": { + "Description": "ARN of the VPC peer role for the peering connection in another AWS account. Required when you are peering a VPC in a different AWS account.", + "Type": "String", + "AllowedPattern": "^arn:(aws[a-zA-Z-]*)?:iam::\\d{12}:role\\/([\\w+=,.@-]*\\/)*[\\w+=,.@-]+" + }, + "PeerVPCCIDR": { + "Description": "CIDR of the VPC Peer", + "Type": "String", + "AllowedPattern": "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\\/(1[6-9]|2[0-8]))$", + "ConstraintDescription": "CIDR block parameter must be in the form x.x.x.x/16-28" + }, + "PeerVPCID": { + "Description": "ID of the VPC with which you are creating the VPC peering connection", + "Type": "String", + "AllowedPattern": "^vpc-[0-9a-f]{17}$", + "ConstraintDescription": "Must have a prefix of \"vpc-\". Followed by 17 characters (numbers, letters \"a-f\")" + }, + "RouteTableIds": { + "Description": "Route Table IDs that will be updated to allow communications via the VPC peering connection. Note, the logical order is preserved.", + "Type": "String", + "AllowedPattern": "^(rtb-[0-9a-f]{17})$|^((rtb-[0-9a-f]{17}(,|, ))*rtb-[0-9a-f]{17})$", + "ConstraintDescription": "Must have a prefix of \"rtb-\". Followed by 17 characters (numbers, letters \"a-f\"). Additional route tables can be provided, separated by a \"comma\"." + }, + "SecurityGroupIds": { + "Description": "Security Group IDs that will be updated to allow communications via the VPC peering connection. Note, the logical order is preserved.", + "Type": "List" + }, + "TemplatesS3BucketName": { + "Description": "Templates S3 bucket name for the CloudFormation templates. S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-).", + "Type": "String", + "AllowedPattern": "^(?=^.{3,63}$)(?!.*[.-]{2})(?!.*[--]{2})(?!^(?:(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\\.(?!$)|$)){4}$)(^(([a-z0-9]|[a-z0-9][a-z0-9\\-]*[a-z0-9])\\.)*([a-z0-9]|[a-z0-9][a-z0-9\\-]*[a-z0-9])$)", + "ConstraintDescription": "Templates S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-)." + }, + "TemplatesS3BucketRegion": { + "Description": "AWS Region where the S3 bucket (TemplatesS3BucketName) is hosted.", + "Type": "String" + }, + "TemplatesS3KeyPrefix": { + "Description": "S3 key prefix for the AWS CloudFormation templates. Key prefix can include numbers, lowercase letters, uppercase letters, hyphens (-), and forward slash (/).", + "Type": "String", + "AllowedPattern": "^[0-9a-zA-Z-/]*$", + "ConstraintDescription": "Templates key prefix can include numbers, lowercase letters, uppercase letters, hyphens (-), and forward slash (/)." + }, + "VPCID": { + "Description": "ID of the VPC", + "Type": "AWS::EC2::VPC::Id" + } + }, + "Rules": { + "PeerRoleValidation": { + "RuleCondition": { + "Fn::Equals": [ + { + "Ref": "PeerRoleARN" + }, + "" + ] + }, + "Assertions": [ + { + "AssetDescription": "ARN of the VPC peer role is required when you are peering a VPC in a different AWS account.", + "Assert": { + "Fn::Equals": [ + { + "Ref": "PeerOwnerId" + }, + { + "Ref": "AWS::AccountId" + } + ] + } + } + ] + } + }, + "Resources": { + "VPCPeeringRequesterSetupStack": { + "Type": "AWS::CloudFormation::Stack", + "Properties": { + "TemplateURL": { + "Fn::Sub": [ + "https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${S3KeyPrefix}templates/VPCPeering-Requester-Setup.cfn.yaml", + { + "S3Bucket": { + "Ref": "TemplatesS3BucketName" + }, + "S3KeyPrefix": { + "Ref": "TemplatesS3KeyPrefix" + }, + "S3Region": { + "Ref": "TemplatesS3BucketRegion" + } + } + ] + }, + "Parameters": { + "PeerName": { + "Ref": "PeerName" + }, + "PeerOwnerId": { + "Ref": "PeerOwnerId" + }, + "PeerRoleARN": { + "Ref": "PeerRoleARN" + }, + "PeerVPCID": { + "Ref": "PeerVPCID" + }, + "VPCID": { + "Ref": "VPCID" + } + } + } + }, + "VPCPeeringUpdatesStack": { + "Type": "AWS::CloudFormation::Stack", + "Properties": { + "TemplateURL": { + "Fn::Sub": [ + "https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${S3KeyPrefix}templates/VPCPeering-Updates.cfn.yaml", + { + "S3Bucket": { + "Ref": "TemplatesS3BucketName" + }, + "S3KeyPrefix": { + "Ref": "TemplatesS3KeyPrefix" + }, + "S3Region": { + "Ref": "TemplatesS3BucketRegion" + } + } + ] + }, + "Parameters": { + "NumberOfRouteTables": { + "Ref": "NumberOfRouteTables" + }, + "NumberOfSecurityGroups": { + "Ref": "NumberOfSecurityGroups" + }, + "PeerName": { + "Ref": "PeerName" + }, + "PeerVPCCIDR": { + "Ref": "PeerVPCCIDR" + }, + "RouteTableIds": { + "Ref": "RouteTableIds" + }, + "SecurityGroupIds": { + "Fn::Join": [ + ",", + { + "Ref": "SecurityGroupIds" + } + ] + }, + "VPCPeeringConnectionId": { + "Fn::GetAtt": [ + "VPCPeeringRequesterSetupStack", + "Outputs.VPCPeeringConnectionId" + ] + } + } + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Requester.main.cfn.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Requester.main.cfn.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e51a4cd2ff580307953e2f541174151f4fe2f52e --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Requester.main.cfn.yaml @@ -0,0 +1,180 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: 'This template accomplishes the following tasks: (1) creates a VPC peering connection. (2) updates the specified route tables and security groups to allow communications via the VPC peering connection. Note, this is for the VPC Peering Requester account.' + +Metadata: + AWS::CloudFormation::Interface: + ParameterGroups: + - Label: + default: Network Configuration + Parameters: + - RouteTableIds + - NumberOfRouteTables + - VPCID + - Label: + default: Security Groups Configuration + Parameters: + - SecurityGroupIds + - NumberOfSecurityGroups + - Label: + default: VPC Peering Configuration + Parameters: + - PeerName + - PeerOwnerId + - PeerRoleARN + - PeerVPCID + - PeerVPCCIDR + ParameterLabels: + NumberOfRouteTables: + default: Number of Route Tables + NumberOfSecurityGroups: + default: Number of Security Groups + PeerName: + default: Peer Name + PeerOwnerId: + default: Peer Owner ID + PeerRoleARN: + default: Peer Role ARN + PeerVPCCIDR: + default: Peer VPC CIDR + PeerVPCID: + default: Peer VPC ID + RouteTableIds: + default: Route Table IDs + SecurityGroupIds: + default: Security Group IDs + TemplatesS3BucketName: + default: Templates S3 Bucket Name + TemplatesS3BucketRegion: + default: Templates S3 bucket region + TemplatesS3KeyPrefix: + default: Templates S3 Key Prefix + VPCID: + default: VPC ID + +Parameters: + NumberOfRouteTables: + Description: Number of Route Table IDs to update. This must match your items in the comma-separated list of RouteTableIds parameter. + Type: String + AllowedValues: + - 1 + - 2 + - 3 + - 4 + - 5 + - 6 + + NumberOfSecurityGroups: + Description: Number of Security Group IDs. This must match your selections in the list of SecurityGroupIds parameter. + Type: String + AllowedValues: + - 1 + - 2 + - 3 + - 4 + - 5 + - 6 + + PeerName: + Description: Name of the VPC Peer + Type: String + MaxLength: 255 + + PeerOwnerId: + Description: AWS account ID of the owner of the accepter VPC + Type: String + AllowedPattern: ^\d{12}$ + ConstraintDescription: Must be 12 digits. + + PeerRoleARN: + Description: ARN of the VPC peer role for the peering connection in another AWS account. Required when you are peering a VPC in a different AWS account. + Type: String + AllowedPattern: ^arn:(aws[a-zA-Z-]*)?:iam::\d{12}:role\/([\w+=,.@-]*\/)*[\w+=,.@-]+ + + PeerVPCCIDR: + Description: CIDR of the VPC Peer + Type: String + AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(1[6-9]|2[0-8]))$ + ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28 + + PeerVPCID: + Description: ID of the VPC with which you are creating the VPC peering connection + Type: String + AllowedPattern: ^vpc-[0-9a-f]{17}$ + ConstraintDescription: Must have a prefix of "vpc-". Followed by 17 characters (numbers, letters "a-f") + + RouteTableIds: + Description: Route Table IDs that will be updated to allow communications via the VPC peering connection. Note, the logical order is preserved. + Type: String + AllowedPattern: ^(rtb-[0-9a-f]{17})$|^((rtb-[0-9a-f]{17}(,|, ))*rtb-[0-9a-f]{17})$ + ConstraintDescription: Must have a prefix of "rtb-". Followed by 17 characters (numbers, letters "a-f"). Additional route tables can be provided, separated by a "comma". + + SecurityGroupIds: + Description: Security Group IDs that will be updated to allow communications via the VPC peering connection. Note, the logical order is preserved. + Type: List + + TemplatesS3BucketName: + Description: Templates S3 bucket name for the CloudFormation templates. S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-). + Type: String + AllowedPattern: ^(?=^.{3,63}$)(?!.*[.-]{2})(?!.*[--]{2})(?!^(?:(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\.(?!$)|$)){4}$)(^(([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])\.)*([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])$) + ConstraintDescription: Templates S3 bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-). + + TemplatesS3BucketRegion: + Description: AWS Region where the S3 bucket (TemplatesS3BucketName) is hosted. + Type: String + + TemplatesS3KeyPrefix: + Description: S3 key prefix for the AWS CloudFormation templates. Key prefix can include numbers, lowercase letters, uppercase letters, hyphens (-), and forward slash (/). + Type: String + AllowedPattern: ^[0-9a-zA-Z-/]*$ + ConstraintDescription: Templates key prefix can include numbers, lowercase letters, uppercase letters, hyphens (-), and forward slash (/). + + VPCID: + Description: ID of the VPC + Type: AWS::EC2::VPC::Id + +Rules: + PeerRoleValidation: + RuleCondition: !Equals + - !Ref PeerRoleARN + - "" + Assertions: + - AssetDescription: ARN of the VPC peer role is required when you are peering a VPC in a different AWS account. + Assert: !Equals + - !Ref PeerOwnerId + - !Ref AWS::AccountId + +Resources: + VPCPeeringRequesterSetupStack: + Type: AWS::CloudFormation::Stack + Properties: + TemplateURL: !Sub + - https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${S3KeyPrefix}templates/VPCPeering-Requester-Setup.cfn.yaml + - S3Bucket: !Ref TemplatesS3BucketName + S3KeyPrefix: !Ref TemplatesS3KeyPrefix + S3Region: !Ref TemplatesS3BucketRegion + Parameters: + PeerName: !Ref PeerName + PeerOwnerId: !Ref PeerOwnerId + PeerRoleARN: !Ref PeerRoleARN + PeerVPCID: !Ref PeerVPCID + VPCID: !Ref VPCID + + VPCPeeringUpdatesStack: + Type: AWS::CloudFormation::Stack + Properties: + TemplateURL: !Sub + - https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${S3KeyPrefix}templates/VPCPeering-Updates.cfn.yaml + - S3Bucket: !Ref TemplatesS3BucketName + S3KeyPrefix: !Ref TemplatesS3KeyPrefix + S3Region: !Ref TemplatesS3BucketRegion + Parameters: + NumberOfRouteTables: !Ref NumberOfRouteTables + NumberOfSecurityGroups: !Ref NumberOfSecurityGroups + PeerName: !Ref PeerName + PeerVPCCIDR: !Ref PeerVPCCIDR + RouteTableIds: !Ref RouteTableIds + SecurityGroupIds: !Join + - ',' + - !Ref SecurityGroupIds + VPCPeeringConnectionId: !GetAtt VPCPeeringRequesterSetupStack.Outputs.VPCPeeringConnectionId diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Updates.cfn.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Updates.cfn.json new file mode 100644 index 0000000000000000000000000000000000000000..f78dffaaa67c810b245e7151f9ad4af9b6f53b4f --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Updates.cfn.json @@ -0,0 +1,624 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "This template updates the specified route tables & security groups to allow communications via the VPC peering connection.", + "Metadata": { + "AWS::CloudFormation::Interface": { + "ParameterGroups": [ + { + "Label": { + "default": "Network Configuration" + }, + "Parameters": [ + "RouteTableIds", + "NumberOfRouteTables", + "VPCPeeringConnectionId" + ] + }, + { + "Label": { + "default": "Security Groups Configuration" + }, + "Parameters": [ + "SecurityGroupIds", + "NumberOfSecurityGroups" + ] + }, + { + "Label": { + "default": "VPC Peering Configuration" + }, + "Parameters": [ + "PeerName", + "PeerVPCCIDR" + ] + } + ], + "ParameterLabels": { + "NumberOfRouteTables": { + "default": "Number of Route Tables" + }, + "NumberOfSecurityGroups": { + "default": "Number of Security Groups" + }, + "PeerName": { + "default": "Peer Name" + }, + "PeerVPCCIDR": { + "default": "Peer VPC CIDR" + }, + "RouteTableIds": { + "default": "Route Table IDs" + }, + "SecurityGroupIds": { + "default": "Security Group IDs" + }, + "VPCPeeringConnectionId": { + "default": "VPC Peering Connection ID" + } + } + } + }, + "Parameters": { + "NumberOfRouteTables": { + "Description": "Number of Route Table IDs to update. This must match your items in the comma-separated list of RouteTableIds parameter.", + "Type": "String", + "AllowedValues": [ + 1, + 2, + 3, + 4, + 5, + 6 + ] + }, + "NumberOfSecurityGroups": { + "Description": "Number of Security Group IDs. This must match your selections in the list of SecurityGroupIds parameter.", + "Type": "String", + "AllowedValues": [ + 1, + 2, + 3, + 4, + 5, + 6 + ] + }, + "PeerName": { + "Description": "Name of the VPC Peer", + "Type": "String", + "MaxLength": 255 + }, + "PeerVPCCIDR": { + "Description": "CIDR of the VPC Peer", + "Type": "String", + "AllowedPattern": "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\\/(1[6-9]|2[0-8]))$", + "ConstraintDescription": "CIDR block parameter must be in the form x.x.x.x/16-28" + }, + "RouteTableIds": { + "Description": "Route Table IDs that will be updated to allow communications via the VPC peering connection. Note, the logical order is preserved.", + "Type": "String", + "AllowedPattern": "^(rtb-[0-9a-f]{17})$|^((rtb-[0-9a-f]{17}(,|, ))*rtb-[0-9a-f]{17})$", + "ConstraintDescription": "Must have a prefix of \"rtb-\". Followed by 17 characters (numbers, letters \"a-f\"). Additional route tables can be provided, separated by a \"comma\"." + }, + "SecurityGroupIds": { + "Description": "Security Group IDs that will be updated to allow communications via the VPC peering connection. Note, the logical order is preserved.", + "Type": "List" + }, + "VPCPeeringConnectionId": { + "Description": "ID of the VPC Peering Connection", + "Type": "String", + "AllowedPattern": "^pcx-[0-9a-f]{17}$", + "ConstraintDescription": "Must have a prefix of \"pcx-\". Followed by 17 characters (numbers, letters \"a-f\")" + } + }, + "Conditions": { + "2RouteTableCondition": { + "Fn::Or": [ + { + "Fn::Equals": [ + { + "Ref": "NumberOfRouteTables" + }, + 2 + ] + }, + { + "Condition": "3RouteTableCondition" + }, + { + "Condition": "4RouteTableCondition" + }, + { + "Condition": "5RouteTableCondition" + }, + { + "Condition": "6RouteTableCondition" + } + ] + }, + "3RouteTableCondition": { + "Fn::Or": [ + { + "Fn::Equals": [ + { + "Ref": "NumberOfRouteTables" + }, + 3 + ] + }, + { + "Condition": "4RouteTableCondition" + }, + { + "Condition": "5RouteTableCondition" + }, + { + "Condition": "6RouteTableCondition" + } + ] + }, + "4RouteTableCondition": { + "Fn::Or": [ + { + "Fn::Equals": [ + { + "Ref": "NumberOfRouteTables" + }, + 4 + ] + }, + { + "Condition": "5RouteTableCondition" + }, + { + "Condition": "6RouteTableCondition" + } + ] + }, + "5RouteTableCondition": { + "Fn::Or": [ + { + "Fn::Equals": [ + { + "Ref": "NumberOfRouteTables" + }, + 5 + ] + }, + { + "Condition": "6RouteTableCondition" + } + ] + }, + "6RouteTableCondition": { + "Fn::Equals": [ + { + "Ref": "NumberOfRouteTables" + }, + 6 + ] + }, + "2SecurityGroupCondition": { + "Fn::Or": [ + { + "Fn::Equals": [ + { + "Ref": "NumberOfSecurityGroups" + }, + 2 + ] + }, + { + "Condition": "3SecurityGroupCondition" + }, + { + "Condition": "4SecurityGroupCondition" + }, + { + "Condition": "5SecurityGroupCondition" + }, + { + "Condition": "6SecurityGroupCondition" + } + ] + }, + "3SecurityGroupCondition": { + "Fn::Or": [ + { + "Fn::Equals": [ + { + "Ref": "NumberOfSecurityGroups" + }, + 3 + ] + }, + { + "Condition": "4SecurityGroupCondition" + }, + { + "Condition": "5SecurityGroupCondition" + }, + { + "Condition": "6SecurityGroupCondition" + } + ] + }, + "4SecurityGroupCondition": { + "Fn::Or": [ + { + "Fn::Equals": [ + { + "Ref": "NumberOfSecurityGroups" + }, + 4 + ] + }, + { + "Condition": "5SecurityGroupCondition" + }, + { + "Condition": "6SecurityGroupCondition" + } + ] + }, + "5SecurityGroupCondition": { + "Fn::Or": [ + { + "Fn::Equals": [ + { + "Ref": "NumberOfSecurityGroups" + }, + 5 + ] + }, + { + "Condition": "6SecurityGroupCondition" + } + ] + }, + "6SecurityGroupCondition": { + "Fn::Equals": [ + { + "Ref": "NumberOfSecurityGroups" + }, + 6 + ] + } + }, + "Resources": { + "PeerRoute1": { + "Type": "AWS::EC2::Route", + "Properties": { + "RouteTableId": { + "Fn::Select": [ + 0, + { + "Fn::Split": [ + ",", + { + "Ref": "RouteTableIds" + } + ] + } + ] + }, + "DestinationCidrBlock": { + "Ref": "PeerVPCCIDR" + }, + "VpcPeeringConnectionId": { + "Ref": "VPCPeeringConnectionId" + } + } + }, + "PeerRoute2": { + "Type": "AWS::EC2::Route", + "Properties": { + "RouteTableId": { + "Fn::Select": [ + 1, + { + "Fn::Split": [ + ",", + { + "Ref": "RouteTableIds" + } + ] + } + ] + }, + "DestinationCidrBlock": { + "Ref": "PeerVPCCIDR" + }, + "VpcPeeringConnectionId": { + "Ref": "VPCPeeringConnectionId" + } + }, + "Condition": "2RouteTableCondition" + }, + "PeerRoute3": { + "Type": "AWS::EC2::Route", + "Properties": { + "RouteTableId": { + "Fn::Select": [ + 2, + { + "Fn::Split": [ + ",", + { + "Ref": "RouteTableIds" + } + ] + } + ] + }, + "DestinationCidrBlock": { + "Ref": "PeerVPCCIDR" + }, + "VpcPeeringConnectionId": { + "Ref": "VPCPeeringConnectionId" + } + }, + "Condition": "3RouteTableCondition" + }, + "PeerRoute4": { + "Type": "AWS::EC2::Route", + "Properties": { + "RouteTableId": { + "Fn::Select": [ + 3, + { + "Fn::Split": [ + ",", + { + "Ref": "RouteTableIds" + } + ] + } + ] + }, + "DestinationCidrBlock": { + "Ref": "PeerVPCCIDR" + }, + "VpcPeeringConnectionId": { + "Ref": "VPCPeeringConnectionId" + } + }, + "Condition": "4RouteTableCondition" + }, + "PeerRoute5": { + "Type": "AWS::EC2::Route", + "Properties": { + "RouteTableId": { + "Fn::Select": [ + 4, + { + "Fn::Split": [ + ",", + { + "Ref": "RouteTableIds" + } + ] + } + ] + }, + "DestinationCidrBlock": { + "Ref": "PeerVPCCIDR" + }, + "VpcPeeringConnectionId": { + "Ref": "VPCPeeringConnectionId" + } + }, + "Condition": "5RouteTableCondition" + }, + "PeerRoute6": { + "Type": "AWS::EC2::Route", + "Properties": { + "RouteTableId": { + "Fn::Select": [ + 5, + { + "Fn::Split": [ + ",", + { + "Ref": "RouteTableIds" + } + ] + } + ] + }, + "DestinationCidrBlock": { + "Ref": "PeerVPCCIDR" + }, + "VpcPeeringConnectionId": { + "Ref": "VPCPeeringConnectionId" + } + }, + "Condition": "6RouteTableCondition" + }, + "PeerIngressRule1": { + "Type": "AWS::EC2::SecurityGroupIngress", + "Metadata": { + "cfn_nag": { + "rules_to_suppress": [ + { + "id": "W42", + "reason": "Allow all inbound communications from VPC Peer CIDR (for Lab purposes)" + } + ] + } + }, + "Properties": { + "IpProtocol": "-1", + "Description": { + "Fn::Sub": "LAB - Allow All Inbound Communications from VPC Peer, ${PeerName}" + }, + "GroupId": { + "Fn::Select": [ + 0, + { + "Ref": "SecurityGroupIds" + } + ] + }, + "CidrIp": { + "Ref": "PeerVPCCIDR" + } + } + }, + "PeerIngressRule2": { + "Type": "AWS::EC2::SecurityGroupIngress", + "Metadata": { + "cfn_nag": { + "rules_to_suppress": [ + { + "id": "W42", + "reason": "Allow all inbound communications from VPC Peer CIDR (for Lab purposes)" + } + ] + } + }, + "Properties": { + "IpProtocol": "-1", + "Description": { + "Fn::Sub": "LAB - Allow All Inbound Communications from VPC Peer CIDR, ${PeerName}" + }, + "GroupId": { + "Fn::Select": [ + 1, + { + "Ref": "SecurityGroupIds" + } + ] + }, + "CidrIp": { + "Ref": "PeerVPCCIDR" + } + }, + "Condition": "2SecurityGroupCondition" + }, + "PeerIngressRule3": { + "Type": "AWS::EC2::SecurityGroupIngress", + "Metadata": { + "cfn_nag": { + "rules_to_suppress": [ + { + "id": "W42", + "reason": "Allow all inbound communications from VPC Peer CIDR (for Lab purposes)" + } + ] + } + }, + "Properties": { + "IpProtocol": "-1", + "Description": { + "Fn::Sub": "LAB - Allow All Inbound Communications from VPC Peer, ${PeerName}" + }, + "GroupId": { + "Fn::Select": [ + 2, + { + "Ref": "SecurityGroupIds" + } + ] + }, + "CidrIp": { + "Ref": "PeerVPCCIDR" + } + }, + "Condition": "3SecurityGroupCondition" + }, + "PeerIngressRule4": { + "Type": "AWS::EC2::SecurityGroupIngress", + "Metadata": { + "cfn_nag": { + "rules_to_suppress": [ + { + "id": "W42", + "reason": "Allow all inbound communications from VPC Peer CIDR (for Lab purposes)" + } + ] + } + }, + "Properties": { + "IpProtocol": "-1", + "Description": { + "Fn::Sub": "LAB - Allow All Inbound Communications from VPC Peer, ${PeerName}" + }, + "GroupId": { + "Fn::Select": [ + 3, + { + "Ref": "SecurityGroupIds" + } + ] + }, + "CidrIp": { + "Ref": "PeerVPCCIDR" + } + }, + "Condition": "4SecurityGroupCondition" + }, + "PeerIngressRule5": { + "Type": "AWS::EC2::SecurityGroupIngress", + "Metadata": { + "cfn_nag": { + "rules_to_suppress": [ + { + "id": "W42", + "reason": "Allow all inbound communications from VPC Peer CIDR (for Lab purposes)" + } + ] + } + }, + "Properties": { + "IpProtocol": "-1", + "Description": { + "Fn::Sub": "LAB - Allow All Inbound Communications from VPC Peer, ${PeerName}" + }, + "GroupId": { + "Fn::Select": [ + 4, + { + "Ref": "SecurityGroupIds" + } + ] + }, + "CidrIp": { + "Ref": "PeerVPCCIDR" + } + }, + "Condition": "5SecurityGroupCondition" + }, + "PeerIngressRule6": { + "Type": "AWS::EC2::SecurityGroupIngress", + "Metadata": { + "cfn_nag": { + "rules_to_suppress": [ + { + "id": "W42", + "reason": "Allow all inbound communications from VPC Peer CIDR (for Lab purposes)" + } + ] + } + }, + "Properties": { + "IpProtocol": "-1", + "Description": { + "Fn::Sub": "LAB - Allow All Inbound Communications from VPC Peer, ${PeerName}" + }, + "GroupId": { + "Fn::Select": [ + 5, + { + "Ref": "SecurityGroupIds" + } + ] + }, + "CidrIp": { + "Ref": "PeerVPCCIDR" + } + }, + "Condition": "6SecurityGroupCondition" + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Updates.cfn.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Updates.cfn.yaml new file mode 100644 index 0000000000000000000000000000000000000000..0e104f149b04411f4f2e31b521c41434712aa649 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/VPCPeering/templates/VPCPeering-Updates.cfn.yaml @@ -0,0 +1,324 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: This template updates the specified route tables & security groups to allow communications via the VPC peering connection. + +Metadata: + AWS::CloudFormation::Interface: + ParameterGroups: + - Label: + default: Network Configuration + Parameters: + - RouteTableIds + - NumberOfRouteTables + - VPCPeeringConnectionId + - Label: + default: Security Groups Configuration + Parameters: + - SecurityGroupIds + - NumberOfSecurityGroups + - Label: + default: VPC Peering Configuration + Parameters: + - PeerName + - PeerVPCCIDR + ParameterLabels: + NumberOfRouteTables: + default: Number of Route Tables + NumberOfSecurityGroups: + default: Number of Security Groups + PeerName: + default: Peer Name + PeerVPCCIDR: + default: Peer VPC CIDR + RouteTableIds: + default: Route Table IDs + SecurityGroupIds: + default: Security Group IDs + VPCPeeringConnectionId: + default: VPC Peering Connection ID + +Parameters: + NumberOfRouteTables: + Description: Number of Route Table IDs to update. This must match your items in the comma-separated list of RouteTableIds parameter. + Type: String + AllowedValues: + - 1 + - 2 + - 3 + - 4 + - 5 + - 6 + + NumberOfSecurityGroups: + Description: Number of Security Group IDs. This must match your selections in the list of SecurityGroupIds parameter. + Type: String + AllowedValues: + - 1 + - 2 + - 3 + - 4 + - 5 + - 6 + + PeerName: + Description: Name of the VPC Peer + Type: String + MaxLength: 255 + + PeerVPCCIDR: + Description: CIDR of the VPC Peer + Type: String + AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(1[6-9]|2[0-8]))$ + ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28 + + RouteTableIds: + Description: Route Table IDs that will be updated to allow communications via the VPC peering connection. Note, the logical order is preserved. + Type: String + AllowedPattern: ^(rtb-[0-9a-f]{17})$|^((rtb-[0-9a-f]{17}(,|, ))*rtb-[0-9a-f]{17})$ + ConstraintDescription: Must have a prefix of "rtb-". Followed by 17 characters (numbers, letters "a-f"). Additional route tables can be provided, separated by a "comma". + + SecurityGroupIds: + Description: Security Group IDs that will be updated to allow communications via the VPC peering connection. Note, the logical order is preserved. + Type: List + + VPCPeeringConnectionId: + Description: ID of the VPC Peering Connection + Type: String + AllowedPattern: ^pcx-[0-9a-f]{17}$ + ConstraintDescription: Must have a prefix of "pcx-". Followed by 17 characters (numbers, letters "a-f") + +Conditions: + 2RouteTableCondition: !Or + - !Equals + - !Ref NumberOfRouteTables + - 2 + - !Condition 3RouteTableCondition + - !Condition 4RouteTableCondition + - !Condition 5RouteTableCondition + - !Condition 6RouteTableCondition + + 3RouteTableCondition: !Or + - !Equals + - !Ref NumberOfRouteTables + - 3 + - !Condition 4RouteTableCondition + - !Condition 5RouteTableCondition + - !Condition 6RouteTableCondition + + 4RouteTableCondition: !Or + - !Equals + - !Ref NumberOfRouteTables + - 4 + - !Condition 5RouteTableCondition + - !Condition 6RouteTableCondition + + 5RouteTableCondition: !Or + - !Equals + - !Ref NumberOfRouteTables + - 5 + - !Condition 6RouteTableCondition + + 6RouteTableCondition: !Equals + - !Ref NumberOfRouteTables + - 6 + + 2SecurityGroupCondition: !Or + - !Equals + - !Ref NumberOfSecurityGroups + - 2 + - !Condition 3SecurityGroupCondition + - !Condition 4SecurityGroupCondition + - !Condition 5SecurityGroupCondition + - !Condition 6SecurityGroupCondition + + 3SecurityGroupCondition: !Or + - !Equals + - !Ref NumberOfSecurityGroups + - 3 + - !Condition 4SecurityGroupCondition + - !Condition 5SecurityGroupCondition + - !Condition 6SecurityGroupCondition + + 4SecurityGroupCondition: !Or + - !Equals + - !Ref NumberOfSecurityGroups + - 4 + - !Condition 5SecurityGroupCondition + - !Condition 6SecurityGroupCondition + + 5SecurityGroupCondition: !Or + - !Equals + - !Ref NumberOfSecurityGroups + - 5 + - !Condition 6SecurityGroupCondition + + 6SecurityGroupCondition: !Equals + - !Ref NumberOfSecurityGroups + - 6 + +Resources: + PeerRoute1: + Type: AWS::EC2::Route + Properties: + RouteTableId: !Select + - 0 + - !Split + - ',' + - !Ref RouteTableIds + DestinationCidrBlock: !Ref PeerVPCCIDR + VpcPeeringConnectionId: !Ref VPCPeeringConnectionId + + PeerRoute2: + Type: AWS::EC2::Route + Properties: + RouteTableId: !Select + - 1 + - !Split + - ',' + - !Ref RouteTableIds + DestinationCidrBlock: !Ref PeerVPCCIDR + VpcPeeringConnectionId: !Ref VPCPeeringConnectionId + Condition: 2RouteTableCondition + + PeerRoute3: + Type: AWS::EC2::Route + Properties: + RouteTableId: !Select + - 2 + - !Split + - ',' + - !Ref RouteTableIds + DestinationCidrBlock: !Ref PeerVPCCIDR + VpcPeeringConnectionId: !Ref VPCPeeringConnectionId + Condition: 3RouteTableCondition + + PeerRoute4: + Type: AWS::EC2::Route + Properties: + RouteTableId: !Select + - 3 + - !Split + - ',' + - !Ref RouteTableIds + DestinationCidrBlock: !Ref PeerVPCCIDR + VpcPeeringConnectionId: !Ref VPCPeeringConnectionId + Condition: 4RouteTableCondition + + PeerRoute5: + Type: AWS::EC2::Route + Properties: + RouteTableId: !Select + - 4 + - !Split + - ',' + - !Ref RouteTableIds + DestinationCidrBlock: !Ref PeerVPCCIDR + VpcPeeringConnectionId: !Ref VPCPeeringConnectionId + Condition: 5RouteTableCondition + + PeerRoute6: + Type: AWS::EC2::Route + Properties: + RouteTableId: !Select + - 5 + - !Split + - ',' + - !Ref RouteTableIds + DestinationCidrBlock: !Ref PeerVPCCIDR + VpcPeeringConnectionId: !Ref VPCPeeringConnectionId + Condition: 6RouteTableCondition + + PeerIngressRule1: + Type: AWS::EC2::SecurityGroupIngress + Metadata: + cfn_nag: + rules_to_suppress: + - id: W42 + reason: Allow all inbound communications from VPC Peer CIDR (for Lab purposes) + Properties: + IpProtocol: "-1" + Description: !Sub LAB - Allow All Inbound Communications from VPC Peer, ${PeerName} + GroupId: !Select + - 0 + - !Ref SecurityGroupIds + CidrIp: !Ref PeerVPCCIDR + + PeerIngressRule2: + Type: AWS::EC2::SecurityGroupIngress + Metadata: + cfn_nag: + rules_to_suppress: + - id: W42 + reason: Allow all inbound communications from VPC Peer CIDR (for Lab purposes) + Properties: + IpProtocol: "-1" + Description: !Sub LAB - Allow All Inbound Communications from VPC Peer CIDR, ${PeerName} + GroupId: !Select + - 1 + - !Ref SecurityGroupIds + CidrIp: !Ref PeerVPCCIDR + Condition: 2SecurityGroupCondition + + PeerIngressRule3: + Type: AWS::EC2::SecurityGroupIngress + Metadata: + cfn_nag: + rules_to_suppress: + - id: W42 + reason: Allow all inbound communications from VPC Peer CIDR (for Lab purposes) + Properties: + IpProtocol: "-1" + Description: !Sub LAB - Allow All Inbound Communications from VPC Peer, ${PeerName} + GroupId: !Select + - 2 + - !Ref SecurityGroupIds + CidrIp: !Ref PeerVPCCIDR + Condition: 3SecurityGroupCondition + + PeerIngressRule4: + Type: AWS::EC2::SecurityGroupIngress + Metadata: + cfn_nag: + rules_to_suppress: + - id: W42 + reason: Allow all inbound communications from VPC Peer CIDR (for Lab purposes) + Properties: + IpProtocol: "-1" + Description: !Sub LAB - Allow All Inbound Communications from VPC Peer, ${PeerName} + GroupId: !Select + - 3 + - !Ref SecurityGroupIds + CidrIp: !Ref PeerVPCCIDR + Condition: 4SecurityGroupCondition + + PeerIngressRule5: + Type: AWS::EC2::SecurityGroupIngress + Metadata: + cfn_nag: + rules_to_suppress: + - id: W42 + reason: Allow all inbound communications from VPC Peer CIDR (for Lab purposes) + Properties: + IpProtocol: "-1" + Description: !Sub LAB - Allow All Inbound Communications from VPC Peer, ${PeerName} + GroupId: !Select + - 4 + - !Ref SecurityGroupIds + CidrIp: !Ref PeerVPCCIDR + Condition: 5SecurityGroupCondition + + PeerIngressRule6: + Type: AWS::EC2::SecurityGroupIngress + Metadata: + cfn_nag: + rules_to_suppress: + - id: W42 + reason: Allow all inbound communications from VPC Peer CIDR (for Lab purposes) + Properties: + IpProtocol: "-1" + Description: !Sub LAB - Allow All Inbound Communications from VPC Peer, ${PeerName} + GroupId: !Select + - 5 + - !Ref SecurityGroupIds + CidrIp: !Ref PeerVPCCIDR + Condition: 6SecurityGroupCondition diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/VSCode/README.md b/human_reference_dataset/aws-cloudformation-templates/Solutions/VSCode/README.md new file mode 100644 index 0000000000000000000000000000000000000000..23d454c7fa8f5069d4f7cb101f4fd35021856285 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/VSCode/README.md @@ -0,0 +1,32 @@ +# VSCode Server + +Create an EC2 instance with the code server from Coder.com and a CloudFront +distribution for encrypted access to the web ui from the browser. The output +from the template provides the CloudFront URL. There is no need to configure SSH +for this solution, it is purely browser based. + +As a prerequisite, you need to create a plaintext secret in Secrets Manager to +store your password for the web site. This will be stored as a hash in the +configuration file for code server on the instance. + +## Files + +### `VSCodeServer.yaml` + +This is the raw template, which includes [Rain](https://github.com/aws-cloudformation/rain) +directives to import a VPC module and embed the user data script. + +### `VSCodeServer-pkg.yaml` + +The is the rendered template that you can deploy with `aws cloudformation +deploy` or `rain deploy`. To regenerate this template if you make any changes +to `VSCodeServer.yaml`, run `rain pkg -x VSCodeServer.yaml > +VSCodeServer-pkg.yaml`. + +### `VSCodeServer.sh` + +This is the user data script that is embedded in the packaged template. It is +meant to be used with Amazon Linux instances. + + + diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/VSCode/VSCodeServer-pkg.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/VSCode/VSCodeServer-pkg.json new file mode 100644 index 0000000000000000000000000000000000000000..720cdbfe1397001329436e1b24f4a7faa316f165 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/VSCode/VSCodeServer-pkg.json @@ -0,0 +1,746 @@ +{ + "Parameters": { + "LatestAMI": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64" + }, + "InstanceType": { + "Type": "String", + "Default": "t3.medium" + }, + "SecretName": { + "Description": "The name of the secrets manager secret that stores the password to be used for the VSCode Server. The password must be a simple plaintext string with no JSON.", + "Type": "String", + "Default": "vscode-password" + } + }, + "Mappings": { + "Prefixes": { + "ap-northeast-1": { + "PrefixList": "pl-58a04531" + }, + "ap-northeast-2": { + "PrefixList": "pl-22a6434b" + }, + "ap-south-1": { + "PrefixList": "pl-9aa247f3" + }, + "ap-southeast-1": { + "PrefixList": "pl-31a34658" + }, + "ap-southeast-2": { + "PrefixList": "pl-b8a742d1" + }, + "ca-central-1": { + "PrefixList": "pl-38a64351" + }, + "eu-central-1": { + "PrefixList": "pl-a3a144ca" + }, + "eu-north-1": { + "PrefixList": "pl-fab65393" + }, + "eu-west-1": { + "PrefixList": "pl-4fa04526" + }, + "eu-west-2": { + "PrefixList": "pl-93a247fa" + }, + "eu-west-3": { + "PrefixList": "pl-75b1541c" + }, + "sa-east-1": { + "PrefixList": "pl-5da64334" + }, + "us-east-1": { + "PrefixList": "pl-3b927c52" + }, + "us-east-2": { + "PrefixList": "pl-b6a144df" + }, + "us-west-1": { + "PrefixList": "pl-4ea04527" + }, + "us-west-2": { + "PrefixList": "pl-82a045eb" + } + } + }, + "Resources": { + "InstanceSecurityGroup": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "vscode-server-isg", + "SecurityGroupIngress": [ + { + "Description": "Allow HTTP from com.amazonaws.global.cloudfront.origin-facing", + "IpProtocol": "tcp", + "FromPort": 8080, + "ToPort": 8080, + "SourcePrefixListId": { + "Fn::FindInMap": [ + "Prefixes", + { + "Ref": "AWS::Region" + }, + "PrefixList" + ] + } + } + ], + "SecurityGroupEgress": [ + { + "CidrIp": "0.0.0.0/0", + "Description": "Allow all outbound traffic by default", + "IpProtocol": "-1" + } + ], + "Tags": [ + { + "Key": "Name", + "Value": "vscode-server-isg" + } + ], + "VpcId": { + "Ref": "NetworkVPC" + } + } + }, + "InstanceRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ec2.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "Tags": [ + { + "Key": "Name", + "Value": "vscode-server-instance" + } + ] + } + }, + "InstanceRolePolicy": { + "Type": "AWS::IAM::RolePolicy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "ec2messages:*", + "ssm:UpdateInstanceInformation", + "ssmmessages:*", + "secretsmanager:GetSecretValue" + ], + "Effect": "Allow", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "InstanceRolePolicy", + "RoleName": { + "Ref": "InstanceRole" + } + } + }, + "InstanceProfile": { + "Type": "AWS::IAM::InstanceProfile", + "Properties": { + "Roles": [ + { + "Ref": "InstanceRole" + } + ] + } + }, + "Server": { + "CreationPolicy": { + "ResourceSignal": { + "Timeout": "PT5M" + } + }, + "Type": "AWS::EC2::Instance", + "DependsOn": [ + "InstanceRolePolicy", + "InstanceRole" + ], + "Properties": { + "AvailabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": null + } + ] + }, + "BlockDeviceMappings": [ + { + "DeviceName": "/dev/xvda", + "Ebs": { + "VolumeSize": 128 + } + } + ], + "IamInstanceProfile": { + "Ref": "InstanceProfile" + }, + "ImageId": { + "Ref": "LatestAMI" + }, + "InstanceType": { + "Ref": "InstanceType" + }, + "SecurityGroupIds": [ + { + "Fn::GetAtt": [ + "InstanceSecurityGroup", + "GroupId" + ] + } + ], + "SubnetId": { + "Fn::GetAtt": [ + "NetworkPublicSubnet1", + "SubnetId" + ] + }, + "Tags": [ + { + "Key": "Name", + "Value": "vscode-server" + } + ], + "UserData": { + "Fn::Base64": { + "Fn::Sub": "#!/bin/bash\n\nset -eou pipefail\n\nlocal_ip=$(ec2-metadata | grep \"^local-ipv4: \" | cut -d \" \" -f 2)\n\n# Install the latest code-server from coder.com (not from yum)\nexport HOME=/root \ncurl -fsSL https://code-server.dev/install.sh | bash\n\n# Install cfn-signal\nyum install -y aws-cfn-bootstrap\n\n#Install argon2 for hashing the vscode server password\nyum install -y argon2\n\n# Configure the service\ntee /etc/systemd/system/code-server.service < + Default: /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64 + + InstanceType: + Type: String + Default: t3.medium + + SecretName: + Type: String + Default: vscode-password + Description: The name of the secrets manager secret that stores the password to be used for the VSCode Server. The password must be a simple plaintext string with no JSON. + +Mappings: + Prefixes: + ap-northeast-1: + PrefixList: pl-58a04531 + ap-northeast-2: + PrefixList: pl-22a6434b + ap-south-1: + PrefixList: pl-9aa247f3 + ap-southeast-1: + PrefixList: pl-31a34658 + ap-southeast-2: + PrefixList: pl-b8a742d1 + ca-central-1: + PrefixList: pl-38a64351 + eu-central-1: + PrefixList: pl-a3a144ca + eu-north-1: + PrefixList: pl-fab65393 + eu-west-1: + PrefixList: pl-4fa04526 + eu-west-2: + PrefixList: pl-93a247fa + eu-west-3: + PrefixList: pl-75b1541c + sa-east-1: + PrefixList: pl-5da64334 + us-east-1: + PrefixList: pl-3b927c52 + us-east-2: + PrefixList: pl-b6a144df + us-west-1: + PrefixList: pl-4ea04527 + us-west-2: + PrefixList: pl-82a045eb + +Resources: + InstanceSecurityGroup: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: vscode-server-isg + SecurityGroupIngress: + - Description: Allow HTTP from com.amazonaws.global.cloudfront.origin-facing + IpProtocol: tcp + FromPort: 8080 + ToPort: 8080 + SourcePrefixListId: !FindInMap + - Prefixes + - !Ref AWS::Region + - PrefixList + SecurityGroupEgress: + - CidrIp: 0.0.0.0/0 + Description: Allow all outbound traffic by default + IpProtocol: "-1" + Tags: + - Key: Name + Value: vscode-server-isg + VpcId: !Ref NetworkVPC + + InstanceRole: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Statement: + - Action: sts:AssumeRole + Effect: Allow + Principal: + Service: ec2.amazonaws.com + Version: "2012-10-17" + Tags: + - Key: Name + Value: vscode-server-instance + + InstanceRolePolicy: + Type: AWS::IAM::RolePolicy + Properties: + PolicyDocument: + Statement: + - Action: + - ec2messages:* + - ssm:UpdateInstanceInformation + - ssmmessages:* + - secretsmanager:GetSecretValue + Effect: Allow + Resource: '*' + Version: "2012-10-17" + PolicyName: InstanceRolePolicy + RoleName: !Ref InstanceRole + + InstanceProfile: + Type: AWS::IAM::InstanceProfile + Properties: + Roles: + - !Ref InstanceRole + + Server: + Type: AWS::EC2::Instance + DependsOn: + - InstanceRolePolicy + - InstanceRole + CreationPolicy: + ResourceSignal: + Timeout: PT5M + Properties: + AvailabilityZone: !Select + - 0 + - !GetAZs + BlockDeviceMappings: + - DeviceName: /dev/xvda + Ebs: + VolumeSize: 128 + IamInstanceProfile: !Ref InstanceProfile + ImageId: !Ref LatestAMI + InstanceType: !Ref InstanceType + SecurityGroupIds: + - !GetAtt InstanceSecurityGroup.GroupId + SubnetId: !GetAtt NetworkPublicSubnet1.SubnetId + Tags: + - Key: Name + Value: vscode-server + UserData: !Base64 + Fn::Sub: "#!/bin/bash\n\nset -eou pipefail\n\nlocal_ip=$(ec2-metadata | grep \"^local-ipv4: \" | cut -d \" \" -f 2)\n\n# Install the latest code-server from coder.com (not from yum)\nexport HOME=/root \ncurl -fsSL https://code-server.dev/install.sh | bash\n\n# Install cfn-signal\nyum install -y aws-cfn-bootstrap\n\n#Install argon2 for hashing the vscode server password\nyum install -y argon2\n\n# Configure the service\ntee /etc/systemd/system/code-server.service <", + "Default": "/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64" + }, + "InstanceType": { + "Type": "String", + "Default": "t3.medium" + }, + "SecretName": { + "Description": "The name of the secrets manager secret that stores the password to be used for the VSCode Server. The password must be a simple plaintext string with no JSON.", + "Type": "String", + "Default": "vscode-password" + } + }, + "Mappings": { + "Prefixes": { + "ap-northeast-1": { + "PrefixList": "pl-58a04531" + }, + "ap-northeast-2": { + "PrefixList": "pl-22a6434b" + }, + "ap-south-1": { + "PrefixList": "pl-9aa247f3" + }, + "ap-southeast-1": { + "PrefixList": "pl-31a34658" + }, + "ap-southeast-2": { + "PrefixList": "pl-b8a742d1" + }, + "ca-central-1": { + "PrefixList": "pl-38a64351" + }, + "eu-central-1": { + "PrefixList": "pl-a3a144ca" + }, + "eu-north-1": { + "PrefixList": "pl-fab65393" + }, + "eu-west-1": { + "PrefixList": "pl-4fa04526" + }, + "eu-west-2": { + "PrefixList": "pl-93a247fa" + }, + "eu-west-3": { + "PrefixList": "pl-75b1541c" + }, + "sa-east-1": { + "PrefixList": "pl-5da64334" + }, + "us-east-1": { + "PrefixList": "pl-3b927c52" + }, + "us-east-2": { + "PrefixList": "pl-b6a144df" + }, + "us-west-1": { + "PrefixList": "pl-4ea04527" + }, + "us-west-2": { + "PrefixList": "pl-82a045eb" + } + } + }, + "Resources": { + "Network": { + "Type": { + "Rain::Module": "../../RainModules/vpc.yml" + }, + "Properties": { + "Name": "vscode-server" + } + }, + "InstanceSecurityGroup": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "vscode-server-isg", + "SecurityGroupIngress": [ + { + "Description": "Allow HTTP from com.amazonaws.global.cloudfront.origin-facing", + "IpProtocol": "tcp", + "FromPort": 8080, + "ToPort": 8080, + "SourcePrefixListId": { + "Fn::FindInMap": [ + "Prefixes", + { + "Ref": "AWS::Region" + }, + "PrefixList" + ] + } + } + ], + "SecurityGroupEgress": [ + { + "CidrIp": "0.0.0.0/0", + "Description": "Allow all outbound traffic by default", + "IpProtocol": "-1" + } + ], + "Tags": [ + { + "Key": "Name", + "Value": "vscode-server-isg" + } + ], + "VpcId": { + "Ref": "NetworkVPC" + } + } + }, + "InstanceRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ec2.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "Tags": [ + { + "Key": "Name", + "Value": "vscode-server-instance" + } + ] + } + }, + "InstanceRolePolicy": { + "Type": "AWS::IAM::RolePolicy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "ec2messages:*", + "ssm:UpdateInstanceInformation", + "ssmmessages:*", + "secretsmanager:GetSecretValue" + ], + "Effect": "Allow", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "InstanceRolePolicy", + "RoleName": { + "Ref": "InstanceRole" + } + } + }, + "InstanceProfile": { + "Type": "AWS::IAM::InstanceProfile", + "Properties": { + "Roles": [ + { + "Ref": "InstanceRole" + } + ] + } + }, + "Server": { + "CreationPolicy": { + "ResourceSignal": { + "Timeout": "PT5M" + } + }, + "Type": "AWS::EC2::Instance", + "DependsOn": [ + "InstanceRolePolicy", + "InstanceRole" + ], + "Properties": { + "AvailabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": null + } + ] + }, + "BlockDeviceMappings": [ + { + "DeviceName": "/dev/xvda", + "Ebs": { + "VolumeSize": 128 + } + } + ], + "IamInstanceProfile": { + "Ref": "InstanceProfile" + }, + "ImageId": { + "Ref": "LatestAMI" + }, + "InstanceType": { + "Ref": "InstanceType" + }, + "SecurityGroupIds": [ + { + "Fn::GetAtt": [ + "InstanceSecurityGroup", + "GroupId" + ] + } + ], + "SubnetId": { + "Fn::GetAtt": [ + "NetworkPublicSubnet1", + "SubnetId" + ] + }, + "Tags": [ + { + "Key": "Name", + "Value": "vscode-server" + } + ], + "UserData": { + "Fn::Base64": { + "Fn::Sub": { + "Rain::Embed": "VSCodeServer.sh" + } + } + } + } + }, + "CloudFront": { + "Type": { + "Rain::Module": "../../RainModules/cloudfront-nocache.yml" + }, + "Properties": { + "Name": "vscode-server", + "DomainName": { + "Fn::GetAtt": [ + "Server", + "PublicDnsName" + ] + }, + "Port": 8080 + }, + "Overrides": { + "Distribution": { + "DependsOn": "Server" + } + } + } + }, + "Outputs": { + "URL": { + "Value": { + "Fn::Sub": "https://${CloudFrontDistribution.DomainName}/?folder=/home/ec2-user" + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/VSCode/VSCodeServer.sh b/human_reference_dataset/aws-cloudformation-templates/Solutions/VSCode/VSCodeServer.sh new file mode 100644 index 0000000000000000000000000000000000000000..1bc9824616696c0a5ef446fe4e210c80b37af8a7 --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/VSCode/VSCodeServer.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +set -eou pipefail + +local_ip=$(ec2-metadata | grep "^local-ipv4: " | cut -d " " -f 2) + +# Install the latest code-server from coder.com (not from yum) +export HOME=/root +curl -fsSL https://code-server.dev/install.sh | bash + +# Install cfn-signal +yum install -y aws-cfn-bootstrap + +#Install argon2 for hashing the vscode server password +yum install -y argon2 + +# Configure the service +tee /etc/systemd/system/code-server.service < + Default: /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64 + + InstanceType: + Type: String + Default: t3.medium + + SecretName: + Type: String + Default: vscode-password + Description: The name of the secrets manager secret that stores the password to be used for the VSCode Server. The password must be a simple plaintext string with no JSON. + +Mappings: + Prefixes: + ap-northeast-1: + PrefixList: pl-58a04531 + ap-northeast-2: + PrefixList: pl-22a6434b + ap-south-1: + PrefixList: pl-9aa247f3 + ap-southeast-1: + PrefixList: pl-31a34658 + ap-southeast-2: + PrefixList: pl-b8a742d1 + ca-central-1: + PrefixList: pl-38a64351 + eu-central-1: + PrefixList: pl-a3a144ca + eu-north-1: + PrefixList: pl-fab65393 + eu-west-1: + PrefixList: pl-4fa04526 + eu-west-2: + PrefixList: pl-93a247fa + eu-west-3: + PrefixList: pl-75b1541c + sa-east-1: + PrefixList: pl-5da64334 + us-east-1: + PrefixList: pl-3b927c52 + us-east-2: + PrefixList: pl-b6a144df + us-west-1: + PrefixList: pl-4ea04527 + us-west-2: + PrefixList: pl-82a045eb + +Resources: + Network: + Type: !Rain::Module ../../RainModules/vpc.yml + Properties: + Name: vscode-server + + InstanceSecurityGroup: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: vscode-server-isg + SecurityGroupIngress: + - Description: Allow HTTP from com.amazonaws.global.cloudfront.origin-facing + IpProtocol: tcp + FromPort: 8080 + ToPort: 8080 + SourcePrefixListId: !FindInMap + - Prefixes + - !Ref AWS::Region + - PrefixList + SecurityGroupEgress: + - CidrIp: 0.0.0.0/0 + Description: Allow all outbound traffic by default + IpProtocol: "-1" + Tags: + - Key: Name + Value: vscode-server-isg + VpcId: !Ref NetworkVPC + + InstanceRole: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Statement: + - Action: sts:AssumeRole + Effect: Allow + Principal: + Service: ec2.amazonaws.com + Version: "2012-10-17" + Tags: + - Key: Name + Value: vscode-server-instance + + InstanceRolePolicy: + Type: AWS::IAM::RolePolicy + Properties: + PolicyDocument: + Statement: + - Action: + - ec2messages:* + - ssm:UpdateInstanceInformation + - ssmmessages:* + - secretsmanager:GetSecretValue + Effect: Allow + Resource: '*' + Version: "2012-10-17" + PolicyName: InstanceRolePolicy + RoleName: !Ref InstanceRole + + InstanceProfile: + Type: AWS::IAM::InstanceProfile + Properties: + Roles: + - !Ref InstanceRole + + Server: + Type: AWS::EC2::Instance + DependsOn: + - InstanceRolePolicy + - InstanceRole + CreationPolicy: + ResourceSignal: + Timeout: PT5M + Properties: + AvailabilityZone: !Select + - 0 + - !GetAZs + BlockDeviceMappings: + - DeviceName: /dev/xvda + Ebs: + VolumeSize: 128 + IamInstanceProfile: !Ref InstanceProfile + ImageId: !Ref LatestAMI + InstanceType: !Ref InstanceType + SecurityGroupIds: + - !GetAtt InstanceSecurityGroup.GroupId + SubnetId: !GetAtt NetworkPublicSubnet1.SubnetId + Tags: + - Key: Name + Value: vscode-server + UserData: !Base64 + Fn::Sub: !Rain::Embed VSCodeServer.sh + + CloudFront: + Type: !Rain::Module ../../RainModules/cloudfront-nocache.yml + Properties: + Name: vscode-server + DomainName: !GetAtt Server.PublicDnsName + Port: 8080 + Overrides: + Distribution: + DependsOn: Server + +Outputs: + URL: + Value: !Sub https://${CloudFrontDistribution.DomainName}/?folder=/home/ec2-user diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/WebApp/webapp.json b/human_reference_dataset/aws-cloudformation-templates/Solutions/WebApp/webapp.json new file mode 100644 index 0000000000000000000000000000000000000000..25acb3e932fe82034a5f22f0e3d92e9e020e3c7b --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/WebApp/webapp.json @@ -0,0 +1,1521 @@ +{ + "Description": "Creates a web application with a static website using S3 and CloudFront, an API Gateway REST API, and a DynamoDB table, with Cognito authentication. Apache-2.0 License. Adapt this template to your needs and thoruoughly test it before introducing it in a production environment. **WARNING** This template will create resources in your account that may incur billing charges.", + "Parameters": { + "AppName": { + "Description": "This name is used as a prefix for resource names", + "Type": "String", + "Default": "rain-webapp-sample" + }, + "LambdaCodeS3Bucket": { + "Description": "The bucket where your lambda handler is", + "Type": "String", + "Default": "rain-artifacts-207567786752-us-east-1" + }, + "LambdaCodeS3Key": { + "Description": "The object key for your lambda handler", + "Type": "String", + "Default": "512113b95e9fc6345b2e19a43350af82aaa815011120288f16b1f281d5efdc95" + } + }, + "Resources": { + "TestResourceHandlerPolicy": { + "Type": "AWS::IAM::RolePolicy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "dynamodb:BatchGetItem", + "dynamodb:GetItem", + "dynamodb:Query", + "dynamodb:Scan", + "dynamodb:BatchWriteItem", + "dynamodb:PutItem", + "dynamodb:UpdateItem" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::GetAtt": [ + "TestTable", + "Arn" + ] + } + ] + } + ] + }, + "PolicyName": "handler-policy", + "RoleName": { + "Ref": "TestResourceHandlerRole" + } + } + }, + "TestTable": { + "Type": "AWS::DynamoDB::Table", + "Metadata": { + "guard": { + "SuppressedRules": [ + "DYNAMODB_PITR_ENABLED" + ] + } + }, + "Properties": { + "BillingMode": "PAY_PER_REQUEST", + "TableName": { + "Fn::Sub": "${AppName}-test" + }, + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ] + } + }, + "SiteOriginAccessControl": { + "Type": "AWS::CloudFront::OriginAccessControl", + "Properties": { + "OriginAccessControlConfig": { + "Name": { + "Fn::Join": [ + "", + [ + { + "Ref": "AppName" + }, + { + "Fn::Select": [ + 2, + { + "Fn::Split": [ + "/", + { + "Ref": "AWS::StackId" + } + ] + } + ] + } + ] + ] + }, + "OriginAccessControlOriginType": "s3", + "SigningBehavior": "always", + "SigningProtocol": "sigv4" + } + } + }, + "SiteDistribution": { + "Type": "AWS::CloudFront::Distribution", + "Metadata": { + "checkov": { + "skip": [ + { + "id": "CKV_AWS_174", + "comment": "Using the default cloudfront certificate with no aliases" + } + ] + }, + "guard": { + "SuppressedRules": [ + "CLOUDFRONT_CUSTOM_SSL_CERTIFICATE", + "CLOUDFRONT_ORIGIN_FAILOVER_ENABLED", + "CLOUDFRONT_SNI_ENABLED" + ] + } + }, + "Properties": { + "DistributionConfig": { + "DefaultCacheBehavior": { + "CachePolicyId": "658327ea-f89d-4fab-a63d-7e88639e58f6", + "Compress": true, + "TargetOriginId": { + "Fn::Sub": "${AppName}-origin-1" + }, + "ViewerProtocolPolicy": "redirect-to-https" + }, + "DefaultRootObject": "index.html", + "Enabled": true, + "HttpVersion": "http2", + "IPV6Enabled": true, + "Logging": { + "Bucket": { + "Fn::GetAtt": [ + "SiteCloudFrontLogsBucket", + "RegionalDomainName" + ] + } + }, + "Origins": [ + { + "DomainName": { + "Fn::GetAtt": [ + "SiteContentBucket", + "RegionalDomainName" + ] + }, + "Id": { + "Fn::Sub": "${AppName}-origin-1" + }, + "OriginAccessControlId": { + "Fn::GetAtt": [ + "SiteOriginAccessControl", + "Id" + ] + }, + "S3OriginConfig": { + "OriginAccessIdentity": "" + } + } + ], + "ViewerCertificate": { + "CloudFrontDefaultCertificate": true + }, + "WebACLId": { + "Fn::GetAtt": [ + "SiteWebACL", + "Arn" + ] + } + } + } + }, + "SiteWebACL": { + "Type": "AWS::WAFv2::WebACL", + "Properties": { + "Name": { + "Fn::Sub": "${AppName}-WebACLWithAMR" + }, + "Scope": "CLOUDFRONT", + "Description": "Web ACL with AWS Managed Rules", + "DefaultAction": { + "Allow": {} + }, + "VisibilityConfig": { + "SampledRequestsEnabled": true, + "CloudWatchMetricsEnabled": true, + "MetricName": "MetricForWebACLWithAMR" + }, + "Tags": [ + { + "Key": "Name", + "Value": { + "Ref": "AppName" + } + } + ], + "Rules": [ + { + "Name": "AWS-AWSManagedRulesCommonRuleSet", + "Priority": 0, + "OverrideAction": { + "None": {} + }, + "VisibilityConfig": { + "SampledRequestsEnabled": true, + "CloudWatchMetricsEnabled": true, + "MetricName": "MetricForAMRCRS" + }, + "Statement": { + "ManagedRuleGroupStatement": { + "VendorName": "AWS", + "Name": "AWSManagedRulesCommonRuleSet", + "ExcludedRules": [ + { + "Name": "NoUserAgent_HEADER" + } + ] + } + } + } + ] + } + }, + "SiteContentLogBucket": { + "Type": "AWS::S3::Bucket", + "Metadata": { + "Comment": "This bucket records access logs for the main bucket", + "checkov": { + "skip": [ + { + "comment": "This is the log bucket", + "id": "CKV_AWS_18" + } + ] + }, + "guard": { + "SuppressedRules": [ + "S3_BUCKET_LOGGING_ENABLED", + "S3_BUCKET_REPLICATION_ENABLED" + ] + } + }, + "Properties": { + "BucketEncryption": { + "ServerSideEncryptionConfiguration": [ + { + "ServerSideEncryptionByDefault": { + "SSEAlgorithm": "AES256" + } + } + ] + }, + "BucketName": { + "Fn::Sub": "${AppName}-content-logs-${AWS::Region}-${AWS::AccountId}" + }, + "ObjectLockConfiguration": { + "ObjectLockEnabled": "Enabled", + "Rule": { + "DefaultRetention": { + "Mode": "COMPLIANCE", + "Years": 1 + } + } + }, + "ObjectLockEnabled": true, + "PublicAccessBlockConfiguration": { + "BlockPublicAcls": true, + "BlockPublicPolicy": true, + "IgnorePublicAcls": true, + "RestrictPublicBuckets": true + }, + "VersioningConfiguration": { + "Status": "Enabled" + } + } + }, + "SiteContentBucket": { + "Type": "AWS::S3::Bucket", + "Metadata": { + "guard": { + "SuppressedRules": [ + "S3_BUCKET_DEFAULT_LOCK_ENABLED" + ] + } + }, + "Properties": { + "BucketEncryption": { + "ServerSideEncryptionConfiguration": [ + { + "ServerSideEncryptionByDefault": { + "SSEAlgorithm": "AES256" + } + } + ] + }, + "BucketName": { + "Fn::Sub": "${AppName}-content-${AWS::Region}-${AWS::AccountId}" + }, + "LoggingConfiguration": { + "DestinationBucketName": { + "Ref": "SiteContentLogBucket" + } + }, + "ObjectLockEnabled": false, + "PublicAccessBlockConfiguration": { + "BlockPublicAcls": true, + "BlockPublicPolicy": true, + "IgnorePublicAcls": true, + "RestrictPublicBuckets": true + }, + "ReplicationConfiguration": { + "Role": { + "Fn::GetAtt": [ + "SiteContentReplicationRole", + "Arn" + ] + }, + "Rules": [ + { + "Destination": { + "Bucket": { + "Fn::GetAtt": [ + "SiteContentReplicaBucket", + "Arn" + ] + } + }, + "Status": "Enabled" + } + ] + }, + "VersioningConfiguration": { + "Status": "Enabled" + } + } + }, + "SiteContentReplicaBucket": { + "Type": "AWS::S3::Bucket", + "Metadata": { + "Comment": "This bucket is used as a target for replicas from the main bucket", + "checkov": { + "skip": [ + { + "comment": "This is the replica bucket", + "id": "CKV_AWS_18" + } + ] + }, + "guard": { + "SuppressedRules": [ + "S3_BUCKET_DEFAULT_LOCK_ENABLED", + "S3_BUCKET_REPLICATION_ENABLED", + "S3_BUCKET_LOGGING_ENABLED" + ] + } + }, + "Properties": { + "BucketEncryption": { + "ServerSideEncryptionConfiguration": [ + { + "ServerSideEncryptionByDefault": { + "SSEAlgorithm": "AES256" + } + } + ] + }, + "BucketName": { + "Fn::Sub": "${AppName}-content-replicas-${AWS::Region}-${AWS::AccountId}" + }, + "ObjectLockEnabled": false, + "PublicAccessBlockConfiguration": { + "BlockPublicAcls": true, + "BlockPublicPolicy": true, + "IgnorePublicAcls": true, + "RestrictPublicBuckets": true + }, + "VersioningConfiguration": { + "Status": "Enabled" + } + } + }, + "SiteContentReplicationPolicy": { + "Type": "AWS::IAM::RolePolicy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "s3:GetReplicationConfiguration", + "s3:ListBucket" + ], + "Effect": "Allow", + "Resource": { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AppName}-content-${AWS::Region}-${AWS::AccountId}" + } + }, + { + "Action": [ + "s3:GetObjectVersionForReplication", + "s3:GetObjectVersionAcl", + "s3:GetObjectVersionTagging" + ], + "Effect": "Allow", + "Resource": { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AppName}-content-${AWS::Region}-${AWS::AccountId}/*" + } + }, + { + "Action": [ + "s3:ReplicateObject", + "s3:ReplicateDelete", + "s3:ReplicationTags" + ], + "Effect": "Allow", + "Resource": { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AppName}-content-replicas-${AWS::Region}-${AWS::AccountId}/*" + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "bucket-replication-policy", + "RoleName": { + "Ref": "SiteContentReplicationRole" + } + } + }, + "SiteContentReplicationRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "s3.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "Path": "/" + } + }, + "SiteContentLogBucketAccessPolicy": { + "Type": "AWS::S3::BucketPolicy", + "Properties": { + "Bucket": { + "Fn::Sub": "${AppName}-content-logs-${AWS::Region}-${AWS::AccountId}" + }, + "PolicyDocument": { + "Statement": [ + { + "Action": "s3:*", + "Condition": { + "Bool": { + "aws:SecureTransport": false + } + }, + "Effect": "Deny", + "Principal": { + "AWS": "*" + }, + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AppName}-content-logs-${AWS::Region}-${AWS::AccountId}" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AppName}-content-logs-${AWS::Region}-${AWS::AccountId}/*" + } + ] + }, + { + "Action": "s3:PutObject", + "Condition": { + "ArnLike": { + "aws:SourceArn": { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AppName}-content-logs-${AWS::Region}-${AWS::AccountId}" + } + }, + "StringEquals": { + "aws:SourceAccount": { + "Ref": "AWS::AccountId" + } + } + }, + "Effect": "Allow", + "Principal": { + "Service": "logging.s3.amazonaws.com" + }, + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AppName}-content-logs-${AWS::Region}-${AWS::AccountId}/*" + } + ] + } + ], + "Version": "2012-10-17" + } + } + }, + "SiteContentBucketAccessPolicy": { + "Type": "AWS::S3::BucketPolicy", + "Properties": { + "Bucket": { + "Fn::Sub": "${AppName}-content-${AWS::Region}-${AWS::AccountId}" + }, + "PolicyDocument": { + "Statement": [ + { + "Action": "s3:GetObject", + "Effect": "Allow", + "Resource": { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AppName}-content-${AWS::Region}-${AWS::AccountId}/*" + }, + "Principal": { + "Service": "cloudfront.amazonaws.com" + }, + "Condition": { + "StringEquals": { + "AWS:SourceArn": { + "Fn::Sub": "arn:${AWS::Partition}:cloudfront::${AWS::AccountId}:distribution/${SiteDistribution.Id}" + } + } + } + }, + { + "Action": "s3:*", + "Condition": { + "Bool": { + "aws:SecureTransport": false + } + }, + "Effect": "Deny", + "Principal": { + "AWS": "*" + }, + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AppName}-content-${AWS::Region}-${AWS::AccountId}" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AppName}-content-${AWS::Region}-${AWS::AccountId}/*" + } + ] + }, + { + "Action": "s3:PutObject", + "Condition": { + "ArnLike": { + "aws:SourceArn": { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AppName}-content-${AWS::Region}-${AWS::AccountId}" + } + }, + "StringEquals": { + "aws:SourceAccount": { + "Ref": "AWS::AccountId" + } + } + }, + "Effect": "Allow", + "Principal": { + "Service": "logging.s3.amazonaws.com" + }, + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AppName}-content-${AWS::Region}-${AWS::AccountId}/*" + } + ] + } + ], + "Version": "2012-10-17" + } + } + }, + "SiteContentReplicaBucketAccessPolicy": { + "Type": "AWS::S3::BucketPolicy", + "Properties": { + "Bucket": { + "Fn::Sub": "${AppName}-content-replicas-${AWS::Region}-${AWS::AccountId}" + }, + "PolicyDocument": { + "Statement": [ + { + "Action": "s3:*", + "Condition": { + "Bool": { + "aws:SecureTransport": false + } + }, + "Effect": "Deny", + "Principal": { + "AWS": "*" + }, + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AppName}-content-replicas-${AWS::Region}-${AWS::AccountId}" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AppName}-content-replicas-${AWS::Region}-${AWS::AccountId}/*" + } + ] + }, + { + "Action": "s3:PutObject", + "Condition": { + "ArnLike": { + "aws:SourceArn": { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AppName}-content-replicas-${AWS::Region}-${AWS::AccountId}" + } + }, + "StringEquals": { + "aws:SourceAccount": { + "Ref": "AWS::AccountId" + } + } + }, + "Effect": "Allow", + "Principal": { + "Service": "logging.s3.amazonaws.com" + }, + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AppName}-content-replicas-${AWS::Region}-${AWS::AccountId}/*" + } + ] + } + ], + "Version": "2012-10-17" + } + } + }, + "SiteCloudFrontLogsLogBucket": { + "Type": "AWS::S3::Bucket", + "Metadata": { + "Comment": "This bucket records access logs for the main bucket", + "checkov": { + "skip": [ + { + "comment": "This is the log bucket", + "id": "CKV_AWS_18" + } + ] + }, + "guard": { + "SuppressedRules": [ + "S3_BUCKET_LOGGING_ENABLED", + "S3_BUCKET_REPLICATION_ENABLED" + ] + } + }, + "Properties": { + "BucketEncryption": { + "ServerSideEncryptionConfiguration": [ + { + "ServerSideEncryptionByDefault": { + "SSEAlgorithm": "AES256" + } + } + ] + }, + "BucketName": { + "Fn::Sub": "${AppName}-cflogs-logs-${AWS::Region}-${AWS::AccountId}" + }, + "ObjectLockConfiguration": { + "ObjectLockEnabled": "Enabled", + "Rule": { + "DefaultRetention": { + "Mode": "COMPLIANCE", + "Years": 1 + } + } + }, + "ObjectLockEnabled": true, + "PublicAccessBlockConfiguration": { + "BlockPublicAcls": true, + "BlockPublicPolicy": true, + "IgnorePublicAcls": true, + "RestrictPublicBuckets": true + }, + "VersioningConfiguration": { + "Status": "Enabled" + } + } + }, + "SiteCloudFrontLogsBucket": { + "Type": "AWS::S3::Bucket", + "Metadata": { + "guard": { + "SuppressedRules": [ + "S3_BUCKET_DEFAULT_LOCK_ENABLED" + ] + } + }, + "Properties": { + "BucketEncryption": { + "ServerSideEncryptionConfiguration": [ + { + "ServerSideEncryptionByDefault": { + "SSEAlgorithm": "AES256" + } + } + ] + }, + "BucketName": { + "Fn::Sub": "${AppName}-cflogs-${AWS::Region}-${AWS::AccountId}" + }, + "LoggingConfiguration": { + "DestinationBucketName": { + "Ref": "SiteCloudFrontLogsLogBucket" + } + }, + "ObjectLockEnabled": false, + "PublicAccessBlockConfiguration": { + "BlockPublicAcls": true, + "BlockPublicPolicy": true, + "IgnorePublicAcls": true, + "RestrictPublicBuckets": true + }, + "ReplicationConfiguration": { + "Role": { + "Fn::GetAtt": [ + "SiteCloudFrontLogsReplicationRole", + "Arn" + ] + }, + "Rules": [ + { + "Destination": { + "Bucket": { + "Fn::GetAtt": [ + "SiteCloudFrontLogsReplicaBucket", + "Arn" + ] + } + }, + "Status": "Enabled" + } + ] + }, + "VersioningConfiguration": { + "Status": "Enabled" + }, + "OwnershipControls": { + "Rules": [ + { + "ObjectOwnership": "BucketOwnerPreferred" + } + ] + } + } + }, + "SiteCloudFrontLogsReplicaBucket": { + "Type": "AWS::S3::Bucket", + "Metadata": { + "Comment": "This bucket is used as a target for replicas from the main bucket", + "checkov": { + "skip": [ + { + "comment": "This is the replica bucket", + "id": "CKV_AWS_18" + } + ] + }, + "guard": { + "SuppressedRules": [ + "S3_BUCKET_DEFAULT_LOCK_ENABLED", + "S3_BUCKET_REPLICATION_ENABLED", + "S3_BUCKET_LOGGING_ENABLED" + ] + } + }, + "Properties": { + "BucketEncryption": { + "ServerSideEncryptionConfiguration": [ + { + "ServerSideEncryptionByDefault": { + "SSEAlgorithm": "AES256" + } + } + ] + }, + "BucketName": { + "Fn::Sub": "${AppName}-cflogs-replicas-${AWS::Region}-${AWS::AccountId}" + }, + "ObjectLockEnabled": false, + "PublicAccessBlockConfiguration": { + "BlockPublicAcls": true, + "BlockPublicPolicy": true, + "IgnorePublicAcls": true, + "RestrictPublicBuckets": true + }, + "VersioningConfiguration": { + "Status": "Enabled" + } + } + }, + "SiteCloudFrontLogsReplicationPolicy": { + "Type": "AWS::IAM::RolePolicy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "s3:GetReplicationConfiguration", + "s3:ListBucket" + ], + "Effect": "Allow", + "Resource": { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AppName}-cflogs-${AWS::Region}-${AWS::AccountId}" + } + }, + { + "Action": [ + "s3:GetObjectVersionForReplication", + "s3:GetObjectVersionAcl", + "s3:GetObjectVersionTagging" + ], + "Effect": "Allow", + "Resource": { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AppName}-cflogs-${AWS::Region}-${AWS::AccountId}/*" + } + }, + { + "Action": [ + "s3:ReplicateObject", + "s3:ReplicateDelete", + "s3:ReplicationTags" + ], + "Effect": "Allow", + "Resource": { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AppName}-cflogs-replicas-${AWS::Region}-${AWS::AccountId}/*" + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "bucket-replication-policy", + "RoleName": { + "Ref": "SiteCloudFrontLogsReplicationRole" + } + } + }, + "SiteCloudFrontLogsReplicationRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "s3.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "Path": "/" + } + }, + "SiteCloudFrontLogsLogBucketAccessPolicy": { + "Type": "AWS::S3::BucketPolicy", + "Properties": { + "Bucket": { + "Fn::Sub": "${AppName}-cflogs-logs-${AWS::Region}-${AWS::AccountId}" + }, + "PolicyDocument": { + "Statement": [ + { + "Action": "s3:*", + "Condition": { + "Bool": { + "aws:SecureTransport": false + } + }, + "Effect": "Deny", + "Principal": { + "AWS": "*" + }, + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AppName}-cflogs-logs-${AWS::Region}-${AWS::AccountId}" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AppName}-cflogs-logs-${AWS::Region}-${AWS::AccountId}/*" + } + ] + }, + { + "Action": "s3:PutObject", + "Condition": { + "ArnLike": { + "aws:SourceArn": { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AppName}-cflogs-logs-${AWS::Region}-${AWS::AccountId}" + } + }, + "StringEquals": { + "aws:SourceAccount": { + "Ref": "AWS::AccountId" + } + } + }, + "Effect": "Allow", + "Principal": { + "Service": "logging.s3.amazonaws.com" + }, + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AppName}-cflogs-logs-${AWS::Region}-${AWS::AccountId}/*" + } + ] + } + ], + "Version": "2012-10-17" + } + } + }, + "SiteCloudFrontLogsBucketAccessPolicy": { + "Type": "AWS::S3::BucketPolicy", + "Properties": { + "Bucket": { + "Fn::Sub": "${AppName}-cflogs-${AWS::Region}-${AWS::AccountId}" + }, + "PolicyDocument": { + "Statement": [ + { + "Action": "s3:*", + "Condition": { + "Bool": { + "aws:SecureTransport": false + } + }, + "Effect": "Deny", + "Principal": { + "AWS": "*" + }, + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AppName}-cflogs-${AWS::Region}-${AWS::AccountId}" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AppName}-cflogs-${AWS::Region}-${AWS::AccountId}/*" + } + ] + }, + { + "Action": "s3:PutObject", + "Condition": { + "ArnLike": { + "aws:SourceArn": { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AppName}-cflogs-${AWS::Region}-${AWS::AccountId}" + } + }, + "StringEquals": { + "aws:SourceAccount": { + "Ref": "AWS::AccountId" + } + } + }, + "Effect": "Allow", + "Principal": { + "Service": "logging.s3.amazonaws.com" + }, + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AppName}-cflogs-${AWS::Region}-${AWS::AccountId}/*" + } + ] + } + ], + "Version": "2012-10-17" + } + } + }, + "SiteCloudFrontLogsReplicaBucketAccessPolicy": { + "Type": "AWS::S3::BucketPolicy", + "Properties": { + "Bucket": { + "Fn::Sub": "${AppName}-cflogs-replicas-${AWS::Region}-${AWS::AccountId}" + }, + "PolicyDocument": { + "Statement": [ + { + "Action": "s3:*", + "Condition": { + "Bool": { + "aws:SecureTransport": false + } + }, + "Effect": "Deny", + "Principal": { + "AWS": "*" + }, + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AppName}-cflogs-replicas-${AWS::Region}-${AWS::AccountId}" + }, + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AppName}-cflogs-replicas-${AWS::Region}-${AWS::AccountId}/*" + } + ] + }, + { + "Action": "s3:PutObject", + "Condition": { + "ArnLike": { + "aws:SourceArn": { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AppName}-cflogs-replicas-${AWS::Region}-${AWS::AccountId}" + } + }, + "StringEquals": { + "aws:SourceAccount": { + "Ref": "AWS::AccountId" + } + } + }, + "Effect": "Allow", + "Principal": { + "Service": "logging.s3.amazonaws.com" + }, + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:s3:::${AppName}-cflogs-replicas-${AWS::Region}-${AWS::AccountId}/*" + } + ] + } + ], + "Version": "2012-10-17" + } + } + }, + "CognitoUserPool": { + "Type": "AWS::Cognito::UserPool", + "DependsOn": [ + "SiteDistribution" + ], + "Properties": { + "UserPoolName": { + "Ref": "AppName" + }, + "AdminCreateUserConfig": { + "AllowAdminCreateUserOnly": true + }, + "AutoVerifiedAttributes": [ + "email" + ], + "Schema": [ + { + "Name": "email", + "Required": true + }, + { + "Name": "given_name", + "Required": true + }, + { + "Name": "family_name", + "Required": true + } + ] + } + }, + "CognitoDomain": { + "Type": "AWS::Cognito::UserPoolDomain", + "Properties": { + "Domain": { + "Ref": "AppName" + }, + "UserPoolId": { + "Ref": "CognitoUserPool" + } + } + }, + "CognitoClient": { + "Type": "AWS::Cognito::UserPoolClient", + "Properties": { + "ClientName": { + "Ref": "AppName" + }, + "GenerateSecret": false, + "UserPoolId": { + "Ref": "CognitoUserPool" + }, + "CallbackURLs": [ + { + "Fn::Sub": "https://${SiteDistribution.DomainName}/index.html" + } + ], + "AllowedOAuthFlows": [ + "code" + ], + "AllowedOAuthFlowsUserPoolClient": true, + "AllowedOAuthScopes": [ + "phone", + "email", + "openid" + ], + "SupportedIdentityProviders": [ + "COGNITO" + ] + } + }, + "TestResourceHandler": { + "Type": "AWS::Lambda::Function", + "Metadata": { + "guard": { + "SuppressedRules": [ + "LAMBDA_INSIDE_VPC" + ] + } + }, + "Properties": { + "Handler": "bootstrap", + "FunctionName": { + "Fn::Sub": "${AppName}-test-handler" + }, + "Runtime": "provided.al2023", + "Code": { + "S3Bucket": { + "Ref": "LambdaCodeS3Bucket" + }, + "S3Key": { + "Ref": "LambdaCodeS3Key" + } + }, + "Role": { + "Fn::GetAtt": [ + "TestResourceHandlerRole", + "Arn" + ] + }, + "Environment": { + "Variables": { + "TABLE_NAME": { + "Ref": "TestTable" + } + } + } + } + }, + "TestResourceHandlerRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + }, + "Action": [ + "sts:AssumeRole" + ] + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + } + }, + "TestResourceResource": { + "Type": "AWS::ApiGateway::Resource", + "Properties": { + "ParentId": { + "Fn::Sub": "${RestApi.RootResourceId}" + }, + "PathPart": "test", + "RestApiId": { + "Ref": "RestApi" + } + } + }, + "TestResourcePermission": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "TestResourceHandler", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${RestApi}/*/*/*" + } + } + }, + "TestResourceRootPermission": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "TestResourceHandler", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${RestApi}/*/*/" + } + } + }, + "TestResourceOptions": { + "Type": "AWS::ApiGateway::Method", + "Properties": { + "HttpMethod": "OPTIONS", + "ResourceId": { + "Ref": "TestResourceResource" + }, + "RestApiId": { + "Ref": "RestApi" + }, + "AuthorizationType": "NONE", + "Integration": { + "IntegrationHttpMethod": "POST", + "Type": "AWS_PROXY", + "Uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${TestResourceHandler.Arn}/invocations" + } + } + } + }, + "TestResourceGet": { + "Type": "AWS::ApiGateway::Method", + "Properties": { + "HttpMethod": "GET", + "ResourceId": { + "Ref": "TestResourceResource" + }, + "RestApiId": { + "Ref": "RestApi" + }, + "AuthorizationType": "COGNITO_USER_POOLS", + "AuthorizerId": { + "Ref": "RestApiAuthorizer" + }, + "Integration": { + "IntegrationHttpMethod": "POST", + "Type": "AWS_PROXY", + "Uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${TestResourceHandler.Arn}/invocations" + } + } + } + }, + "JwtResourceHandler": { + "Type": "AWS::Lambda::Function", + "Metadata": { + "guard": { + "SuppressedRules": [ + "LAMBDA_INSIDE_VPC" + ] + } + }, + "Properties": { + "Handler": "bootstrap", + "FunctionName": { + "Fn::Sub": "${AppName}-jwt-handler" + }, + "Runtime": "provided.al2023", + "Code": { + "S3Bucket": "rain-artifacts-207567786752-us-east-1", + "S3Key": "15d7c92b571beed29cf6c012a96022482eee1df1b477ad528ddc03a4be52c076" + }, + "Role": { + "Fn::GetAtt": [ + "JwtResourceHandlerRole", + "Arn" + ] + }, + "Environment": { + "Variables": { + "COGNITO_REGION": "us-east-1", + "COGNITO_POOL_ID": { + "Ref": "CognitoUserPool" + }, + "COGNITO_REDIRECT_URI": { + "Fn::Sub": "https://${SiteDistribution.DomainName}/index.html" + }, + "COGNITO_DOMAIN_PREFIX": { + "Ref": "AppName" + }, + "COGNITO_APP_CLIENT_ID": { + "Ref": "CognitoClient" + } + } + } + } + }, + "JwtResourceHandlerRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + }, + "Action": [ + "sts:AssumeRole" + ] + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + } + }, + "JwtResourceResource": { + "Type": "AWS::ApiGateway::Resource", + "Properties": { + "ParentId": { + "Fn::Sub": "${RestApi.RootResourceId}" + }, + "PathPart": "jwt", + "RestApiId": { + "Ref": "RestApi" + } + } + }, + "JwtResourcePermission": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "JwtResourceHandler", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${RestApi}/*/*/*" + } + } + }, + "JwtResourceRootPermission": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "JwtResourceHandler", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${RestApi}/*/*/" + } + } + }, + "JwtResourceOptions": { + "Type": "AWS::ApiGateway::Method", + "Properties": { + "HttpMethod": "OPTIONS", + "ResourceId": { + "Ref": "JwtResourceResource" + }, + "RestApiId": { + "Ref": "RestApi" + }, + "AuthorizationType": "NONE", + "Integration": { + "IntegrationHttpMethod": "POST", + "Type": "AWS_PROXY", + "Uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${JwtResourceHandler.Arn}/invocations" + } + } + } + }, + "JwtResourceGet": { + "Type": "AWS::ApiGateway::Method", + "Properties": { + "HttpMethod": "GET", + "ResourceId": { + "Ref": "JwtResourceResource" + }, + "RestApiId": { + "Ref": "RestApi" + }, + "AuthorizationType": "NONE", + "AuthorizerId": "AWS::NoValue", + "Integration": { + "IntegrationHttpMethod": "POST", + "Type": "AWS_PROXY", + "Uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${JwtResourceHandler.Arn}/invocations" + } + } + } + }, + "RestApi": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "Name": { + "Ref": "AppName" + } + } + }, + "RestApiDeployment": { + "Type": "AWS::ApiGateway::Deployment", + "DependsOn": [ + "TestResourceGet", + "TestResourceOptions", + "JwtResourceGet", + "JwtResourceOptions" + ], + "Metadata": { + "Version": 2 + }, + "Properties": { + "RestApiId": { + "Ref": "RestApi" + } + } + }, + "RestApiStage": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "RestApiId": { + "Ref": "RestApi" + }, + "DeploymentId": { + "Ref": "RestApiDeployment" + }, + "StageName": "prod" + } + }, + "RestApiAuthorizer": { + "Type": "AWS::ApiGateway::Authorizer", + "Properties": { + "IdentitySource": "method.request.header.authorization", + "Name": "CognitoApiAuthorizer", + "ProviderARNs": [ + { + "Fn::GetAtt": [ + "CognitoUserPool", + "Arn" + ] + } + ], + "RestApiId": { + "Ref": "RestApi" + }, + "Type": "COGNITO_USER_POOLS" + } + } + }, + "Outputs": { + "SiteURL": { + "Value": { + "Fn::Sub": "https://${SiteDistribution.DomainName}" + } + }, + "RedirectURI": { + "Value": { + "Fn::Sub": "https://${SiteDistribution.DomainName}/index.html" + } + }, + "AppName": { + "Value": { + "Ref": "AppName" + } + }, + "RestApiInvokeURL": { + "Value": { + "Fn::Sub": "https://${RestApi}.execute-api.${AWS::Region}.amazonaws.com/${RestApiStage}" + } + }, + "AppClientId": { + "Value": { + "Ref": "CognitoClient" + } + }, + "CognitoDomainPrefix": { + "Value": { + "Ref": "AppName" + } + } + } +} diff --git a/human_reference_dataset/aws-cloudformation-templates/Solutions/WebApp/webapp.yaml b/human_reference_dataset/aws-cloudformation-templates/Solutions/WebApp/webapp.yaml new file mode 100644 index 0000000000000000000000000000000000000000..343579498090a27ad0af3c090087327bfd62e40f --- /dev/null +++ b/human_reference_dataset/aws-cloudformation-templates/Solutions/WebApp/webapp.yaml @@ -0,0 +1,841 @@ +Description: Creates a web application with a static website using S3 and CloudFront, an API Gateway REST API, and a DynamoDB table, with Cognito authentication. Apache-2.0 License. Adapt this template to your needs and thoruoughly test it before introducing it in a production environment. **WARNING** This template will create resources in your account that may incur billing charges. + +Parameters: + AppName: + Type: String + Description: This name is used as a prefix for resource names + Default: rain-webapp-sample + + LambdaCodeS3Bucket: + Type: String + Description: The bucket where your lambda handler is + Default: rain-artifacts-207567786752-us-east-1 + + LambdaCodeS3Key: + Type: String + Description: The object key for your lambda handler + Default: 512113b95e9fc6345b2e19a43350af82aaa815011120288f16b1f281d5efdc95 + +Resources: + TestResourceHandlerPolicy: + Type: AWS::IAM::RolePolicy + Properties: + PolicyDocument: + Statement: + - Action: + - dynamodb:BatchGetItem + - dynamodb:GetItem + - dynamodb:Query + - dynamodb:Scan + - dynamodb:BatchWriteItem + - dynamodb:PutItem + - dynamodb:UpdateItem + Effect: Allow + Resource: + - !GetAtt TestTable.Arn + PolicyName: handler-policy + RoleName: !Ref TestResourceHandlerRole + + TestTable: + Type: AWS::DynamoDB::Table + Metadata: + guard: + SuppressedRules: + - DYNAMODB_PITR_ENABLED + Properties: + BillingMode: PAY_PER_REQUEST + TableName: !Sub ${AppName}-test + AttributeDefinitions: + - AttributeName: id + AttributeType: S + KeySchema: + - AttributeName: id + KeyType: HASH + + SiteOriginAccessControl: + Type: AWS::CloudFront::OriginAccessControl + Properties: + OriginAccessControlConfig: + Name: !Join + - "" + - - !Ref AppName + - !Select + - 2 + - !Split + - / + - !Ref AWS::StackId + OriginAccessControlOriginType: s3 + SigningBehavior: always + SigningProtocol: sigv4 + + SiteDistribution: + Type: AWS::CloudFront::Distribution + Properties: + DistributionConfig: + DefaultCacheBehavior: + CachePolicyId: 658327ea-f89d-4fab-a63d-7e88639e58f6 + Compress: true + TargetOriginId: !Sub ${AppName}-origin-1 + ViewerProtocolPolicy: redirect-to-https + DefaultRootObject: index.html + Enabled: true + HttpVersion: http2 + IPV6Enabled: true + Logging: + Bucket: !GetAtt SiteCloudFrontLogsBucket.RegionalDomainName + Origins: + - DomainName: !GetAtt SiteContentBucket.RegionalDomainName + Id: !Sub ${AppName}-origin-1 + OriginAccessControlId: !GetAtt SiteOriginAccessControl.Id + S3OriginConfig: + OriginAccessIdentity: "" + ViewerCertificate: + CloudFrontDefaultCertificate: true + WebACLId: !GetAtt SiteWebACL.Arn + Metadata: + checkov: + skip: + - id: CKV_AWS_174 + comment: Using the default cloudfront certificate with no aliases + guard: + SuppressedRules: + - CLOUDFRONT_CUSTOM_SSL_CERTIFICATE + - CLOUDFRONT_ORIGIN_FAILOVER_ENABLED + - CLOUDFRONT_SNI_ENABLED + + SiteWebACL: + Type: AWS::WAFv2::WebACL + Properties: + Name: !Sub ${AppName}-WebACLWithAMR + Scope: CLOUDFRONT + Description: Web ACL with AWS Managed Rules + DefaultAction: + Allow: {} + VisibilityConfig: + SampledRequestsEnabled: true + CloudWatchMetricsEnabled: true + MetricName: MetricForWebACLWithAMR + Tags: + - Key: Name + Value: !Ref AppName + Rules: + - Name: AWS-AWSManagedRulesCommonRuleSet + Priority: 0 + OverrideAction: + None: {} + VisibilityConfig: + SampledRequestsEnabled: true + CloudWatchMetricsEnabled: true + MetricName: MetricForAMRCRS + Statement: + ManagedRuleGroupStatement: + VendorName: AWS + Name: AWSManagedRulesCommonRuleSet + ExcludedRules: + - Name: NoUserAgent_HEADER + + SiteContentLogBucket: + Type: AWS::S3::Bucket + Properties: + BucketEncryption: + ServerSideEncryptionConfiguration: + - ServerSideEncryptionByDefault: + SSEAlgorithm: AES256 + BucketName: !Sub ${AppName}-content-logs-${AWS::Region}-${AWS::AccountId} + ObjectLockConfiguration: + ObjectLockEnabled: Enabled + Rule: + DefaultRetention: + Mode: COMPLIANCE + Years: 1 + ObjectLockEnabled: true + PublicAccessBlockConfiguration: + BlockPublicAcls: true + BlockPublicPolicy: true + IgnorePublicAcls: true + RestrictPublicBuckets: true + VersioningConfiguration: + Status: Enabled + Metadata: + Comment: This bucket records access logs for the main bucket + checkov: + skip: + - comment: This is the log bucket + id: CKV_AWS_18 + guard: + SuppressedRules: + - S3_BUCKET_LOGGING_ENABLED + - S3_BUCKET_REPLICATION_ENABLED + + SiteContentBucket: + Type: AWS::S3::Bucket + Properties: + BucketEncryption: + ServerSideEncryptionConfiguration: + - ServerSideEncryptionByDefault: + SSEAlgorithm: AES256 + BucketName: !Sub ${AppName}-content-${AWS::Region}-${AWS::AccountId} + LoggingConfiguration: + DestinationBucketName: !Ref SiteContentLogBucket + ObjectLockEnabled: false + PublicAccessBlockConfiguration: + BlockPublicAcls: true + BlockPublicPolicy: true + IgnorePublicAcls: true + RestrictPublicBuckets: true + ReplicationConfiguration: + Role: !GetAtt SiteContentReplicationRole.Arn + Rules: + - Destination: + Bucket: !GetAtt SiteContentReplicaBucket.Arn + Status: Enabled + VersioningConfiguration: + Status: Enabled + Metadata: + guard: + SuppressedRules: + - S3_BUCKET_DEFAULT_LOCK_ENABLED + + SiteContentReplicaBucket: + Type: AWS::S3::Bucket + Properties: + BucketEncryption: + ServerSideEncryptionConfiguration: + - ServerSideEncryptionByDefault: + SSEAlgorithm: AES256 + BucketName: !Sub ${AppName}-content-replicas-${AWS::Region}-${AWS::AccountId} + ObjectLockEnabled: false + PublicAccessBlockConfiguration: + BlockPublicAcls: true + BlockPublicPolicy: true + IgnorePublicAcls: true + RestrictPublicBuckets: true + VersioningConfiguration: + Status: Enabled + Metadata: + Comment: This bucket is used as a target for replicas from the main bucket + checkov: + skip: + - comment: This is the replica bucket + id: CKV_AWS_18 + guard: + SuppressedRules: + - S3_BUCKET_DEFAULT_LOCK_ENABLED + - S3_BUCKET_REPLICATION_ENABLED + - S3_BUCKET_LOGGING_ENABLED + + SiteContentReplicationPolicy: + Type: AWS::IAM::RolePolicy + Properties: + PolicyDocument: + Statement: + - Action: + - s3:GetReplicationConfiguration + - s3:ListBucket + Effect: Allow + Resource: !Sub arn:${AWS::Partition}:s3:::${AppName}-content-${AWS::Region}-${AWS::AccountId} + - Action: + - s3:GetObjectVersionForReplication + - s3:GetObjectVersionAcl + - s3:GetObjectVersionTagging + Effect: Allow + Resource: !Sub arn:${AWS::Partition}:s3:::${AppName}-content-${AWS::Region}-${AWS::AccountId}/* + - Action: + - s3:ReplicateObject + - s3:ReplicateDelete + - s3:ReplicationTags + Effect: Allow + Resource: !Sub arn:${AWS::Partition}:s3:::${AppName}-content-replicas-${AWS::Region}-${AWS::AccountId}/* + Version: "2012-10-17" + PolicyName: bucket-replication-policy + RoleName: !Ref SiteContentReplicationRole + + SiteContentReplicationRole: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Statement: + - Action: + - sts:AssumeRole + Effect: Allow + Principal: + Service: + - s3.amazonaws.com + Version: "2012-10-17" + Path: / + + SiteContentLogBucketAccessPolicy: + Type: AWS::S3::BucketPolicy + Properties: + Bucket: !Sub ${AppName}-content-logs-${AWS::Region}-${AWS::AccountId} + PolicyDocument: + Statement: + - Action: s3:* + Condition: + Bool: + aws:SecureTransport: false + Effect: Deny + Principal: + AWS: '*' + Resource: + - !Sub arn:${AWS::Partition}:s3:::${AppName}-content-logs-${AWS::Region}-${AWS::AccountId} + - !Sub arn:${AWS::Partition}:s3:::${AppName}-content-logs-${AWS::Region}-${AWS::AccountId}/* + - Action: s3:PutObject + Condition: + ArnLike: + aws:SourceArn: !Sub arn:${AWS::Partition}:s3:::${AppName}-content-logs-${AWS::Region}-${AWS::AccountId} + StringEquals: + aws:SourceAccount: !Ref AWS::AccountId + Effect: Allow + Principal: + Service: logging.s3.amazonaws.com + Resource: + - !Sub arn:${AWS::Partition}:s3:::${AppName}-content-logs-${AWS::Region}-${AWS::AccountId}/* + Version: "2012-10-17" + + SiteContentBucketAccessPolicy: + Type: AWS::S3::BucketPolicy + Properties: + Bucket: !Sub ${AppName}-content-${AWS::Region}-${AWS::AccountId} + PolicyDocument: + Statement: + - Action: s3:GetObject + Effect: Allow + Resource: !Sub arn:${AWS::Partition}:s3:::${AppName}-content-${AWS::Region}-${AWS::AccountId}/* + Principal: + Service: cloudfront.amazonaws.com + Condition: + StringEquals: + AWS:SourceArn: !Sub arn:${AWS::Partition}:cloudfront::${AWS::AccountId}:distribution/${SiteDistribution.Id} + - Action: s3:* + Condition: + Bool: + aws:SecureTransport: false + Effect: Deny + Principal: + AWS: '*' + Resource: + - !Sub arn:${AWS::Partition}:s3:::${AppName}-content-${AWS::Region}-${AWS::AccountId} + - !Sub arn:${AWS::Partition}:s3:::${AppName}-content-${AWS::Region}-${AWS::AccountId}/* + - Action: s3:PutObject + Condition: + ArnLike: + aws:SourceArn: !Sub arn:${AWS::Partition}:s3:::${AppName}-content-${AWS::Region}-${AWS::AccountId} + StringEquals: + aws:SourceAccount: !Ref AWS::AccountId + Effect: Allow + Principal: + Service: logging.s3.amazonaws.com + Resource: + - !Sub arn:${AWS::Partition}:s3:::${AppName}-content-${AWS::Region}-${AWS::AccountId}/* + Version: "2012-10-17" + + SiteContentReplicaBucketAccessPolicy: + Type: AWS::S3::BucketPolicy + Properties: + Bucket: !Sub ${AppName}-content-replicas-${AWS::Region}-${AWS::AccountId} + PolicyDocument: + Statement: + - Action: s3:* + Condition: + Bool: + aws:SecureTransport: false + Effect: Deny + Principal: + AWS: '*' + Resource: + - !Sub arn:${AWS::Partition}:s3:::${AppName}-content-replicas-${AWS::Region}-${AWS::AccountId} + - !Sub arn:${AWS::Partition}:s3:::${AppName}-content-replicas-${AWS::Region}-${AWS::AccountId}/* + - Action: s3:PutObject + Condition: + ArnLike: + aws:SourceArn: !Sub arn:${AWS::Partition}:s3:::${AppName}-content-replicas-${AWS::Region}-${AWS::AccountId} + StringEquals: + aws:SourceAccount: !Ref AWS::AccountId + Effect: Allow + Principal: + Service: logging.s3.amazonaws.com + Resource: + - !Sub arn:${AWS::Partition}:s3:::${AppName}-content-replicas-${AWS::Region}-${AWS::AccountId}/* + Version: "2012-10-17" + + SiteCloudFrontLogsLogBucket: + Type: AWS::S3::Bucket + Properties: + BucketEncryption: + ServerSideEncryptionConfiguration: + - ServerSideEncryptionByDefault: + SSEAlgorithm: AES256 + BucketName: !Sub ${AppName}-cflogs-logs-${AWS::Region}-${AWS::AccountId} + ObjectLockConfiguration: + ObjectLockEnabled: Enabled + Rule: + DefaultRetention: + Mode: COMPLIANCE + Years: 1 + ObjectLockEnabled: true + PublicAccessBlockConfiguration: + BlockPublicAcls: true + BlockPublicPolicy: true + IgnorePublicAcls: true + RestrictPublicBuckets: true + VersioningConfiguration: + Status: Enabled + Metadata: + Comment: This bucket records access logs for the main bucket + checkov: + skip: + - comment: This is the log bucket + id: CKV_AWS_18 + guard: + SuppressedRules: + - S3_BUCKET_LOGGING_ENABLED + - S3_BUCKET_REPLICATION_ENABLED + + SiteCloudFrontLogsBucket: + Type: AWS::S3::Bucket + Properties: + BucketEncryption: + ServerSideEncryptionConfiguration: + - ServerSideEncryptionByDefault: + SSEAlgorithm: AES256 + BucketName: !Sub ${AppName}-cflogs-${AWS::Region}-${AWS::AccountId} + LoggingConfiguration: + DestinationBucketName: !Ref SiteCloudFrontLogsLogBucket + ObjectLockEnabled: false + PublicAccessBlockConfiguration: + BlockPublicAcls: true + BlockPublicPolicy: true + IgnorePublicAcls: true + RestrictPublicBuckets: true + ReplicationConfiguration: + Role: !GetAtt SiteCloudFrontLogsReplicationRole.Arn + Rules: + - Destination: + Bucket: !GetAtt SiteCloudFrontLogsReplicaBucket.Arn + Status: Enabled + VersioningConfiguration: + Status: Enabled + OwnershipControls: + Rules: + - ObjectOwnership: BucketOwnerPreferred + Metadata: + guard: + SuppressedRules: + - S3_BUCKET_DEFAULT_LOCK_ENABLED + + SiteCloudFrontLogsReplicaBucket: + Type: AWS::S3::Bucket + Properties: + BucketEncryption: + ServerSideEncryptionConfiguration: + - ServerSideEncryptionByDefault: + SSEAlgorithm: AES256 + BucketName: !Sub ${AppName}-cflogs-replicas-${AWS::Region}-${AWS::AccountId} + ObjectLockEnabled: false + PublicAccessBlockConfiguration: + BlockPublicAcls: true + BlockPublicPolicy: true + IgnorePublicAcls: true + RestrictPublicBuckets: true + VersioningConfiguration: + Status: Enabled + Metadata: + Comment: This bucket is used as a target for replicas from the main bucket + checkov: + skip: + - comment: This is the replica bucket + id: CKV_AWS_18 + guard: + SuppressedRules: + - S3_BUCKET_DEFAULT_LOCK_ENABLED + - S3_BUCKET_REPLICATION_ENABLED + - S3_BUCKET_LOGGING_ENABLED + + SiteCloudFrontLogsReplicationPolicy: + Type: AWS::IAM::RolePolicy + Properties: + PolicyDocument: + Statement: + - Action: + - s3:GetReplicationConfiguration + - s3:ListBucket + Effect: Allow + Resource: !Sub arn:${AWS::Partition}:s3:::${AppName}-cflogs-${AWS::Region}-${AWS::AccountId} + - Action: + - s3:GetObjectVersionForReplication + - s3:GetObjectVersionAcl + - s3:GetObjectVersionTagging + Effect: Allow + Resource: !Sub arn:${AWS::Partition}:s3:::${AppName}-cflogs-${AWS::Region}-${AWS::AccountId}/* + - Action: + - s3:ReplicateObject + - s3:ReplicateDelete + - s3:ReplicationTags + Effect: Allow + Resource: !Sub arn:${AWS::Partition}:s3:::${AppName}-cflogs-replicas-${AWS::Region}-${AWS::AccountId}/* + Version: "2012-10-17" + PolicyName: bucket-replication-policy + RoleName: !Ref SiteCloudFrontLogsReplicationRole + + SiteCloudFrontLogsReplicationRole: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Statement: + - Action: + - sts:AssumeRole + Effect: Allow + Principal: + Service: + - s3.amazonaws.com + Version: "2012-10-17" + Path: / + + SiteCloudFrontLogsLogBucketAccessPolicy: + Type: AWS::S3::BucketPolicy + Properties: + Bucket: !Sub ${AppName}-cflogs-logs-${AWS::Region}-${AWS::AccountId} + PolicyDocument: + Statement: + - Action: s3:* + Condition: + Bool: + aws:SecureTransport: false + Effect: Deny + Principal: + AWS: '*' + Resource: + - !Sub arn:${AWS::Partition}:s3:::${AppName}-cflogs-logs-${AWS::Region}-${AWS::AccountId} + - !Sub arn:${AWS::Partition}:s3:::${AppName}-cflogs-logs-${AWS::Region}-${AWS::AccountId}/* + - Action: s3:PutObject + Condition: + ArnLike: + aws:SourceArn: !Sub arn:${AWS::Partition}:s3:::${AppName}-cflogs-logs-${AWS::Region}-${AWS::AccountId} + StringEquals: + aws:SourceAccount: !Ref AWS::AccountId + Effect: Allow + Principal: + Service: logging.s3.amazonaws.com + Resource: + - !Sub arn:${AWS::Partition}:s3:::${AppName}-cflogs-logs-${AWS::Region}-${AWS::AccountId}/* + Version: "2012-10-17" + + SiteCloudFrontLogsBucketAccessPolicy: + Type: AWS::S3::BucketPolicy + Properties: + Bucket: !Sub ${AppName}-cflogs-${AWS::Region}-${AWS::AccountId} + PolicyDocument: + Statement: + - Action: s3:* + Condition: + Bool: + aws:SecureTransport: false + Effect: Deny + Principal: + AWS: '*' + Resource: + - !Sub arn:${AWS::Partition}:s3:::${AppName}-cflogs-${AWS::Region}-${AWS::AccountId} + - !Sub arn:${AWS::Partition}:s3:::${AppName}-cflogs-${AWS::Region}-${AWS::AccountId}/* + - Action: s3:PutObject + Condition: + ArnLike: + aws:SourceArn: !Sub arn:${AWS::Partition}:s3:::${AppName}-cflogs-${AWS::Region}-${AWS::AccountId} + StringEquals: + aws:SourceAccount: !Ref AWS::AccountId + Effect: Allow + Principal: + Service: logging.s3.amazonaws.com + Resource: + - !Sub arn:${AWS::Partition}:s3:::${AppName}-cflogs-${AWS::Region}-${AWS::AccountId}/* + Version: "2012-10-17" + + SiteCloudFrontLogsReplicaBucketAccessPolicy: + Type: AWS::S3::BucketPolicy + Properties: + Bucket: !Sub ${AppName}-cflogs-replicas-${AWS::Region}-${AWS::AccountId} + PolicyDocument: + Statement: + - Action: s3:* + Condition: + Bool: + aws:SecureTransport: false + Effect: Deny + Principal: + AWS: '*' + Resource: + - !Sub arn:${AWS::Partition}:s3:::${AppName}-cflogs-replicas-${AWS::Region}-${AWS::AccountId} + - !Sub arn:${AWS::Partition}:s3:::${AppName}-cflogs-replicas-${AWS::Region}-${AWS::AccountId}/* + - Action: s3:PutObject + Condition: + ArnLike: + aws:SourceArn: !Sub arn:${AWS::Partition}:s3:::${AppName}-cflogs-replicas-${AWS::Region}-${AWS::AccountId} + StringEquals: + aws:SourceAccount: !Ref AWS::AccountId + Effect: Allow + Principal: + Service: logging.s3.amazonaws.com + Resource: + - !Sub arn:${AWS::Partition}:s3:::${AppName}-cflogs-replicas-${AWS::Region}-${AWS::AccountId}/* + Version: "2012-10-17" + + CognitoUserPool: + Type: AWS::Cognito::UserPool + Properties: + UserPoolName: !Ref AppName + AdminCreateUserConfig: + AllowAdminCreateUserOnly: true + AutoVerifiedAttributes: + - email + Schema: + - Name: email + Required: true + - Name: given_name + Required: true + - Name: family_name + Required: true + DependsOn: + - SiteDistribution + + CognitoDomain: + Type: AWS::Cognito::UserPoolDomain + Properties: + Domain: !Ref AppName + UserPoolId: !Ref CognitoUserPool + + CognitoClient: + Type: AWS::Cognito::UserPoolClient + Properties: + ClientName: !Ref AppName + GenerateSecret: false + UserPoolId: !Ref CognitoUserPool + CallbackURLs: + - !Sub https://${SiteDistribution.DomainName}/index.html + AllowedOAuthFlows: + - code + AllowedOAuthFlowsUserPoolClient: true + AllowedOAuthScopes: + - phone + - email + - openid + SupportedIdentityProviders: + - COGNITO + + TestResourceHandler: + Type: AWS::Lambda::Function + Metadata: + guard: + SuppressedRules: + - LAMBDA_INSIDE_VPC + Properties: + Handler: bootstrap + FunctionName: !Sub ${AppName}-test-handler + Runtime: provided.al2023 + Code: + S3Bucket: !Ref LambdaCodeS3Bucket + S3Key: !Ref LambdaCodeS3Key + Role: !GetAtt TestResourceHandlerRole.Arn + Environment: + Variables: + TABLE_NAME: !Ref TestTable + + TestResourceHandlerRole: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Principal: + Service: + - lambda.amazonaws.com + Action: + - sts:AssumeRole + ManagedPolicyArns: + - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole + + TestResourceResource: + Type: AWS::ApiGateway::Resource + Properties: + ParentId: !Sub ${RestApi.RootResourceId} + PathPart: test + RestApiId: !Ref RestApi + + TestResourcePermission: + Type: AWS::Lambda::Permission + Properties: + Action: lambda:InvokeFunction + FunctionName: !GetAtt TestResourceHandler.Arn + Principal: apigateway.amazonaws.com + SourceArn: !Sub arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${RestApi}/*/*/* + + TestResourceRootPermission: + Type: AWS::Lambda::Permission + Properties: + Action: lambda:InvokeFunction + FunctionName: !GetAtt TestResourceHandler.Arn + Principal: apigateway.amazonaws.com + SourceArn: !Sub arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${RestApi}/*/*/ + + TestResourceOptions: + Type: AWS::ApiGateway::Method + Properties: + HttpMethod: OPTIONS + ResourceId: !Ref TestResourceResource + RestApiId: !Ref RestApi + AuthorizationType: NONE + Integration: + IntegrationHttpMethod: POST + Type: AWS_PROXY + Uri: !Sub arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${TestResourceHandler.Arn}/invocations + + TestResourceGet: + Type: AWS::ApiGateway::Method + Properties: + HttpMethod: GET + ResourceId: !Ref TestResourceResource + RestApiId: !Ref RestApi + AuthorizationType: COGNITO_USER_POOLS + AuthorizerId: !Ref RestApiAuthorizer + Integration: + IntegrationHttpMethod: POST + Type: AWS_PROXY + Uri: !Sub arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${TestResourceHandler.Arn}/invocations + + JwtResourceHandler: + Type: AWS::Lambda::Function + Metadata: + guard: + SuppressedRules: + - LAMBDA_INSIDE_VPC + Properties: + Handler: bootstrap + FunctionName: !Sub ${AppName}-jwt-handler + Runtime: provided.al2023 + Code: + S3Bucket: rain-artifacts-207567786752-us-east-1 + S3Key: 15d7c92b571beed29cf6c012a96022482eee1df1b477ad528ddc03a4be52c076 + Role: !GetAtt JwtResourceHandlerRole.Arn + Environment: + Variables: + COGNITO_REGION: us-east-1 + COGNITO_POOL_ID: !Ref CognitoUserPool + COGNITO_REDIRECT_URI: !Sub https://${SiteDistribution.DomainName}/index.html + COGNITO_DOMAIN_PREFIX: !Ref AppName + COGNITO_APP_CLIENT_ID: !Ref CognitoClient + + JwtResourceHandlerRole: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Principal: + Service: + - lambda.amazonaws.com + Action: + - sts:AssumeRole + ManagedPolicyArns: + - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole + + JwtResourceResource: + Type: AWS::ApiGateway::Resource + Properties: + ParentId: !Sub ${RestApi.RootResourceId} + PathPart: jwt + RestApiId: !Ref RestApi + + JwtResourcePermission: + Type: AWS::Lambda::Permission + Properties: + Action: lambda:InvokeFunction + FunctionName: !GetAtt JwtResourceHandler.Arn + Principal: apigateway.amazonaws.com + SourceArn: !Sub arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${RestApi}/*/*/* + + JwtResourceRootPermission: + Type: AWS::Lambda::Permission + Properties: + Action: lambda:InvokeFunction + FunctionName: !GetAtt JwtResourceHandler.Arn + Principal: apigateway.amazonaws.com + SourceArn: !Sub arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${RestApi}/*/*/ + + JwtResourceOptions: + Type: AWS::ApiGateway::Method + Properties: + HttpMethod: OPTIONS + ResourceId: !Ref JwtResourceResource + RestApiId: !Ref RestApi + AuthorizationType: NONE + Integration: + IntegrationHttpMethod: POST + Type: AWS_PROXY + Uri: !Sub arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${JwtResourceHandler.Arn}/invocations + + JwtResourceGet: + Type: AWS::ApiGateway::Method + Properties: + HttpMethod: GET + ResourceId: !Ref JwtResourceResource + RestApiId: !Ref RestApi + AuthorizationType: NONE + AuthorizerId: AWS::NoValue + Integration: + IntegrationHttpMethod: POST + Type: AWS_PROXY + Uri: !Sub arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${JwtResourceHandler.Arn}/invocations + + RestApi: + Type: AWS::ApiGateway::RestApi + Properties: + Name: !Ref AppName + + RestApiDeployment: + Type: AWS::ApiGateway::Deployment + Properties: + RestApiId: !Ref RestApi + Metadata: + Version: 2 + DependsOn: + - TestResourceGet + - TestResourceOptions + - JwtResourceGet + - JwtResourceOptions + + RestApiStage: + Type: AWS::ApiGateway::Stage + Properties: + RestApiId: !Ref RestApi + DeploymentId: !Ref RestApiDeployment + StageName: prod + + RestApiAuthorizer: + Type: AWS::ApiGateway::Authorizer + Properties: + IdentitySource: method.request.header.authorization + Name: CognitoApiAuthorizer + ProviderARNs: + - !GetAtt CognitoUserPool.Arn + RestApiId: !Ref RestApi + Type: COGNITO_USER_POOLS + +Outputs: + SiteURL: + Value: !Sub https://${SiteDistribution.DomainName} + + RedirectURI: + Value: !Sub https://${SiteDistribution.DomainName}/index.html + + AppName: + Value: !Ref AppName + + RestApiInvokeURL: + Value: !Sub https://${RestApi}.execute-api.${AWS::Region}.amazonaws.com/${RestApiStage} + + AppClientId: + Value: !Ref CognitoClient + + CognitoDomainPrefix: + Value: !Ref AppName