Skip to content

Commit 3589492

Browse files
committed
Merge branch 'stop_ad_admin' into 'develop'
[BI] Shut down Windows AD management host See merge request mwvaughn/aws-hpc-recipes!102
2 parents 7da010c + c3380b7 commit 3589492

File tree

5 files changed

+26
-28
lines changed

5 files changed

+26
-28
lines changed

recipes/dir/demo_managed_ad/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Then select **Connect** to connect to the instance using AWS Session Manager whi
3737

3838
Follow the same instructions as for accessing the host by SSM, until you get to the **Connect** step. There, select **SSH Client** to get directions on how to connect with SSH.
3939

40-
**Note** If you haven chosen **Yes** for the parameter **StopAdAdminInstance** whe you launched the CloudFormation template, the Linux instance may be in a stopped state. Choose **Instance state::Start instance** to bring it back online before connecting to it. You can shut the instance down again when you are done working with it.
40+
**Note** If you haven chosen **True** for the parameter **StopAdAdminInstance** when you launched the CloudFormation template, the Linux instance may be in a stopped state. Choose **Instance state::Start instance** to bring it back online before connecting to it. You can shut the instance down again when you are done working with it.
4141

4242
#### Adding Users and Groups
4343

@@ -87,7 +87,7 @@ There is a [Windows Management Host](https://console.aws.amazon.com/cloudformati
8787
8888
You may access this instance by going to the Outputs tab and copying the **ManagementHostId**. Next, navigate to the EC2 console and search for the instance ID. Copy its **Public IPv4 address** and use that with your RDP client to connect to the instance. The access credentials will be `Admin` and the value for **AdministratorPassword** you provided when you created the AD.
8989
90-
**Note** If you haven chosen **Yes** for the parameter **StopAdAdminInstance** when you launched the CloudFormation template, the Windows instance may be in a stopped state. Choose **Instance state::Start instance** to bring it back online before connecting to it. You can shut the instance down again when you are done working with it.
90+
**Note** If you haven chosen **True** for the parameter **StopAdAdminInstance** when you launched the CloudFormation template, the Windows instance may be in a stopped state. Choose **Instance state::Start instance** to bring it back online before connecting to it. You can shut the instance down again when you are done working with it.
9191
9292
Once you connect to the instance, you may open the **Active Directory Users and Computers** interface by choosing to run that from the Windows Start menu:
9393
![image](https://github.com/charlesg3/aws-hpc-recipes/assets/6087509/387f0abe-5db4-4d8d-aaff-9e42023f5dc9)

recipes/dir/demo_managed_ad/assets/main-import.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ Parameters:
9696
StopAdAdminInstance:
9797
Description: Automatically stop the Management Instance to save costs
9898
Type: String
99-
Default: "No"
99+
Default: "False"
100100
AllowedValues:
101-
- "Yes"
102-
- "No"
101+
- "True"
102+
- "False"
103103

104104
Conditions:
105105
isUSEast1: !Equals [!Ref "AWS::Region", "us-east-1"]
@@ -510,7 +510,7 @@ Resources:
510510
user_name = event['ResourceProperties']['UserName']
511511
user_password = event['ResourceProperties']['UserPassword']
512512
admin_password = event['ResourceProperties']['AdminPassword']
513-
stop_ad_admin_instance = event['ResourceProperties']['StopAdAdminInstance'] == 'Yes'
513+
stop_ad_admin_instance = event['ResourceProperties']['StopAdAdminInstance'] == 'True'
514514
515515
response_data = {}
516516
reason = None

recipes/dir/demo_managed_ad/assets/main.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ Parameters:
118118
StopAdAdminInstance:
119119
Description: Automatically stop the management instance to save costs.
120120
Type: String
121-
Default: "No"
121+
Default: "False"
122122
AllowedValues:
123-
- "Yes"
124-
- "No"
123+
- "True"
124+
- "False"
125125

126126
Transform: AWS::Serverless-2016-10-31
127127

@@ -633,7 +633,7 @@ Resources:
633633
user_name = event['ResourceProperties']['UserName']
634634
user_password = event['ResourceProperties']['UserPassword']
635635
admin_password = event['ResourceProperties']['AdminPassword']
636-
stop_ad_admin_instance = event['ResourceProperties']['StopAdAdminInstance'] == 'Yes'
636+
stop_ad_admin_instance = event['ResourceProperties']['StopAdAdminInstance'] == 'True'
637637
638638
response_data = {}
639639
reason = None

recipes/dir/demo_managed_ad/assets/windows_management_host.yaml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ Parameters:
116116
StopAdAdminInstance:
117117
Description: Automatically stop the management instance after launch to reduce costs.
118118
Type: String
119-
Default: "No"
119+
Default: "False"
120120
AllowedValues:
121-
- "Yes"
122-
- "No"
121+
- "True"
122+
- "False"
123123

124124
Conditions:
125125
AddPrefixList: !Not [!Equals [!Ref ClientPrefixList, ""]]
@@ -307,6 +307,9 @@ Resources:
307307
}
308308
Unregister-ScheduledTask -TaskName $task_name -Confirm:$false # remove subtask
309309
Unregister-ScheduledTask -TaskName "Setup domain" -Confirm:$false # remove the parent task that called us
310+
if ("${StopAdAdminInstance}" -eq "True") {
311+
stop-computer
312+
}
310313
}
311314
'@
312315
@@ -335,6 +338,7 @@ Resources:
335338
DomainName: !Ref DomainName,
336339
DelegationUser: !Ref DelegationUser,
337340
ServiceAccountName: !Ref ServiceAccountName,
341+
StopAdAdminInstance: !Ref StopAdAdminInstance,
338342
DC: !Join [",DC=", !Split [".", !Ref DomainName ]],
339343
OU: !Select [0, !Split ['.', !Ref DomainName ]]
340344
}
@@ -413,19 +417,13 @@ Resources:
413417
def handler(event, context):
414418
print( 'boto version {}'.format(boto3.__version__))
415419
416-
instance_id = event['ResourceProperties']['InstanceId']
417-
# stop_admin_instance = event['ResourceProperties']['StopAdAdminInstance'] == 'Yes'
418-
stop_admin_instance = False
419-
420420
response_data = {}
421421
reason = None
422422
response_status = cfnresponse.SUCCESS
423423
424424
if event['RequestType'] == 'Create':
425425
response_data['Message'] = 'Resource creation successful!'
426426
physical_resource_id = create_physical_resource_id()
427-
if stop_admin_instance:
428-
ec2.stop_instances(InstanceIds=[instance_id])
429427
else:
430428
physical_resource_id = event['PhysicalResourceId']
431429

recipes/res/res_demo_env/assets/bi.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Metadata:
1717
- LDIFS3Path
1818
- ClientIpCidr
1919
- ClientPrefixList
20-
# - StopAdAdminInstances
20+
- StopAdAdminInstances
2121

2222
Parameters:
2323
DomainName:
@@ -58,13 +58,13 @@ Parameters:
5858
Description: (Optional) An S3 Path (without the s3://) to an LDIF file that will be used during stack creation.
5959
Type: String
6060
Default: aws-hpc-recipes/main/recipes/res/res_demo_env/assets/res.ldif
61-
# StopAdAdminInstances:
62-
# Description: Automatically stop management instances to save costs.
63-
# Type: String
64-
# Default: "No"
65-
# AllowedValues:
66-
# - "Yes"
67-
# - "No"
61+
StopAdAdminInstances:
62+
Description: Automatically stop management instances to save costs.
63+
Type: String
64+
Default: "False"
65+
AllowedValues:
66+
- "True"
67+
- "False"
6868
Keypair:
6969
Description: EC2 Keypair to access AD management instances.
7070
Type: AWS::EC2::KeyPair::KeyName
@@ -148,7 +148,7 @@ Resources:
148148
Keypair: !Ref Keypair
149149
VpcId: !GetAtt [ Networking, Outputs.VPC ]
150150
Subnet: {"Fn::Select": [0, { "Fn::Split" : [",", !GetAtt [ Networking, Outputs.PublicSubnets ]] }]}
151-
# StopAdAdminInstance: !Ref StopAdAdminInstances
151+
StopAdAdminInstance: !Ref StopAdAdminInstances
152152
ClientIpCidr: !Ref ClientIpCidr
153153
ClientPrefixList: !Ref ClientPrefixList
154154
PSS3Path: aws-hpc-recipes/main/recipes/res/res_demo_env/assets/service_account.ps1

0 commit comments

Comments
 (0)