Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

CI/CD updates for EFS mapping (#771)

Rich Turner9d27a06d480f
diff --git a/.ci_cd/aws/cloudformation-create-ec2.yml b/.ci_cd/aws/cloudformation-create-ec2.yml
index 8d119780f..e0d4215ef 100644
--- a/.ci_cd/aws/cloudformation-create-ec2.yml
+++ b/.ci_cd/aws/cloudformation-create-ec2.yml
@@ -9,9 +9,12 @@
#
# Optionally assign an Elastic IP address by setting the ElasticIP parameter to true.
#
+# Environment variables are optionally output to /etc/environment for:
+# - EFS_DNS for an EFS that can then be mounted from docker services without having to put IP address in docker-compose
+# - SMTP Credentials for use within docker services to simplify SMTP configuration
+#
# Systemd services are also created to:
#
-# - Mount EFS volume named 'hosts-filesystem' at /deployment.local/efs on restart
# - Perform daily backup of /deployment.local/backup if an S3 bucket with the same name as the FQDN for this host exists
# (periods replaced with hyphen e.g. demo.openremote.app -> demo-openremote-app)
# - Update DNS A record on restart
@@ -39,6 +42,9 @@ Parameters:
SSHSecurityGroupId:
Description: SSH Security Group ID
Type: String
+ EFSDNS:
+ Description: EFS DNS entry (for maps)
+ Type: String
ImageId:
Description: AMI ID
Type: String
@@ -75,6 +81,13 @@ Parameters:
- true
- false
Default: false
+ HealthChecks:
+ Description: Create health checks
+ Type: String
+ AllowedValues:
+ - true
+ - false
+ Default: true
SMTPHost:
Type: String
Default: ""
@@ -99,9 +112,9 @@ Parameters:
Conditions:
AssignElasticIP: !Equals [!Ref ElasticIP, "true"]
+ CreateHealthChecks: !Equals [!Ref HealthChecks, "true"]
Resources:
-
InstanceRoleProfile:
Type: AWS::IAM::InstanceProfile
Properties:
@@ -479,13 +492,11 @@ Resources:
echo 'OR_EMAIL_X_HEADERS="X-SES-SOURCE-ARN: ${SMTPORArn}"' >> /etc/environment
fi
02_efs_dns:
- command: !Sub |
- # Look for EFS filesystem called hosts-filesystem and create env variable for it
- FILESYSTEMID=$(aws efs describe-file-systems --query "FileSystems[?Name=='hosts-filesystem'].FileSystemId" --output text --region ${AWS::Region})
-
- if [ -n "$FILESYSTEMID" ]; then
- echo "EFS Filesystem found: $FILESYSTEMID"
- echo "EFS_DNS=$FILESYSTEMID.efs.${AWS::Region}.amazonaws.com" >> /etc/environment
+ command: !Sub |
+ # Output EFS_DNS to /etc/environment
+ if [ -n "${EFSDNS}" ]; then
+ echo "EFS Filesystem DNS: ${EFSDNS}"
+ echo "EFS_DNS=${EFSDNS}" >> /etc/environment
fi
docker_setup:
@@ -625,6 +636,7 @@ Resources:
SystemStatusAlarm:
Type: AWS::CloudWatch::Alarm
+ Condition: CreateHealthChecks
Properties:
Namespace: AWS/EC2
MetricName: StatusCheckFailed_System
@@ -644,6 +656,7 @@ Resources:
InstanceStatusAlarm:
Type: AWS::CloudWatch::Alarm
+ Condition: CreateHealthChecks
Properties:
Namespace: AWS/EC2
MetricName: StatusCheckFailed_Instance
@@ -682,6 +695,7 @@ Resources:
HealthCheckAlarm:
Type: AWS::CloudWatch::Alarm
+ Condition: CreateHealthChecks
Properties:
Namespace: AWS/Route53
MetricName: HealthCheckStatus
@@ -700,6 +714,7 @@ Resources:
HealthCheck:
Type: AWS::Route53::HealthCheck
+ Condition: CreateHealthChecks
DependsOn: EC2Instance
Properties:
HealthCheckConfig:
diff --git a/.ci_cd/aws/cloudformation-create-efs.yml b/.ci_cd/aws/cloudformation-create-efs.yml
index aab64f560..4153e31cd 100644
--- a/.ci_cd/aws/cloudformation-create-efs.yml
+++ b/.ci_cd/aws/cloudformation-create-efs.yml
@@ -1,19 +1,14 @@
# ---------------------------------------------------------------------------------------------
-# Provisions an EFS using the specified VPC, Subnets and Security Group (they must belong to
-# the same VPC). Also adds ingress rule for VPC CIDR (IPv4 and/or IPv6) TCP port 2049. This
-# is intended to be used to create an EFS that can be shared by all hosts within the VPC
+# Provisions an EFS using the specified VPC and subnets; creates a security group called
+# `or-map`.
# ---------------------------------------------------------------------------------------------
AWSTemplateFormatVersion: 2010-09-09
Description: Hosts EFS
Parameters:
- VPCIP4CIDR:
+ VpcId:
Type: String
- Description: The VPC IPv4 CIDR
-
- VPCIP6CIDR:
- Type: String
- Description: The VPC IPv6 CIDR
+ Description: The VPC ID
SubnetID1:
Type: AWS::EC2::Subnet::Id
@@ -27,15 +22,20 @@ Parameters:
Type: AWS::EC2::Subnet::Id
Description: Mount target 3 subnet ID
- SecurityGroupID:
- Type: AWS::EC2::SecurityGroup::Id
- Description: Security group for mount targets
-
Conditions:
- CreateIPV4Ingress: !Not [!Equals [!Ref VPCIP4CIDR, ""]]
- CreateIPV6Ingress: !Not [!Equals [!Ref VPCIP6CIDR, ""]]
+ CreateTarget1: !Not [!Equals [!Ref SubnetID1, ""]]
+ CreateTarget2: !Not [!Equals [!Ref SubnetID2, ""]]
+ CreateTarget3: !Not [!Equals [!Ref SubnetID3, ""]]
Resources:
+ SecurityGroup:
+ Type: AWS::EC2::SecurityGroup
+ Properties:
+ GroupDescription: "OR Map EFS access"
+ VpcId: !Ref VpcId
+ Tags:
+ - Key: Name
+ Value: or-map
FileSystem:
Type: 'AWS::EFS::FileSystem'
@@ -48,7 +48,7 @@ Resources:
- TransitionToIA: AFTER_30_DAYS
FileSystemTags:
- Key: Name
- Value: hosts-filesystem
+ Value: or-map-efs
# FileSystemPolicy:
# Version: "2012-10-17"
# Statement:
@@ -61,48 +61,53 @@ Resources:
# StringEquals:
# 'aws:PrincipalOrgID': o-dhb7rpaban
+
+
MountTargetResource1:
Type: AWS::EFS::MountTarget
+ Condition: CreateTarget1
Properties:
FileSystemId: !Ref FileSystem
SubnetId: !Ref SubnetID1
SecurityGroups:
- - !Ref SecurityGroupID
+ - !Ref SecurityGroup
MountTargetResource2:
Type: AWS::EFS::MountTarget
+ Condition: CreateTarget2
Properties:
FileSystemId: !Ref FileSystem
SubnetId: !Ref SubnetID2
SecurityGroups:
- - !Ref SecurityGroupID
+ - !Ref SecurityGroup
MountTargetResource3:
Type: AWS::EFS::MountTarget
+ Condition: CreateTarget3
Properties:
FileSystemId: !Ref FileSystem
SubnetId: !Ref SubnetID3
SecurityGroups:
- - !Ref SecurityGroupID
+ - !Ref SecurityGroup
- SecurityGroupIngressIP4:
- Condition: CreateIPV4Ingress
- Type: AWS::EC2::SecurityGroupIngress
- Properties:
- CidrIp: !Ref VPCIP4CIDR
- GroupId: !Ref SecurityGroupID
- Description: "EFS for VPC"
- FromPort: 2049
- IpProtocol: "tcp"
- ToPort: 2049
-
- SecurityGroupIngressIP6:
- Condition: CreateIPV6Ingress
- Type: AWS::EC2::SecurityGroupIngress
- Properties:
- CidrIpv6: !Ref VPCIP6CIDR
- GroupId: !Ref SecurityGroupID
- Description: "EFS for VPC"
- FromPort: 2049
- IpProtocol: "tcp"
- ToPort: 2049
+# SecurityGroupIngressIP4:
+# Condition: CreateIPV4Ingress
+# Type: AWS::EC2::SecurityGroupIngress
+# Properties:
+# CidrIp: !Ref VPCIP4CIDR
+# GroupId: !Ref SecurityGroupID
+# Description: "EFS for VPC"
+# FromPort: 2049
+# IpProtocol: "tcp"
+# ToPort: 2049
+#
+# SecurityGroupIngressIP6:
+# Condition: CreateIPV6Ingress
+# Type: AWS::EC2::SecurityGroupIngress
+# Properties:
+# CidrIpv6: !Ref VPCIP6CIDR
+# GroupId: !Ref SecurityGroupID
+# Description: "EFS for VPC"
+# FromPort: 2049
+# IpProtocol: "tcp"
+# ToPort: 2049
diff --git a/.ci_cd/aws/cloudformation-create-vpc.yml b/.ci_cd/aws/cloudformation-create-vpc.yml
index 05f293f2c..745412265 100644
--- a/.ci_cd/aws/cloudformation-create-vpc.yml
+++ b/.ci_cd/aws/cloudformation-create-vpc.yml
@@ -1,14 +1,46 @@
# ---------------------------------------------------------------------------------------------------------------------
-# Create standard OpenRemote VPC with 2 public and 2 private subnets
+# Create standard OpenRemote VPC with 3 public and 3 private subnets and configure IGW for public subnets
+# optional SSH access security group and optional VPC peer accepter role or peering request.
# ---------------------------------------------------------------------------------------------------------------------
AWSTemplateFormatVersion: 2010-09-09
-Description: 'Creates standard OR VPC, subnets, route tables and IGW'
+Description: 'Creates standard OR VPC, subnets, route tables and IGW; optionally create VPC Peering request or acceptor role'
Parameters:
IPV4CIDR:
- Description: IPV4CIDR for VPC
+ Description: IPv4 CIDR for VPC
Type: String
+ VPCAcceptRole:
+ Description: Create VPC Peering Accept Role
+ Type: String
+ AllowedValues:
+ - true
+ - false
+ Default: false
+ PeerVPCAccountId:
+ Description: VPC Peering acceptor Account ID
+ Type: String
+ PeerVPCId:
+ Description: VPC Peering acceptor ID
+ Type: String
+ PeerVpcCidr:
+ Description: VPC Peering acceptor CIDR
+ Type: String
+ PeerRoleArn:
+ Description: Role ARN of VPC Peering acceptor
+ Type: String
+ SSHSecurityGroup:
+ Description: Create SSH Access security group
+ Type: String
+ AllowedValues:
+ - true
+ - false
+ Default: true
+
+Conditions:
+ CreateVPCAcceptRole: !Equals [!Ref VPCAcceptRole, "true"]
+ CreateVPCPeerRequest: !Not [!Equals [!Ref PeerRoleArn, ""]]
+ CreateSSHSecurityGroup: !Equals [!Ref SSHSecurityGroup, "true"]
Resources:
## VPC
@@ -29,14 +61,52 @@ Resources:
VpcId: !Ref Vpc
AmazonProvidedIpv6CidrBlock: true
- SecurityGroup:
- Type: AWS::EC2::SecurityGroup
+ ## VPC Peering accept role
+ VPCPeerRole:
+ Type: AWS::IAM::Role
+ Condition: CreateVPCAcceptRole
+ Properties:
+ RoleName: !Join [ "-", [ "or-vpc-peer", !Ref "AWS::Region" ] ]
+ AssumeRolePolicyDocument:
+ Version: '2012-10-17'
+ Statement:
+ - Principal:
+ AWS: "*"
+ Action:
+ - 'sts:AssumeRole'
+ Effect: Allow
+ Condition:
+ StringEquals:
+ 'aws:PrincipalOrgID': o-dhb7rpaban
+ Path: /
+ Policies:
+ - PolicyName: root
+ PolicyDocument:
+ Version: '2012-10-17'
+ Statement:
+ - Effect: Allow
+ Action: 'ec2:AcceptVpcPeeringConnection'
+ Resource:
+ 'Fn::Sub': 'arn:aws:ec2:${AWS::Region}:${AWS::AccountId}:vpc/${Vpc}'
+ - Action: 'ec2:AcceptVpcPeeringConnection'
+ Condition:
+ StringEquals:
+ 'ec2:AccepterVpc':
+ 'Fn::Sub': 'arn:aws:ec2:${AWS::Region}:${AWS::AccountId}:vpc/${Vpc}'
+ Effect: Allow
+ Resource:
+ 'Fn::Sub': >-
+ arn:aws:ec2:${AWS::Region}:${AWS::AccountId}:vpc-peering-connection/*
+
+ ## VPC Peering Request
+ VpcPeeringConnection:
+ Type: 'AWS::EC2::VPCPeeringConnection'
+ Condition: CreateVPCPeerRequest
Properties:
- GroupDescription: "SSH access whitelist"
VpcId: !Ref Vpc
- Tags:
- - Key: Name
- Value: ssh-access
+ PeerVpcId: !Ref PeerVPCId
+ PeerOwnerId: !Ref PeerVPCAccountId
+ PeerRoleArn: !Ref PeerRoleArn
## SUBNETS
PublicSubnet1:
@@ -67,6 +137,20 @@ Resources:
- Key: Name
Value: or-subnet-public-2
+ PublicSubnet3:
+ Type: AWS::EC2::Subnet
+ DependsOn: VpcCidrBlockIpv6
+ Properties:
+ VpcId: !Ref Vpc
+ AvailabilityZone: !Select [ 2, !GetAZs '' ]
+ CidrBlock: !Select [ 5, !Cidr [!Ref IPV4CIDR, 7, 8]]
+ Ipv6CidrBlock: !Select [6, !Cidr [!Select [0, !GetAtt 'Vpc.Ipv6CidrBlocks'], 8, 64]]
+ AssignIpv6AddressOnCreation: true
+ MapPublicIpOnLaunch: true
+ Tags:
+ - Key: Name
+ Value: or-subnet-public-3
+
PrivateSubnet1:
Type: AWS::EC2::Subnet
DependsOn: VpcCidrBlockIpv6
@@ -95,6 +179,20 @@ Resources:
- Key: Name
Value: or-subnet-private-2
+ PrivateSubnet3:
+ Type: AWS::EC2::Subnet
+ DependsOn: VpcCidrBlockIpv6
+ Properties:
+ VpcId: !Ref Vpc
+ AvailabilityZone: !Select [ 2, !GetAZs '' ]
+ CidrBlock: !Select [ 6, !Cidr [!Ref IPV4CIDR, 7, 8]]
+ Ipv6CidrBlock: !Select [7, !Cidr [!Select [0, !GetAtt 'Vpc.Ipv6CidrBlocks'], 8, 64]]
+ AssignIpv6AddressOnCreation: true
+ MapPublicIpOnLaunch: false
+ Tags:
+ - Key: Name
+ Value: or-subnet-private-3
+
## INTERNET GATEWAY
InternetGateway:
Type: AWS::EC2::InternetGateway
@@ -110,6 +208,9 @@ Resources:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref Vpc
+ Tags:
+ - Key: Name
+ Value: or-routetable
PublicRoute:
Type: AWS::EC2::Route
@@ -119,6 +220,23 @@ Resources:
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref InternetGateway
+ PublicRoute6:
+ Type: AWS::EC2::Route
+ DependsOn: GatewayToInternet
+ Properties:
+ RouteTableId: !Ref PublicRouteTable
+ DestinationIpv6CidrBlock: ::/0
+ GatewayId: !Ref InternetGateway
+
+ VpcPeerRoute:
+ Type: AWS::EC2::Route
+ Condition: CreateVPCPeerRequest
+ DependsOn: VpcPeeringConnection
+ Properties:
+ RouteTableId: !Ref PublicRouteTable
+ DestinationCidrBlock: !Ref PeerVpcCidr
+ VpcPeeringConnectionId: !Ref VpcPeeringConnection
+
PublicSubnet1RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
@@ -130,3 +248,20 @@ Resources:
Properties:
SubnetId: !Ref PublicSubnet2
RouteTableId: !Ref PublicRouteTable
+
+ PublicSubnet3RouteTableAssociation:
+ Type: AWS::EC2::SubnetRouteTableAssociation
+ Properties:
+ SubnetId: !Ref PublicSubnet3
+ RouteTableId: !Ref PublicRouteTable
+
+ ## SSH Security Group
+ SecurityGroup:
+ Type: AWS::EC2::SecurityGroup
+ Condition: CreateSSHSecurityGroup
+ Properties:
+ GroupDescription: "SSH access whitelist"
+ VpcId: !Ref Vpc
+ Tags:
+ - Key: Name
+ Value: ssh-access
diff --git a/.ci_cd/aws/provision_account.sh b/.ci_cd/aws/provision_account.sh
index a25b2caec..29891b53c 100644
--- a/.ci_cd/aws/provision_account.sh
+++ b/.ci_cd/aws/provision_account.sh
@@ -11,7 +11,6 @@
# * Create Hosted domain zone (if requested) and will create the NS record in the PARENT_DNS_ZONE to delegate to the
# new hosted zone; the zone will use the account name.
# * Adds SSH whitelist to the ssh-access security group in the new account (see refresh_ssh_whitelist.sh)
-# * Create EFS filesystem for sharing data between instances (see cloudformation-create-efs.yml)
#
# Arguments:
# 1 - OU - Name of organizational unit where account should be provisioned (defaults to account root if not set)
@@ -19,7 +18,6 @@
# 2 - PARENT_DNS_ZONE - name of parent hosted domain zone in management account
# 3 - HOSTED_DNS - If set to 'true' a sub domain hosted zone will be provisioned in the new account and delegated from the
# PARENT_DNS_ZONE in the callee account (e.g. x.y -> AWS_ACCOUNT_NAME.x.y)
-# 4 - PROVISION_EFS set to 'false' to not provision an EFS volume for the default VPC using (cloudformation-create-efs.yml)
if [[ $BASH_SOURCE = */* ]]; then
awsDir=${BASH_SOURCE%/*}/
@@ -31,7 +29,7 @@ OU=${1}
AWS_ACCOUNT_NAME=${2,,}
PARENT_DNS_ZONE=${3,,}
HOSTED_DNS=${4,,}
-PROVISION_EFS=${5,,}
+CREATE_VPC_PEER=${5,,}
ACCOUNT_PROFILE='--profile github-da'
if [ -z "$AWS_ACCOUNT_NAME" ]; then
@@ -164,8 +162,16 @@ if [ "$VPCID" == 'None' ]; then
#Configure parameters
PARAMS="ParameterKey=IPV4CIDR,ParameterValue='$VPCIP4CIDR'"
+ # Create a VPC Peer connection to the caller account
+ if [ -n "$CREATE_VPC_PEER" ]; then
+ PEER_VPCID=$(aws ec2 describe-vpcs --filters Name=tag:Name,Values=or-vpc --query "Vpcs[0].VpcId" --output text)
+ PEER_VPCCIDR=$(aws ec2 describe-vpcs --filters Name=tag:Name,Values=or-vpc --query "Vpcs[0].CidrBlock" --output text)
+ PEER_ARN="arn:aws:iam::$CALLER_AWS_ACCOUNT_ID:role/or-vpc-peer-$AWS_REGION"
+ PARAMS="$PARAMS ParameterKey=PeerRoleArn,ParameterValue='$PEER_ARN' ParameterKey=PeerVPCId,ParameterValue='$PEER_VPCID' ParameterKey=PeerVPCAccountId,ParameterValue='$CALLER_AWS_ACCOUNT_ID' ParameterKey=PeerVpcCidr,ParameterValue='$PEER_VPCCIDR'"
+ fi
+
# Create standard stack resources in specified account
- STACK_ID=$(aws cloudformation create-stack --stack-name $STACK_NAME --template-body file://$TEMPLATE_PATH --parameters $PARAMS --output text)
+ STACK_ID=$(aws cloudformation create-stack --capabilities CAPABILITY_NAMED_IAM --stack-name $STACK_NAME --template-body file://$TEMPLATE_PATH --parameters $PARAMS --output text)
# Wait for cloud formation stack status to be CREATE_*
echo "Waiting for stack to be created"
@@ -184,6 +190,14 @@ if [ "$VPCID" == 'None' ]; then
echo "Stack creation is complete"
fi
+ # Create route for VPC peer connection in caller account
+ if [ -n "$CREATE_VPC_PEER" ]; then
+ VPCID=$(aws ec2 describe-vpcs --filters Name=tag:Name,Values=or-vpc --query "Vpcs[0].VpcId" --output text $ACCOUNT_PROFILE 2>/dev/null)
+ FILTERS="Name=tag:Name,Values='or-routetable' Name=vpc-id,Values='$PEER_VPCID'"
+ ROUTE_TABLE_ID=$(aws ec2 describe-route-tables --filters $FILTERS --query "RouteTables[0].RouteTableId" --output text)
+ PEER_ID=$(aws ec2 describe-vpc-peering-connections --filters Name=requester-vpc-info.vpc-id,Values=$VPCID --query "VpcPeeringConnections[0].VpcPeeringConnectionId" --output text)
+ aws ec2 create-route --route-table-id $ROUTE_TABLE_ID --destination-cidr-block $VPCIP4CIDR --vpc-peering-connection-id $PEER_ID
+ fi
else
echo "OR VPC already exists"
fi
@@ -264,82 +278,3 @@ if [ -n "$SGID" ]; then
"${awsDir}refresh_ssh_whitelist.sh" "" "" $AWS_ACCOUNT_ID
fi
-# Provision EFS unless set to false
-if [ "$PROVISION_EFS" != 'false' ]; then
- echo "Provisioning EFS for account '$AWS_ACCOUNT_NAME' using cloud formation template"
-
- if [ -f "${awsDir}cloudformation-create-efs.yml" ]; then
- TEMPLATE_PATH="${awsDir}cloudformation-create-efs.yml"
- elif [ -f ".ci_cd/aws/cloudformation-create-efs.yml" ]; then
- TEMPLATE_PATH=".ci_cd/aws/cloudformation-create-efs.yml"
- elif [ -f "openremote/.ci_cd/aws/cloudformation-create-efs.yml" ]; then
- TEMPLATE_PATH="openremote/.ci_cd/aws/cloudformation-create-efs.yml"
- else
- echo "Cannot determine location of cloudformation-create-efs.yml so cannot provision EFS filesystem"
- fi
-
- STACK_NAME='hosts-filesystem'
-
- # Check stack doesn't already exist
- STATUS=$(aws cloudformation describe-stacks --stack-name $STACK_NAME --query "Stacks[0].StackStatus" --output text $ACCOUNT_PROFILE 2>/dev/null)
-
- if [ -n "$STATUS" ] && [ "$STATUS" != 'DELETE_COMPLETE' ]; then
- echo "EFS stack already exists"
- else
-
- # Find Default VPC security group and IP CIDRs
- VPCIP4CIDR=$(aws ec2 describe-vpcs --filters Name=tag:Name,Values=or-vpc --query "Vpcs[0].CidrBlockAssociationSet[0].CidrBlock" --output text $ACCOUNT_PROFILE 2>/dev/null)
- VPCIP6CIDR=$(aws ec2 describe-vpcs --filters Name=tag:Name,Values=or-vpc --query "Vpcs[0].Ipv6CidrBlockAssociationSet[0].Ipv6CidrBlock" --output text $ACCOUNT_PROFILE 2>/dev/null)
-
- if [ "$VPCIP4CIDR" == 'None' ]; then
- unset VPCIP4CIDR
- fi
- if [ "$VPCIP6CIDR" == 'None' ]; then
- unset VPCIP6CIDR
- fi
-
- if [ -z "$VPCIP4CIDR" ] && [ -z "$VPCIP6CIDR" ]; then
- echo "OR VPC not found"
- else
-
- SGID=$(aws ec2 describe-security-groups --filters Name=vpc-id,Values=$VPCID --group-names 'default' --query "SecurityGroups[0].GroupId" --output text $ACCOUNT_PROFILE 2>/dev/null)
-
- if [ -z "$SGID" ]; then
- echo "Security group for OR VPC not found"
- exit 1
- else
- SUBNETIDS=$(aws ec2 describe-subnets --filters Name=vpc-id,Values=$VPCID --query "Subnets[*].SubnetId" --output text $ACCOUNT_PROFILE 2>/dev/null)
-
- if [ -z "$SUBNETIDS" ]; then
- echo "Subnets for OR VPC not found"
- else
-
- PARAMS="ParameterKey=SecurityGroupID,ParameterValue=$SGID"
-
- if [ -n "$VPCIP4CIDR" ]; then
- PARAMS="$PARAMS ParameterKey=VPCIP4CIDR,ParameterValue=$VPCIP4CIDR"
- fi
- if [ -n "$VPCIP6CIDR" ]; then
- PARAMS="$PARAMS ParameterKey=VPCIP6CIDR,ParameterValue=$VPCIP6CIDR"
- fi
-
- IFS=$' \t'
- count=1
- for SUBNETID in $SUBNETIDS; do
- PARAMS="$PARAMS ParameterKey=SubnetID$count,ParameterValue=$SUBNETID"
- count=$((count+1))
- done
-
- echo "Creating stack using cloudformation-create-efs.yml"
- STACK_ID=$(aws cloudformation create-stack --capabilities CAPABILITY_NAMED_IAM --stack-name $STACK_NAME --template-body file://$TEMPLATE_PATH --parameters $PARAMS --output text $ACCOUNT_PROFILE)
-
- if [ $? -ne 0 ]; then
- echo "Create stack failed"
- else
- echo "Create stack in progress"
- fi
- fi
- fi
- fi
- fi
-fi
diff --git a/.ci_cd/aws/provision_host.sh b/.ci_cd/aws/provision_host.sh
index ddeb04aaf..46d3a0ece 100644
--- a/.ci_cd/aws/provision_host.sh
+++ b/.ci_cd/aws/provision_host.sh
@@ -194,14 +194,22 @@ EOF
PARAMS="$PARAMS ParameterKey=DNSHostedZoneRoleArn,ParameterValue=$DNSHostedZoneRoleArn"
fi
- # Get OR VPC ID, Subnet ID and SSH Security Group ID
+ # Get OR VPC ID, Subnet ID, SSH Security Group ID and EFS MOUNT TARGET IP
VPCID=$(aws ec2 describe-vpcs --filters Name=tag:Name,Values=or-vpc --query "Vpcs[0].VpcId" --output text $ACCOUNT_PROFILE 2>/dev/null)
- SUBNETNAME="or-subnet-public-$(( $RANDOM % 2 + 1 ))"
+ SUBNET_NUMBER=$(( $RANDOM % 3 + 1 ))
+ SUBNETNAME="or-subnet-public-$SUBNET_NUMBER"
SUBNETID=$(aws ec2 describe-subnets --filters Name=tag:Name,Values=$SUBNETNAME --query "Subnets[0].SubnetId" --output text $ACCOUNT_PROFILE 2>/dev/null)
+ SUBNET_AZ=$(aws ec2 describe-subnets --filters Name=tag:Name,Values=$SUBNETNAME --query "Subnets[0].AvailabilityZone" --output text $ACCOUNT_PROFILE 2>/dev/null)
SGID=$(aws ec2 describe-security-groups --filters Name=tag:Name,Values=ssh-access --query "SecurityGroups[0].GroupId" --output text $ACCOUNT_PROFILE 2>/dev/null)
+
+ # Look for EFS mount target in caller account for the same availability zone (no costs if within same AZ)
+ EFS_ID=$(aws efs describe-file-systems --query "FileSystems[?Name=='or-map-efs'].FileSystemId" --output text)
+ EFS_DNS=$(aws efs describe-mount-targets --file-system-id $EFS_ID --query "MountTargets[?AvailabilityZoneName=='$SUBNET_AZ'].IpAddress" --output text)
+
PARAMS="$PARAMS ParameterKey=VpcId,ParameterValue=$VPCID"
PARAMS="$PARAMS ParameterKey=SSHSecurityGroupId,ParameterValue=$SGID"
PARAMS="$PARAMS ParameterKey=SubnetId,ParameterValue=$SUBNETID"
+ PARAMS="$PARAMS ParameterKey=EFSDNS,ParameterValue=$EFS_DNS"
# Create standard stack resources in specified account
STACK_ID=$(aws cloudformation create-stack --capabilities CAPABILITY_NAMED_IAM --stack-name $STACK_NAME --template-body file://$TEMPLATE_PATH --parameters $PARAMS --output text $ACCOUNT_PROFILE)