Skip to content

Commit

Permalink
rds_instance_pram_group_info: add new module rds_instance_pram_group_…
Browse files Browse the repository at this point in the history
…info (ansible-collections#2372)

SUMMARY

Adding a new module for retrieving parameter group info.
Can get info for

a specific RDS parameter group
the parameter group associated with a specified RDS instance
all parameter groups available in the current region.

Resolves ansible-collections#2313
ISSUE TYPE


New Module Pull Request

COMPONENT NAME

rds_instance_pram_group_info
ADDITIONAL INFORMATION
Created basic module, waiting on confirmation to move forward with adding tests, etc.

Reviewed-by: GomathiselviS <[email protected]>
Reviewed-by: Mandar Kulkarni <[email protected]>
Reviewed-by: Alina Buzachis
  • Loading branch information
mandar242 authored Nov 8, 2024
1 parent 2b48095 commit b48adec
Show file tree
Hide file tree
Showing 4 changed files with 213 additions and 57 deletions.
1 change: 1 addition & 0 deletions meta/runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ action_groups:
- rds_instance
- rds_instance_info
- rds_instance_param_group
- rds_instance_param_group_info
- rds_instance_snapshot
- rds_option_group
- rds_option_group_info
Expand Down
28 changes: 28 additions & 0 deletions plugins/module_utils/rds.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
pass

from ansible.module_utils._text import to_text
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
from ansible.module_utils.common.dict_transformations import snake_dict_to_camel_dict

from ansible_collections.amazon.aws.plugins.module_utils.botocore import get_boto3_client_method_parameters
Expand Down Expand Up @@ -744,6 +745,33 @@ def describe_db_cluster_parameter_groups(
return result


@AWSRetry.jittered_backoff()
def describe_db_instance_parameter_groups(
connection: Any, module: AnsibleAWSModule, db_parameter_group_name: str = None
) -> List[dict]:
try:
if db_parameter_group_name:
result = connection.describe_db_parameter_groups(DBParameterGroupName=db_parameter_group_name)[
"DBParameterGroups"
]
else:
result = connection.describe_db_parameter_groups()["DBParameterGroups"]

# Get tags
for parameter_group in result:
existing_tags = connection.list_tags_for_resource(ResourceName=parameter_group["DBParameterGroupArn"])[
"TagList"
]
parameter_group["tags"] = boto3_tag_list_to_ansible_dict(existing_tags)

return [camel_dict_to_snake_dict(group, ignore_list=["tags"]) for group in result] if result else []
except is_boto3_error_code("DBParameterGroupNotFound"):
return []
except ClientError as e:
module.fail_json_aws(e, msg="Couldn't access parameter group information")
return result


@AWSRetry.jittered_backoff()
def describe_db_cluster_parameters(
module: AnsibleAWSModule, connection: Any, group_name: str, source: str = "all"
Expand Down
93 changes: 93 additions & 0 deletions plugins/modules/rds_instance_param_group_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright (c) 2024 Ansible Project
# Copyright (c) 2024 Mandar Vijay Kulkarni (@mandar242)
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

DOCUMENTATION = r"""
module: rds_instance_param_group_info
version_added: 9.1.0
short_description: Describes the RDS parameter group.
description:
- Describe a specific RDS parameter group, or
all parameter groups available in the current region.
options:
db_parameter_group_name:
description:
- The name of a specific DB parameter group to return details for.
required: false
type: str
author:
- Mandar Vijay Kulkarni (@mandar242)
extends_documentation_fragment:
- amazon.aws.common.modules
- amazon.aws.region.modules
- amazon.aws.boto3
"""

EXAMPLES = r"""
- name: Get specific DB parameter group's info
amazon.aws.rds_instance_param_group_info:
db_parameter_group_name: my-test-pg
- name: Get all parameter group info from the region
amazon.aws.rds_instance_param_group_info:
"""

RETURN = r"""
db_instance_parameter_groups:
description: List of RDS instance parameter groups.
returned: always
type: list
contains:
db_parameter_group_name:
description:
- The name of the RDS instance parameter group.
type: str
db_parameter_group_family:
description:
- The name of the RDS parameter group family that this RDS instance parameter group is compatible with.
type: str
description:
description:
- Provides the customer-specified description for this RDS instance parameter group.
type: str
db_parameter_group_arn:
description:
- The Amazon Resource Name (ARN) for the RDS instance parameter group.
type: str
tags:
description: Any tags associated to the parameter group.
returned: always
type: dict
sample: {
"Name": "test-parameter-group",
"Env": "Dev001"
}
"""

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.rds import describe_db_instance_parameter_groups


def main() -> None:
argument_spec = {
"db_parameter_group_name": {"type": "str", "required": False},
}

module = AnsibleAWSModule(
argument_spec=argument_spec,
supports_check_mode=True,
)

client = module.client("rds")
db_parameter_group_name = module.params.get("db_parameter_group_name")

result = describe_db_instance_parameter_groups(client, module, db_parameter_group_name)

module.exit_json(changed=False, db_instance_parameter_groups=result)


if __name__ == "__main__":
main()
Loading

0 comments on commit b48adec

Please sign in to comment.