Skip to content

Commit fbc17f0

Browse files
committed
Fix comments
1 parent 36a622c commit fbc17f0

File tree

1 file changed

+103
-28
lines changed

1 file changed

+103
-28
lines changed

Management-Utilities/ec2-user-data-iscsi-create-and-mount/EC2-cloud_formation.yaml

Lines changed: 103 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,76 @@
1+
12
AWSTemplateFormatVersion: '2010-09-09'
2-
Description: Launch EC2 instance with user data script downloaded from S3 and dynamic parameters
3+
Description: Launch EC2 instance with user data script downloaded from Github and dynamic parameters
4+
Metadata:
5+
AWS::CloudFormation::Interface:
6+
ParameterGroups:
7+
- Label:
8+
default: "EC2 Configuration"
9+
Parameters:
10+
- OperationSystem
11+
- InstanceType
12+
- InstanceName
13+
- KeyName
14+
- ImageId
15+
- VpcId
16+
- SubnetId
17+
- ManagedPolicyArn
18+
- Label:
19+
default: "FSxN Configuration"
20+
Parameters:
21+
- SecretName
22+
- AWSRegion
23+
- ManagementEndpointIP
24+
- VolumeName
25+
- VolumeSize
26+
- SvmName
27+
- DriveLetter
28+
- Label:
29+
default: "Networking"
30+
Parameters:
31+
- CidrIp
32+
- Label:
33+
default: "User Data Scripts"
34+
Parameters:
35+
- LinuxUserDataUrl
36+
- WindowsUserDataUrl
37+
ParameterLabels:
38+
OperationSystem:
39+
default: "Operating System"
40+
InstanceType:
41+
default: "Instance Type"
42+
InstanceName:
43+
default: "Instance Name"
44+
KeyName:
45+
default: "Key Pair Name"
46+
ImageId:
47+
default: "AMI ID"
48+
VpcId:
49+
default: "VPC ID"
50+
SubnetId:
51+
default: "Subnet ID"
52+
SecretName:
53+
default: "AWS Secret Name"
54+
AWSRegion:
55+
default: "AWS Region"
56+
ManagementEndpointIP:
57+
default: "Management Endpoint IP"
58+
VolumeName:
59+
default: "Volume Name"
60+
VolumeSize:
61+
default: "Volume Size (GiB)"
62+
SvmName:
63+
default: "SVM Name"
64+
DriveLetter:
65+
default: "Drive Letter (Windows Only)"
66+
CidrIp:
67+
default: "CIDR IP for SSH/RDP Access"
68+
LinuxUserDataUrl:
69+
default: "Linux User Data Script URL"
70+
WindowsUserDataUrl:
71+
default: "Windows User Data Script URL"
72+
ManagedPolicyArn:
73+
default: "IAM Managed Policy ARN"
374

475
Parameters:
576
OperationSystem:
@@ -9,7 +80,7 @@ Parameters:
980
- Windows
1081
InstanceType:
1182
Type: String
12-
Default: t3.micro
83+
Default: t3.large
1384
Description: EC2 instance type
1485
InstanceName:
1586
Type: String
@@ -20,6 +91,9 @@ Parameters:
2091
ImageId:
2192
Type: AWS::EC2::Image::Id
2293
Description: AMI ID for the instance
94+
AllowedValues:
95+
- ami-0b09ffb6d8b58ca91 # Amazon Linux 2023 Kernel-6.1 AMI (us-east-1)
96+
- ami-0e3c2921641a4a215 # Microsoft Windows Server 2025 Base (us-east-1)
2397
VpcId:
2498
Type: AWS::EC2::VPC::Id
2599
Description: VPC ID
@@ -31,10 +105,10 @@ Parameters:
31105
Description: Aws Secret name
32106
AWSRegion:
33107
Type: String
34-
Description: AWS Region
35-
FSxNAdminIp:
108+
Description: AWS Secret region(in which you have yours secret)
109+
ManagementEndpointIP :
36110
Type: String
37-
Description: FSxN Admin IP
111+
Description: Management endpoint IP Address of your FSxN
38112
VolumeName:
39113
Type: String
40114
Description: Volume Name
@@ -51,7 +125,6 @@ Parameters:
51125
Description: Drive Letter - valid for Windows only
52126
CidrIp:
53127
Type: String
54-
Default: 0.0.0.0/0 # For testing; restrict to your IP for production
55128
Description: CIDR IP for SSH access to the instance
56129
LinuxUserDataUrl:
57130
Type: String
@@ -61,11 +134,13 @@ Parameters:
61134
Type: String
62135
Default: https://raw.githubusercontent.com/NetApp/FSx-ONTAP-samples-scripts/refs/heads/main/Management-Utilities/ec2-user-data-iscsi-create-and-mount/windows_userData.ps1
63136
Description: URL to Windows user data script
64-
137+
ManagedPolicyArn:
138+
Type: String
139+
Description: IAM managed policy ARN to attach to the EC2 instance role
65140
Conditions:
66141
IsLinux: !Equals [ !Ref OperationSystem, "Linux" ]
67142
IsWindows: !Equals [ !Ref OperationSystem, "Windows" ]
68-
143+
69144
Resources:
70145
EC2InstanceSecurityGroup:
71146
Type: AWS::EC2::SecurityGroup
@@ -75,13 +150,13 @@ Resources:
75150
SecurityGroupIngress:
76151
- IpProtocol: tcp
77152
FromPort: !If
78-
- IsLinux
79-
- 22
80-
- 3389
153+
- IsLinux
154+
- 22
155+
- 3389
81156
ToPort: !If
82-
- IsLinux
83-
- 22
84-
- 3389
157+
- IsLinux
158+
- 22
159+
- 3389
85160
CidrIp: !Ref CidrIp
86161
EC2InstanceRole:
87162
Type: AWS::IAM::Role
@@ -95,7 +170,7 @@ Resources:
95170
Action: sts:AssumeRole
96171
Path: /
97172
ManagedPolicyArns:
98-
- arn:aws:iam::aws:policy/SecretsManagerReadWrite
173+
- !Ref ManagedPolicyArn
99174

100175
EC2InstanceProfile:
101176
Type: AWS::IAM::InstanceProfile
@@ -116,19 +191,19 @@ Resources:
116191
- Key: Name
117192
Value: !Ref InstanceName
118193
UserData: !If
119-
- IsLinux
120-
- Fn::Base64: !Sub |
121-
#!/bin/bash
122-
curl -o /tmp/userdata-script.sh ${LinuxUserDataUrl}
123-
chmod +x /tmp/userdata-script.sh
124-
# Pass parameters to the script
125-
/tmp/userdata-script.sh "${SecretName}" "${AWSRegion}" "${FSxNAdminIp}" "${VolumeName}" "${VolumeSize}" "${SvmName}"
126-
- Fn::Base64: !Sub |
127-
<powershell>
128-
Invoke-WebRequest -Uri ${WindowsUserDataUrl} -OutFile C:\userdata-script.ps1
129-
(Get-Content 'C:\userdata-script.ps1') | Where-Object { $_ -notmatch '^<powershell>$|^</powershell>$' } | Set-Content 'C:\userdata-script.ps1'
130-
powershell.exe -ExecutionPolicy Bypass -File C:\userdata-script.ps1 -SecretIdParam "${SecretName}" -FSxNAdminIpParam "${FSxNAdminIp}" -VolumeNameParam "${VolumeName}" -VolumeSizeParam "${VolumeSize}" -DriveLetterParam "${DriveLetter}" -SvmNameParam "${SvmName}"
131-
</powershell>
194+
- IsLinux
195+
- Fn::Base64: !Sub |
196+
#!/bin/bash
197+
curl -o /tmp/userdata-script.sh ${LinuxUserDataUrl}
198+
chmod +x /tmp/userdata-script.sh
199+
# Pass parameters to the script
200+
/tmp/userdata-script.sh "${SecretName}" "${AWSRegion}" "${ManagementEndpointIP }" "${VolumeName}" "${VolumeSize}" "${SvmName}"
201+
- Fn::Base64: !Sub |
202+
<powershell>
203+
Invoke-WebRequest -Uri ${WindowsUserDataUrl} -OutFile C:\userdata-script.ps1
204+
(Get-Content 'C:\userdata-script.ps1') | Where-Object { $_ -notmatch '^<powershell>$|^</powershell>$' } | Set-Content 'C:\userdata-script.ps1'
205+
powershell.exe -ExecutionPolicy Bypass -File C:\userdata-script.ps1 -SecretIdParam "${SecretName}" -FSxNAdminIpParam "${ManagementEndpointIP }" -VolumeNameParam "${VolumeName}" -VolumeSizeParam "${VolumeSize}" -DriveLetterParam "${DriveLetter}" -SvmNameParam "${SvmName}"
206+
</powershell>
132207
Outputs:
133208
InstanceId:
134209
Description: EC2 Instance ID

0 commit comments

Comments
 (0)