Skip to content

Commit

Permalink
feat: add codedeploy_deployment_group module
Browse files Browse the repository at this point in the history
  • Loading branch information
shblue21 committed Sep 20, 2023
1 parent 207f83c commit df020df
Show file tree
Hide file tree
Showing 11 changed files with 1,344 additions and 0 deletions.
1 change: 1 addition & 0 deletions meta/runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ action_groups:
- codebuild_project
- codecommit_repository
- codedeploy_application
- codedeploy_deployment_group
- codepipeline
- config_aggregation_authorization
- config_aggregator
Expand Down
939 changes: 939 additions & 0 deletions plugins/modules/codedeploy_deployment_group.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cloud/aws
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
codedeploy_service_role_name: "ansible-test-{{ tiny_prefix | truncate(6, True, '') }}-codedeploy-role"
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": "codedeploy.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dependencies: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
- name: create IAM role needed for CodeDeploy deploy
iam_role:
name: "{{ codedeploy_service_role_name }}"
description: Role with permissions for CodePipeline actions.
assume_role_policy_document: "{{ lookup('file', 'codedeploy_iam_trust_policy.json') }}"
create_instance_profile: no
managed_policies:
- 'AWSCodeDeployRole'
state: present
wait: True
register: codedeploy_service_role

- name: wait for 15 seconds # IAM policy takes time to propagate
pause:
seconds: 15

- name: create codedeploy_application - Server
codedeploy_application:
application_name: "{{ resource_prefix }}_app_server"
compute_platform: Server
state: present
register: codedeploy_application_server

- name: create codedeploy_application - Lambda
codedeploy_application:
application_name: "{{ resource_prefix }}_app_lambda"
compute_platform: Lambda
state: present
register: codedeploy_application_lambda
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
- name: Create deployment group - Server, No Options (CHECK_MODE)
codedeploy_deployment_group:
application_name: "{{ codedeploy_application_server.application.application_name }}"
deployment_group_name: "{{ tiny_prefix }}_dg_server_no_options"
service_role: "{{ codedeploy_service_role.iam_role.arn }}"
state: present
check_mode: true
register: codedeploy_deployment_group_server

- name: check that deployment group was correctly created
assert:
that:
- codedeploy_deployment_group_server.changed

- name: Create deployment group - Server, No Options
codedeploy_deployment_group:
application_name: "{{ codedeploy_application_server.application.application_name }}"
deployment_group_name: "{{ tiny_prefix }}_dg_server_no_options"
service_role: "{{ codedeploy_service_role.iam_role.arn }}"
state: present

- name: Create deployment group - tag sets
codedeploy_deployment_group:
application_name: "{{ codedeploy_application_server.application.application_name }}"
deployment_group_name: "{{ tiny_prefix }}_dg_server_all_options"
service_role: "{{ codedeploy_service_role.iam_role.arn }}"
deployment_config_name: CodeDeployDefault.HalfAtATime
alarm_configuration:
enabled: True
ignore_poll_alarm_failure: True
alarm_names:
- "{{ tiny_prefix }}_test_alarm_1"
- "{{ tiny_prefix }}_test_alarm_2"
outdated_instances_strategy: IGNORE
deployment_style:
deployment_type: IN_PLACE
deployment_option: WITHOUT_TRAFFIC_CONTROL
auto_rollback_configuration:
enabled: True
events:
- DEPLOYMENT_STOP_ON_ALARM
- DEPLOYMENT_STOP_ON_REQUEST
ec2_tag_set:
ec2_tag_set_list:
- ec2_tag:
- key: Name
value: "{{ tiny_prefix }}_ec2_instance_tagset_1"
type: KEY_AND_VALUE
- key: Env
value: "{{ tiny_prefix }}_ansible_test"
type: KEY_AND_VALUE
- ec2_tag:
- key: Name
value: "{{ tiny_prefix }}_ec2_instance_tagset_2"
type: KEY_AND_VALUE
- key: Env
value: "{{ tiny_prefix }}_ansible_test"
type: KEY_AND_VALUE
on_premises_tag_set:
on_premises_tag_set_list:
- on_premises_tag:
- key: Name
value: "{{ tiny_prefix }}_instance_tagset_1"
type: KEY_AND_VALUE
- key: Env
value: "{{ tiny_prefix }}_ansible_test"
type: KEY_AND_VALUE
- on_premises_tag:
- key: Name
value: "{{ tiny_prefix }}_instance_tagset_2"
type: KEY_AND_VALUE
- key: Env
value: "{{ tiny_prefix }}_ansible_test"
type: KEY_AND_VALUE
state: present
register: codedeploy_deployment_group_server

- name: check that deployment group was correctly created
assert:
that:
- codedeploy_deployment_group_server.changed
- codedeploy_deployment_group_server.deployment_group is defined
- codedeploy_deployment_group_server.deployment_group.deployment_group_name == "{{ tiny_prefix }}_dg_server_all_options"

- name: update deployment group - tag sets (CHECK_MODE)
codedeploy_deployment_group:
application_name: "{{ codedeploy_application_server.application.application_name }}"
deployment_group_name: "{{ tiny_prefix }}_dg_server_all_options"
new_deployment_group_name: "{{ tiny_prefix }}_dg_server_all_options_updated" # change deployment group name
service_role: "{{ codedeploy_service_role.iam_role.arn }}"
deployment_config_name: CodeDeployDefault.AllAtOnce # change deployment config
alarm_configuration:
enabled: True
ignore_poll_alarm_failure: True
alarm_names:
- "{{ tiny_prefix }}_test_alarm_1"
- "{{ tiny_prefix }}_test_alarm_2"
outdated_instances_strategy: IGNORE
deployment_style:
deployment_type: IN_PLACE
deployment_option: WITHOUT_TRAFFIC_CONTROL
auto_rollback_configuration:
enabled: True
events:
- DEPLOYMENT_STOP_ON_ALARM
- DEPLOYMENT_FAILURE
ec2_tag_set:
ec2_tag_set_list:
- ec2_tag: # change ec2 tag set
- key: Name
value: "{{ tiny_prefix }}_ec2_instance_tagset_1_updated"
type: KEY_AND_VALUE
- key: Env
value: "{{ tiny_prefix }}_ansible_new_test_updated"
type: KEY_AND_VALUE
- ec2_tag:
- key: Name
value: "{{ tiny_prefix }}_ec2_instance_new_tagset_2_updated"
type: KEY_AND_VALUE
- key: Env
value: "{{ tiny_prefix }}_ansible_new_test_updated"
type: KEY_AND_VALUE
on_premises_tag_set:
on_premises_tag_set_list:
- on_premises_tag:
- key: Name
value: "{{ tiny_prefix }}_instance_tagset_1_updated"
type: KEY_AND_VALUE
- key: Env
value: "{{ tiny_prefix }}_ansible_test_updated"
type: KEY_AND_VALUE
- on_premises_tag:
- key: Name
value: "{{ tiny_prefix }}_instance_tagset_2_updated"
type: KEY_AND_VALUE
- key: Env
value: "{{ tiny_prefix }}_ansible_test_updated"
type: KEY_AND_VALUE
state: present
check_mode: true
register: codedeploy_deployment_group_server

- name: check that deployment group was correctly updated
assert:
that:
- codedeploy_deployment_group_server.changed
- codedeploy_deployment_group_server.deployment_group is defined
- codedeploy_deployment_group_server.deployment_group.deployment_group_name == "{{ tiny_prefix }}_dg_server_all_options"

- name: update deployment group - tag sets
codedeploy_deployment_group:
application_name: "{{ codedeploy_application_server.application.application_name }}"
deployment_group_name: "{{ tiny_prefix }}_dg_server_all_options"
new_deployment_group_name: "{{ tiny_prefix }}_dg_server_all_options_updated" # change deployment group name
service_role: "{{ codedeploy_service_role.iam_role.arn }}"
deployment_config_name: CodeDeployDefault.AllAtOnce # change deployment config
alarm_configuration:
enabled: True
ignore_poll_alarm_failure: True
alarm_names:
- "{{ tiny_prefix }}_test_alarm_1"
- "{{ tiny_prefix }}_test_alarm_2"
outdated_instances_strategy: IGNORE
deployment_style:
deployment_type: IN_PLACE
deployment_option: WITHOUT_TRAFFIC_CONTROL
auto_rollback_configuration:
enabled: True
events:
- DEPLOYMENT_STOP_ON_ALARM
- DEPLOYMENT_FAILURE
ec2_tag_set:
ec2_tag_set_list:
- ec2_tag: # change ec2 tag set
- key: Name
value: "{{ tiny_prefix }}_ec2_instance_tagset_1_updated"
type: KEY_AND_VALUE
- key: Env
value: "{{ tiny_prefix }}_ansible_new_test_updated"
type: KEY_AND_VALUE
- ec2_tag:
- key: Name
value: "{{ tiny_prefix }}_ec2_instance_new_tagset_2_updated"
type: KEY_AND_VALUE
- key: Env
value: "{{ tiny_prefix }}_ansible_new_test_updated"
type: KEY_AND_VALUE
on_premises_tag_set:
on_premises_tag_set_list:
- on_premises_tag:
- key: Name
value: "{{ tiny_prefix }}_instance_tagset_1_updated"
type: KEY_AND_VALUE
- key: Env
value: "{{ tiny_prefix }}_ansible_test_updated"
type: KEY_AND_VALUE
- on_premises_tag:
- key: Name
value: "{{ tiny_prefix }}_instance_tagset_2_updated"
type: KEY_AND_VALUE
- key: Env
value: "{{ tiny_prefix }}_ansible_test_updated"
type: KEY_AND_VALUE
state: present
register: codedeploy_deployment_group_server

- name: check that deployment group was correctly updated
assert:
that:
- codedeploy_deployment_group_server.changed
- codedeploy_deployment_group_server.deployment_group is defined
- codedeploy_deployment_group_server.deployment_group.deployment_group_name == "{{ tiny_prefix }}_dg_server_all_options_updated"
- codedeploy_deployment_group_server.deployment_group.deployment_config_name == "CodeDeployDefault.AllAtOnce"


- name: delete deployment group - tag sets (CHECK_MODE)
codedeploy_deployment_group:
application_name: "{{ codedeploy_application_server.application.application_name }}"
deployment_group_name: "{{ tiny_prefix }}_dg_server_all_options_updated"
service_role: "{{ codedeploy_service_role.iam_role.arn }}"
state: absent
check_mode: true
register: codedeploy_deployment_group_server

- name: check that deployment group was correctly deleted
assert:
that:
- codedeploy_deployment_group_server.changed

- name: delete deployment group - tag sets
codedeploy_deployment_group:
application_name: "{{ codedeploy_application_server.application.application_name }}"
deployment_group_name: "{{ tiny_prefix }}_dg_server_all_options_updated"
state: absent
register: codedeploy_deployment_group_server
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
- name: Create deployment group - Lambda, no options(Check mode)
codedeploy_deployment_group:
application_name: "{{ codedeploy_application_lambda.application.application_name }}"
deployment_group_name: "{{ tiny_prefix }}_dg_lambda_no_options"
service_role: "{{ codedeploy_service_role.iam_role.arn }}"
state: present
check_mode: true
register: codedeploy_deployment_group_lambda

- name: check that deployment group was correctly created
assert:
that:
- codedeploy_deployment_group_lambda.changed

- name: Create deployment group - Lambda, no options
codedeploy_deployment_group:
application_name: "{{ codedeploy_application_lambda.application.application_name }}"
deployment_group_name: "{{ tiny_prefix }}_dg_lambda_no_options"
service_role: "{{ codedeploy_service_role.iam_role.arn }}"
deployment_style:
deployment_type: BLUE_GREEN
deployment_option: WITH_TRAFFIC_CONTROL
state: present
register: codedeploy_deployment_group_lambda

- name: Create deployment group - Lambda, all options
codedeploy_deployment_group:
application_name: "{{ codedeploy_application_lambda.application.application_name }}"
deployment_group_name: "{{ tiny_prefix }}_dg_lambda_all_options"
service_role: "{{ codedeploy_service_role.iam_role.arn }}"
deployment_config_name: CodeDeployDefault.LambdaCanary10Percent30Minutes
alarm_configuration:
enabled: True
ignore_poll_alarm_failure: True
alarm_names:
- "{{ tiny_prefix }}_test_alarm_1"
- "{{ tiny_prefix }}_test_alarm_2"
auto_rollback_configuration:
enabled: True
events:
- DEPLOYMENT_STOP_ON_ALARM
deployment_style:
deployment_type: BLUE_GREEN
deployment_option: WITH_TRAFFIC_CONTROL
state: present
register: codedeploy_deployment_group_lambda

- name: check that deployment group was correctly created
assert:
that:
- codedeploy_deployment_group_lambda.changed
- codedeploy_deployment_group_lambda.deployment_group is defined
- codedeploy_deployment_group_lambda.deployment_group.deployment_group_name == "{{ tiny_prefix }}_dg_lambda_all_options"

- name: Update deployment group - Lambda, all options
codedeploy_deployment_group:
application_name: "{{ codedeploy_application_lambda.application.application_name }}"
deployment_group_name: "{{ tiny_prefix }}_dg_lambda_all_options"
new_deployment_group_name: "{{ tiny_prefix }}_dg_lambda_all_options_updated"
deployment_config_name: CodeDeployDefault.LambdaLinear10PercentEvery1Minute
alarm_configuration:
enabled: True
ignore_poll_alarm_failure: True
alarm_names:
- "{{ tiny_prefix }}_test_alarm_1_updated"
- "{{ tiny_prefix }}_test_alarm_2_updated"
auto_rollback_configuration:
enabled: True
events:
- DEPLOYMENT_STOP_ON_ALARM
- DEPLOYMENT_FAILURE
deployment_style:
deployment_type: BLUE_GREEN
deployment_option: WITH_TRAFFIC_CONTROL
state: present
register: codedeploy_deployment_group_lambda


- name: check that deployment group was correctly updated
assert:
that:
- codedeploy_deployment_group_lambda.changed
- codedeploy_deployment_group_lambda.deployment_group is defined
- codedeploy_deployment_group_lambda.deployment_group.deployment_group_name == "{{ tiny_prefix }}_dg_lambda_all_options_updated"
- codedeploy_deployment_group_lambda.deployment_group.deployment_config_name == "CodeDeployDefault.LambdaLinear10PercentEvery1Minute"

- name: delete deployment group - Lambda
codedeploy_deployment_group:
application_name: "{{ codedeploy_application_lambda.application.application_name }}"
deployment_group_name: "{{ tiny_prefix }}_dg_lambda_all_options_updated"
state: absent
register: codedeploy_deployment_group_lambda
Loading

0 comments on commit df020df

Please sign in to comment.