Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postgres server backup-support #566

Merged
merged 20 commits into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 62 additions & 9 deletions plugins/modules/azure_rm_postgresqlserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@
description:
- The maximum storage allowed for a server.
type: int
geo_redundant_backup:
karisN marked this conversation as resolved.
Show resolved Hide resolved
description:
- Choose between locally redundant(default) or geo-redundant backup. This cannot be updated after first deployment
default: default
karisN marked this conversation as resolved.
Show resolved Hide resolved
backup_retention_days:
description:
- Backup retention period between 7 and 35 days. 7 days by default if not set
type: int
version:
description:
- Server version.
Expand All @@ -77,8 +85,19 @@
- The password of the administrator login.
create_mode:
description:
- Create mode of SQL Server.
default: Default
- Create mode of SQL Server. Blank (default), restore from geo redundant (geo_restore), or restore from point in time (point_in_time_restore).
default: default
choices:
- default
- geo_restore
- point_in_time_restore
source_server_id:
description:
- Id if the source server if I(create_mode=default).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@karisN There is something wrong with this description statement. Please refer to the relevant documents of this module and describe it again. Thank you very much!

restore_point_in_time:
description:
- Restore point creation time (ISO8601 format), specifying the time to restore from.
- Required if I(create_mode=point_in_time_restore).
state:
description:
- Assert the state of the PostgreSQL server. Use C(present) to create or update a server and C(absent) to delete it.
Expand Down Expand Up @@ -178,6 +197,14 @@ def __init__(self):
storage_mb=dict(
type='int'
),
geo_redundant_backup=dict(
type='str',
default=Disabled,
karisN marked this conversation as resolved.
Show resolved Hide resolved
choices=['Disabled', 'Enabled']
),
backup_retention_days=dict(
type='int',
),
version=dict(
type='str',
choices=['9.5', '9.6', '10', '11']
Expand All @@ -192,7 +219,14 @@ def __init__(self):
),
create_mode=dict(
type='str',
default='Default'
default='default',
choices=['default', 'geo_restore', 'point_in_time_restore']
),
source_server_id=dict(
Fred-sun marked this conversation as resolved.
Show resolved Hide resolved
type='str'
),
restore_point_in_time=dict(
type='str'
),
admin_username=dict(
type='str'
Expand All @@ -210,7 +244,7 @@ def __init__(self):

self.resource_group = None
self.name = None
self.parameters = dict()
self.parameters = {'properties': {'create_mode': 'default'}}
self.tags = None

self.results = dict(changed=False)
Expand Down Expand Up @@ -239,20 +273,39 @@ def exec_module(self, **kwargs):
elif key == "location":
self.parameters["location"] = kwargs[key]
elif key == "storage_mb":
self.parameters.setdefault("properties", {}).setdefault("storage_profile", {})["storage_mb"] = kwargs[key]
self.parameters.setdefault("properties", {}).setdefault("storage_profile", {})["storage_mb"] = \
kwargs[key]
elif key == "storage_autogrow":
self.parameters.setdefault("properties", {}).setdefault("storage_profile", {})["storage_autogrow"] = ('Enabled' if kwargs[key]
else 'Disabled')
self.parameters.setdefault("properties", {}).setdefault("storage_profile", {})[
"storage_autogrow"] = ('Enabled' if kwargs[key]
else 'Disabled')
elif key == "geo_redundant_backup":
self.parameters.setdefault("properties", {}).setdefault("storage_profile", {})[
"geo_redundant_backup"] = \
'Enabled' if kwargs[key] else 'Disabled'
elif key == "backup_retention_days":
self.parameters.setdefault("properties", {}).setdefault("storage_profile", {})[
"backup_retention_days"] = kwargs[key]
elif key == "version":
self.parameters.setdefault("properties", {})["version"] = kwargs[key]
elif key == "enforce_ssl":
self.parameters.setdefault("properties", {})["ssl_enforcement"] = 'Enabled' if kwargs[key] else 'Disabled'
self.parameters.setdefault("properties", {})["ssl_enforcement"] = 'Enabled' if kwargs[
key] else 'Disabled'
elif key == "create_mode":
self.parameters.setdefault("properties", {})["create_mode"] = kwargs[key]
if kwargs[key] == 'default':
self.parameters["properties"]["create_mode"] = 'Default'
elif kwargs[key] == 'point_in_time_restore':
self.parameters["properties"]["create_mode"] = 'PointInTimeRestore'
elif kwargs[key] == 'geo_restore':
self.parameters["properties"]["create_mode"] = 'GeoRestore'
elif key == "admin_username":
self.parameters.setdefault("properties", {})["administrator_login"] = kwargs[key]
elif key == "admin_password":
self.parameters.setdefault("properties", {})["administrator_login_password"] = kwargs[key]
elif key == "source_server_id":
self.parameters["properties"]["source_server_id"] = kwargs[key]
elif key == "restore_point_in_time":
self.parameters["properties"]["restore_point_in_time"] = kwargs[key]

old_response = None
response = None
Expand Down
14 changes: 14 additions & 0 deletions plugins/modules/azure_rm_postgresqlserver_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@
returned: always
type: str
sample: postgreabdud1223.postgres.database.azure.com
backup_retention_days:
description:
- Backup retention period between 7 and 35 days. 7 days by default if not set.
returned: always
type: int
sample: 7
geo_redundant_backup:
description:
- Choose between locally redundant(default) or geo-redundant backup. This cannot be updated after first deployment.
returned: always
type: str
sample: Disabled
tags:
description:
- Tags assigned to the resource. Dictionary of string:string pairs.
Expand Down Expand Up @@ -245,6 +257,8 @@ def format_item(self, item):
'admin_username': d['administrator_login'],
'user_visible_state': d['user_visible_state'],
'fully_qualified_domain_name': d['fully_qualified_domain_name'],
'geo_redundant_backup': d['storage_profile']['geo_redundant_backup'],
karisN marked this conversation as resolved.
Show resolved Hide resolved
'backup_retention_days': d['storage_profile']['backup_retention_days'],
'tags': d.get('tags')
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
storage_mb: 51200
enforce_ssl: True
storage_autogrow: True
backup_retention_days: 7
admin_username: zimxyz
admin_password: Password123!
tags:
Expand All @@ -118,6 +119,7 @@
storage_mb: 51200
enforce_ssl: True
storage_autogrow: True
backup_retention_days: 7
admin_username: zimxyz
admin_password: Password123!
tags:
Expand All @@ -144,6 +146,7 @@
- output.servers[0]['fully_qualified_domain_name'] != None
- output.servers[0]['tags']['aaa'] == 'bbb'
- output.servers[0]['tags']['ccc'] == 'ddd'
- output.servers[0]['backup_retention_days'] == 7

- name: Gather facts PostgreSQL Server
azure_rm_postgresqlserver_info:
Expand Down