generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5181 from ministryofjustice/CC-2391/execute-scrip…
…t-via-systems-manager CC-2391: Added resource groups, tags.
- Loading branch information
Showing
15 changed files
with
592 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
terraform/environments/ccms-ebs-upgrade/ccms-resource-groups.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
resource "aws_resourcegroups_group" "accessgate" { | ||
name = "accessgate" | ||
description = "Accessgate instances" | ||
|
||
resource_query { | ||
query = <<JSON | ||
{ | ||
"ResourceTypeFilters": [ "AWS::EC2::Instance" ], | ||
"TagFilters": [ | ||
{ | ||
"Key": "instance-role", | ||
"Values": ["accessgate"] | ||
} | ||
] | ||
} | ||
JSON | ||
} | ||
} | ||
|
||
resource "aws_resourcegroups_group" "ebsapps" { | ||
name = "ebsapps" | ||
description = "EBSapps instances" | ||
|
||
resource_query { | ||
query = <<JSON | ||
{ | ||
"ResourceTypeFilters": [ "AWS::EC2::Instance" ], | ||
"TagFilters": [ | ||
{ | ||
"Key": "instance-role", | ||
"Values": ["ebsapps"] | ||
} | ||
] | ||
} | ||
JSON | ||
} | ||
} | ||
|
||
resource "aws_resourcegroups_group" "conc" { | ||
name = "conc" | ||
description = "EBSconc instances" | ||
|
||
resource_query { | ||
query = <<JSON | ||
{ | ||
"ResourceTypeFilters": [ "AWS::EC2::Instance" ], | ||
"TagFilters": [ | ||
{ | ||
"Key": "instance-role", | ||
"Values": ["conc"] | ||
} | ||
] | ||
} | ||
JSON | ||
} | ||
} | ||
|
||
resource "aws_resourcegroups_group" "ebsdb" { | ||
name = "ebsdb" | ||
description = "EBSdb instances" | ||
|
||
resource_query { | ||
query = <<JSON | ||
{ | ||
"ResourceTypeFilters": [ "AWS::EC2::Instance" ], | ||
"TagFilters": [ | ||
{ | ||
"Key": "instance-role", | ||
"Values": ["ebsdb"] | ||
} | ||
] | ||
} | ||
JSON | ||
} | ||
} | ||
|
||
resource "aws_resourcegroups_group" "webgate" { | ||
name = "webgate" | ||
description = "Webgate instances" | ||
|
||
resource_query { | ||
query = <<JSON | ||
{ | ||
"ResourceTypeFilters": [ "AWS::EC2::Instance" ], | ||
"TagFilters": [ | ||
{ | ||
"Key": "instance-role", | ||
"Values": ["webgate"] | ||
} | ||
] | ||
} | ||
JSON | ||
} | ||
} | ||
|
||
output "aws_resourcegroups_group_accessgate_arn" { | ||
description = "aws_resourcegroups_group accessgate arn" | ||
value = "aws_resourcegroups_group.accessgate.arn" | ||
} | ||
|
||
output "aws_resourcegroups_group_ebsapps_arn" { | ||
description = "aws_resourcegroups_group ebsapps arn" | ||
value = "aws_resourcegroups_group.ebsapps.arn" | ||
} | ||
|
||
output "aws_resourcegroups_group_conc_arn" { | ||
description = "aws_resourcegroups_group conc arn" | ||
value = "aws_resourcegroups_group.conc.arn" | ||
} | ||
|
||
output "aws_resourcegroups_group_ebsdb_arn" { | ||
description = "aws_resourcegroups_group ebsdb arn" | ||
value = "aws_resourcegroups_group.ebsdb.arn" | ||
} | ||
|
||
output "aws_resourcegroups_group_webgate_arn" { | ||
description = "aws_resourcegroups_group webgate arn" | ||
value = "aws_resourcegroups_group.webgate.arn" | ||
} |
20 changes: 20 additions & 0 deletions
20
terraform/environments/ccms-ebs-upgrade/ccms-ssm-document-ebs-apps-service-start.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# ccms-ssm-document-ebs-apps-service-start.yaml | ||
--- | ||
schemaVersion: "2.2" | ||
description: Execute the startAPP.sh script. | ||
parameters: | ||
action: | ||
type: String | ||
allowedValues: | ||
- start | ||
mainSteps: | ||
- name: startAPP | ||
action: aws:runShellScript | ||
isEnd: true | ||
precondition: | ||
StringEquals: | ||
- "{{ action }}" | ||
- start | ||
inputs: | ||
runCommand: | ||
- "/home/applmgr/scripts/startAPP.sh" |
20 changes: 20 additions & 0 deletions
20
terraform/environments/ccms-ebs-upgrade/ccms-ssm-document-ebs-apps-service-status.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# ccms-ssm-document-ebs-apps-service-status.yaml | ||
--- | ||
schemaVersion: "2.2" | ||
description: Execute the statusAPP.sh script. | ||
parameters: | ||
action: | ||
type: String | ||
allowedValues: | ||
- status | ||
mainSteps: | ||
- name: statusAPP | ||
action: aws:runShellScript | ||
isEnd: true | ||
precondition: | ||
StringEquals: | ||
- "{{ action }}" | ||
- status | ||
inputs: | ||
runCommand: | ||
- "/home/applmgr/scripts/statusAPP.sh" |
20 changes: 20 additions & 0 deletions
20
terraform/environments/ccms-ebs-upgrade/ccms-ssm-document-ebs-apps-service-stop.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# ccms-ssm-document-ebs-apps-service-stop.yaml | ||
--- | ||
schemaVersion: "2.2" | ||
description: Execute the stopAPP.sh script. | ||
parameters: | ||
action: | ||
type: String | ||
allowedValues: | ||
- stop | ||
mainSteps: | ||
- name: stopAPP | ||
action: aws:runShellScript | ||
isEnd: true | ||
precondition: | ||
StringEquals: | ||
- "{{ action }}" | ||
- stop | ||
inputs: | ||
runCommand: | ||
- "/home/applmgr/scripts/stopAPP.sh" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
resource "aws_ssm_document" "ebs_apps_service_start" { | ||
name = "EBS-Apps-Service-Start" | ||
document_type = "Command" | ||
document_format = "YAML" | ||
|
||
content = file("ccms-ssm-document-ebs-apps-service-start.yaml") | ||
} | ||
|
||
resource "aws_ssm_document" "ebs_apps_service_status" { | ||
name = "EBS-Apps-Service-Status" | ||
document_type = "Command" | ||
document_format = "YAML" | ||
|
||
content = file("ccms-ssm-document-ebs-apps-service-status.yaml") | ||
} | ||
|
||
resource "aws_ssm_document" "ebs_apps_service_stop" { | ||
name = "EBS-Apps-Service-Stop" | ||
document_type = "Command" | ||
document_format = "YAML" | ||
|
||
content = file("ccms-ssm-document-ebs-apps-service-stop.yaml") | ||
} | ||
|
||
resource "aws_ssm_maintenance_window" "ebs_apps_service_status_mw" { | ||
name = "EBS-Apps-Service-Status" | ||
schedule = "cron(*/15 * * * ? *)" | ||
duration = 1 | ||
cutoff = 0 | ||
allow_unassociated_targets = false | ||
} | ||
|
||
resource "aws_ssm_maintenance_window" "ebs_apps_service_start_mw" { | ||
name = "EBS-Apps-Service-Start" | ||
schedule = "cron(15 7 * * ? *)" # "cron(15 7 ? * MON-FRI *)" | ||
duration = 1 | ||
cutoff = 0 | ||
allow_unassociated_targets = false | ||
} | ||
|
||
resource "aws_ssm_maintenance_window" "ebs_apps_service_stop_mw" { | ||
name = "EBS-Apps-Service-Stop" | ||
schedule = "cron(45 17 * * ? *)" | ||
duration = 1 | ||
cutoff = 0 | ||
allow_unassociated_targets = false | ||
} | ||
|
||
# resource "aws_ssm_maintenance_window_target" "ebs_apps_service_status_targets" { | ||
# window_id = aws_ssm_maintenance_window.ebs_apps_service_status_mw.id | ||
# resource_type = "INSTANCE" | ||
# | ||
# targets { | ||
# key = "ResourceGroup" | ||
# values = ["EBS-Apps"] | ||
# } | ||
# } | ||
# | ||
# resource "aws_ssm_maintenance_window_target" "ebs_apps_service_start_targets" { | ||
# window_id = aws_ssm_maintenance_window.ebs_apps_service_start_mw.id | ||
# resource_type = "INSTANCE" | ||
# | ||
# targets { | ||
# key = "ResourceGroup" | ||
# values = ["EBS-Apps"] | ||
# } | ||
# } | ||
# | ||
# resource "aws_ssm_maintenance_window_target" "ebs_apps_service_stop_targets" { | ||
# window_id = aws_ssm_maintenance_window.ebs_apps_service_stop_mw.id | ||
# resource_type = "INSTANCE" | ||
# | ||
# targets { | ||
# key = "ResourceGroup" | ||
# values = ["EBS-Apps"] | ||
# } | ||
# } | ||
|
||
# resource "aws_ssm_association" "start_app_association" { | ||
# name = "StartAppMaintenanceWindowAssociation" | ||
# document_version = "$LATEST" | ||
# instance_id = aws_ssm_maintenance_window_target.foo_ec2_targets.targets[0].key | ||
# targets { | ||
# key = "WindowTargetIds" | ||
# values = [aws_ssm_maintenance_window_target.foo_ec2_targets.id] | ||
# } | ||
# parameters { | ||
# "documentVersion" = "$LATEST" | ||
# "documentName" = aws_ssm_document.start_app_command_document.name | ||
# } | ||
# schedule_expression = "cron(15 7 ? * MON-FRI *)" | ||
# } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.