| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
from __future__ import absolute_import, division, print_function |
| 8 |
__metaclass__ = type |
| 9 |
|
| 10 |
|
| 11 |
DOCUMENTATION = ''' |
| 12 |
--- |
| 13 |
module: azure_rm_postgresqlflexibleserver |
| 14 |
version_added: "2.2.0" |
| 15 |
short_description: Manage PostgreSQL Flexible Server instance |
| 16 |
description: |
| 17 |
- Create, update and delete instance of PostgreSQL Flexible Server. |
| 18 |
|
| 19 |
options: |
| 20 |
resource_group: |
| 21 |
description: |
| 22 |
- The name of the resource group that contains the resource. |
| 23 |
- You can obtain this value from the Azure Resource Manager API or the portal. |
| 24 |
required: True |
| 25 |
type: str |
| 26 |
name: |
| 27 |
description: |
| 28 |
- The name of the flexible server. |
| 29 |
required: True |
| 30 |
type: str |
| 31 |
sku: |
| 32 |
description: |
| 33 |
- The SKU (pricing tier) of the server. |
| 34 |
type: dict |
| 35 |
suboptions: |
| 36 |
name: |
| 37 |
description: |
| 38 |
- The name of the sku, typically, tier + family + cores, such as Standard_D4s_v3. |
| 39 |
type: str |
| 40 |
required: True |
| 41 |
tier: |
| 42 |
description: |
| 43 |
- The tier of the particular |
| 44 |
type: str |
| 45 |
choices: |
| 46 |
- Burstable |
| 47 |
- GeneralPurpose |
| 48 |
- MemoryOptimized |
| 49 |
required: True |
| 50 |
location: |
| 51 |
description: |
| 52 |
- Resource location. If not set, location from the resource group will be used as default. |
| 53 |
type: str |
| 54 |
storage: |
| 55 |
description: |
| 56 |
- Storage properties of a server. |
| 57 |
type: dict |
| 58 |
suboptions: |
| 59 |
storage_size_gb: |
| 60 |
description: |
| 61 |
- The storage size for the server. |
| 62 |
type: int |
| 63 |
administrator_login: |
| 64 |
description: |
| 65 |
- The administrator's login name of a server. |
| 66 |
- Can only be specified when the server is being created (and is required for creation). |
| 67 |
type: str |
| 68 |
administrator_login_password: |
| 69 |
description: |
| 70 |
- The administrator login password (required for server creation). |
| 71 |
type: str |
| 72 |
version: |
| 73 |
description: |
| 74 |
- PostgreSQL Server version. |
| 75 |
type: str |
| 76 |
choices: |
| 77 |
- '11' |
| 78 |
- '12' |
| 79 |
- '13' |
| 80 |
- '14' |
| 81 |
- '15' |
| 82 |
- '16' |
| 83 |
- '17' |
| 84 |
fully_qualified_domain_name: |
| 85 |
description: |
| 86 |
- The fully qualified domain name of a server. |
| 87 |
type: str |
| 88 |
backup: |
| 89 |
description: |
| 90 |
- Backup properties of a server. |
| 91 |
type: dict |
| 92 |
suboptions: |
| 93 |
backup_retention_days: |
| 94 |
description: |
| 95 |
- Backup retention days for the server. |
| 96 |
type: int |
| 97 |
geo_redundant_backup: |
| 98 |
description: |
| 99 |
- A value indicating whether Geo-Redundant backup is enabled on the server. |
| 100 |
type: str |
| 101 |
choices: |
| 102 |
- Enabled |
| 103 |
- Disabled |
| 104 |
network: |
| 105 |
description: |
| 106 |
- Network properties of a server. |
| 107 |
type: dict |
| 108 |
suboptions: |
| 109 |
delegated_subnet_resource_id: |
| 110 |
description: |
| 111 |
- Delegated subnet arm resource id. |
| 112 |
type: str |
| 113 |
private_dns_zone_arm_resource_id: |
| 114 |
description: |
| 115 |
- Private dns zone arm resource id. |
| 116 |
type: str |
| 117 |
public_network_access: |
| 118 |
description: |
| 119 |
- Public network access is enabled or not. |
| 120 |
type: str |
| 121 |
choices: |
| 122 |
- Enabled |
| 123 |
- Disabled |
| 124 |
high_availability: |
| 125 |
description: |
| 126 |
- High availability properties of a server. |
| 127 |
type: dict |
| 128 |
suboptions: |
| 129 |
mode: |
| 130 |
description: |
| 131 |
- The HA mode for the server. |
| 132 |
type: str |
| 133 |
choices: |
| 134 |
- Disabled |
| 135 |
- ZoneRedundant |
| 136 |
- SameZone |
| 137 |
standby_availability_zone: |
| 138 |
description: |
| 139 |
- Availability zone information of the standby. |
| 140 |
type: str |
| 141 |
maintenance_window: |
| 142 |
description: |
| 143 |
- Maintenance window properties of a server. |
| 144 |
type: dict |
| 145 |
suboptions: |
| 146 |
custom_window: |
| 147 |
description: |
| 148 |
- Indicates whether custom window is enabled or disabled. |
| 149 |
type: str |
| 150 |
choices: |
| 151 |
- Enabled |
| 152 |
- Disabled |
| 153 |
start_hour: |
| 154 |
description: |
| 155 |
- Start hour for maintenance window. |
| 156 |
type: int |
| 157 |
start_minute: |
| 158 |
description: |
| 159 |
- Start minute for maintenance window. |
| 160 |
type: int |
| 161 |
day_of_week: |
| 162 |
description: |
| 163 |
- Day of week for maintenance window. |
| 164 |
type: int |
| 165 |
point_in_time_utc: |
| 166 |
description: |
| 167 |
- Restore point creation time (ISO8601 format), specifying the time to restore from. |
| 168 |
- It's required when I(create_mode=PointInTimeRestore). |
| 169 |
type: str |
| 170 |
availability_zone: |
| 171 |
description: |
| 172 |
- Availability zone information of the server |
| 173 |
type: str |
| 174 |
cluster: |
| 175 |
description: |
| 176 |
- The elastic cluster properties of a server. |
| 177 |
type: dict |
| 178 |
suboptions: |
| 179 |
cluster_size: |
| 180 |
description: |
| 181 |
- The number of instances in the cluster. |
| 182 |
type: int |
| 183 |
required: True |
| 184 |
default_database_name: |
| 185 |
description: |
| 186 |
- The default database name for the cluster. |
| 187 |
type: str |
| 188 |
create_mode: |
| 189 |
description: |
| 190 |
- The mode to create a new PostgreSQL server. |
| 191 |
type: str |
| 192 |
choices: |
| 193 |
- Default |
| 194 |
- Create |
| 195 |
- Update |
| 196 |
- PointInTimeRestore |
| 197 |
source_server_resource_id: |
| 198 |
description: |
| 199 |
- The source server resource ID to restore from. |
| 200 |
- It's required when I(create_mode=PointInTimeRestore) |
| 201 |
type: str |
| 202 |
state: |
| 203 |
description: |
| 204 |
- Assert the state of the PostgreSQL Flexible server. |
| 205 |
- Use C(present) to create or update a server and C(absent) to delete it. |
| 206 |
default: present |
| 207 |
type: str |
| 208 |
choices: |
| 209 |
- present |
| 210 |
- absent |
| 211 |
is_restart: |
| 212 |
description: |
| 213 |
- Whether to restart the Post gresql server. |
| 214 |
type: bool |
| 215 |
default: False |
| 216 |
is_stop: |
| 217 |
description: |
| 218 |
- Whether to stop the Post gresql server. |
| 219 |
type: bool |
| 220 |
default: False |
| 221 |
is_start: |
| 222 |
description: |
| 223 |
- Whether to start the Post gresql server. |
| 224 |
type: bool |
| 225 |
default: False |
| 226 |
auth_config: |
| 227 |
description: |
| 228 |
- AuthConfig properties of a server. |
| 229 |
type: dict |
| 230 |
version_added: '3.6.0' |
| 231 |
suboptions: |
| 232 |
active_directory_auth: |
| 233 |
description: |
| 234 |
- If C(Enabled), Azure Active Directory authentication is enabled. |
| 235 |
type: str |
| 236 |
choices: |
| 237 |
- Enabled |
| 238 |
- Disabled |
| 239 |
password_auth: |
| 240 |
description: |
| 241 |
- If C(Enabled), Password authentication is enabled. |
| 242 |
type: str |
| 243 |
choices: |
| 244 |
- Enabled |
| 245 |
- Disabled |
| 246 |
tenant_id: |
| 247 |
description: |
| 248 |
- Tenant id of the server. |
| 249 |
type: str |
| 250 |
identity: |
| 251 |
description: |
| 252 |
- Identity for the Server. |
| 253 |
type: dict |
| 254 |
version_added: '2.4.0' |
| 255 |
suboptions: |
| 256 |
type: |
| 257 |
description: |
| 258 |
- Type of the managed identity |
| 259 |
required: false |
| 260 |
choices: |
| 261 |
- UserAssigned |
| 262 |
- None |
| 263 |
- SystemAssigned |
| 264 |
default: None |
| 265 |
type: str |
| 266 |
user_assigned_identities: |
| 267 |
description: |
| 268 |
- User Assigned Managed Identities and its options |
| 269 |
required: false |
| 270 |
type: dict |
| 271 |
default: {} |
| 272 |
suboptions: |
| 273 |
id: |
| 274 |
description: |
| 275 |
- List of the user assigned identities IDs associated to the VM |
| 276 |
required: false |
| 277 |
type: list |
| 278 |
elements: str |
| 279 |
default: [] |
| 280 |
append: |
| 281 |
description: |
| 282 |
- If the list of identities has to be appended to current identities (true) or if it has to replace current identities (false) |
| 283 |
required: false |
| 284 |
type: bool |
| 285 |
default: True |
| 286 |
|
| 287 |
|
| 288 |
extends_documentation_fragment: |
| 289 |
- azure.azcollection.azure |
| 290 |
- azure.azcollection.azure_tags |
| 291 |
|
| 292 |
author: |
| 293 |
- xuzhang3 (@xuzhang3) |
| 294 |
- Fred-sun (@Fred-sun) |
| 295 |
|
| 296 |
''' |
| 297 |
|
| 298 |
EXAMPLES = ''' |
| 299 |
- name: Create (or update) PostgreSQL Flexible Server |
| 300 |
azure_rm_postgresqlflexibleserver: |
| 301 |
resource_group: myResourceGroup |
| 302 |
name: testserver |
| 303 |
sku: |
| 304 |
name: Standard_B1ms |
| 305 |
tier: Burstable |
| 306 |
administrator_login: azureuser |
| 307 |
administrator_login_password: "{{ password }}" |
| 308 |
version: 12 |
| 309 |
storage: |
| 310 |
storage_size_gb: 128 |
| 311 |
fully_qualified_domain_name: st-private-dns-zone.postgres.database.azure.com |
| 312 |
backup: |
| 313 |
backup_retention_days: 7 |
| 314 |
geo_redundant_backup: Disabled |
| 315 |
maintenance_window: |
| 316 |
custom_window: Enabled |
| 317 |
start_hour: 8 |
| 318 |
start_minute: 0 |
| 319 |
day_of_week: 0 |
| 320 |
point_in_time_utc: 2023-05-31T00:28:17.7279547+00:00 |
| 321 |
availability_zone: 1 |
| 322 |
create_mode: Default |
| 323 |
|
| 324 |
- name: Create (or update) PostgreSQL Elastic Cluster with 3 nodes |
| 325 |
azure_rm_postgresqlflexibleserver: |
| 326 |
resource_group: myResourceGroup |
| 327 |
name: testserver |
| 328 |
sku: |
| 329 |
name: Standard_B1ms |
| 330 |
tier: Burstable |
| 331 |
administrator_login: azureuser |
| 332 |
administrator_login_password: "{{ password }}" |
| 333 |
version: 17 # PostgreSQL version 17 for flexible server |
| 334 |
storage: |
| 335 |
storage_size_gb: 128 |
| 336 |
fully_qualified_domain_name: st-private-dns-zone.postgres.database.azure.com |
| 337 |
backup: |
| 338 |
backup_retention_days: 7 |
| 339 |
geo_redundant_backup: Disabled |
| 340 |
maintenance_window: |
| 341 |
custom_window: Enabled |
| 342 |
start_hour: 8 |
| 343 |
start_minute: 0 |
| 344 |
day_of_week: 0 |
| 345 |
cluster: |
| 346 |
cluster_size: 3 |
| 347 |
default_database_name: "myclusterdb" |
| 348 |
point_in_time_utc: 2023-05-31T00:28:17.7279547+00:00 |
| 349 |
availability_zone: 1 |
| 350 |
create_mode: Default |
| 351 |
|
| 352 |
- name: Delete PostgreSQL Flexible Server |
| 353 |
azure_rm_postgresqlflexibleserver: |
| 354 |
resource_group: myResourceGroup |
| 355 |
name: testserver |
| 356 |
state: absent |
| 357 |
''' |
| 358 |
|
| 359 |
RETURN = ''' |
| 360 |
servers: |
| 361 |
description: |
| 362 |
- A list of dictionaries containing facts for PostgreSQL Flexible servers. |
| 363 |
returned: always |
| 364 |
type: complex |
| 365 |
contains: |
| 366 |
id: |
| 367 |
description: |
| 368 |
- Resource ID of the postgresql flexible server. |
| 369 |
returned: always |
| 370 |
type: str |
| 371 |
sample: "/subscriptions/xxx/resourceGroups/myResourceGroup/providers/Microsoft.DBforPostgreSQL/flexibleservers/postgresql3" |
| 372 |
resource_group: |
| 373 |
description: |
| 374 |
- Resource group name. |
| 375 |
returned: always |
| 376 |
type: str |
| 377 |
sample: myResourceGroup |
| 378 |
name: |
| 379 |
description: |
| 380 |
- Resource name. |
| 381 |
returned: always |
| 382 |
type: str |
| 383 |
sample: postgreabdud1223 |
| 384 |
location: |
| 385 |
description: |
| 386 |
- The location the resource resides in. |
| 387 |
returned: always |
| 388 |
type: str |
| 389 |
sample: eastus |
| 390 |
sku: |
| 391 |
description: |
| 392 |
- The SKU of the server. |
| 393 |
returned: always |
| 394 |
type: complex |
| 395 |
contains: |
| 396 |
name: |
| 397 |
description: |
| 398 |
- The name of the SKU. |
| 399 |
returned: always |
| 400 |
type: str |
| 401 |
sample: Standard_B1ms |
| 402 |
tier: |
| 403 |
description: |
| 404 |
- The tier of the particular SKU. |
| 405 |
returned: always |
| 406 |
type: str |
| 407 |
sample: Burstable |
| 408 |
storage: |
| 409 |
description: |
| 410 |
- The maximum storage allowed for a server. |
| 411 |
returned: always |
| 412 |
type: complex |
| 413 |
contains: |
| 414 |
storage_size_gb: |
| 415 |
description: |
| 416 |
- ax storage allowed for a server. |
| 417 |
type: int |
| 418 |
returned: always |
| 419 |
sample: 128 |
| 420 |
administrator_login: |
| 421 |
description: |
| 422 |
- The administrator's login name of a server. |
| 423 |
returned: always |
| 424 |
type: str |
| 425 |
sample: azureuser |
| 426 |
version: |
| 427 |
description: |
| 428 |
- Flexible Server version. |
| 429 |
returned: always |
| 430 |
type: str |
| 431 |
sample: "12" |
| 432 |
choices: |
| 433 |
- '11' |
| 434 |
- '12' |
| 435 |
- '13' |
| 436 |
fully_qualified_domain_name: |
| 437 |
description: |
| 438 |
- The fully qualified domain name of the flexible server. |
| 439 |
returned: always |
| 440 |
type: str |
| 441 |
sample: postflexiblefredpgsqlflexible.postgres.database.azure.com |
| 442 |
availability_zone: |
| 443 |
description: |
| 444 |
- Availability zone information of the server. |
| 445 |
type: str |
| 446 |
returned: always |
| 447 |
sample: 1 |
| 448 |
cluster: |
| 449 |
description: |
| 450 |
- The elastic cluster properties of a server. |
| 451 |
type: complex |
| 452 |
returned: always |
| 453 |
contains: |
| 454 |
cluster_size: |
| 455 |
description: |
| 456 |
- The number of instances in the cluster. |
| 457 |
type: int |
| 458 |
returned: always |
| 459 |
sample: 3 |
| 460 |
default_database_name: |
| 461 |
description: |
| 462 |
- The default database name for the cluster. |
| 463 |
type: str |
| 464 |
returned: always |
| 465 |
sample: mydb |
| 466 |
backup: |
| 467 |
description: |
| 468 |
- Backup properties of a server. |
| 469 |
type: complex |
| 470 |
returned: always |
| 471 |
contains: |
| 472 |
backup_retention_days: |
| 473 |
description: |
| 474 |
- Backup retention days for the server. |
| 475 |
type: int |
| 476 |
returned: always |
| 477 |
sample: 7 |
| 478 |
geo_redundant_backup: |
| 479 |
description: |
| 480 |
- A value indicating whether Geo-Redundant backup is enabled on the server. |
| 481 |
type: str |
| 482 |
returned: always |
| 483 |
sample: Disabled |
| 484 |
high_availability: |
| 485 |
description: |
| 486 |
- High availability properties of a server. |
| 487 |
type: complex |
| 488 |
returned: always |
| 489 |
contains: |
| 490 |
mode: |
| 491 |
description: |
| 492 |
- The HA mode for the server. |
| 493 |
returned: always |
| 494 |
sample: Disabled |
| 495 |
type: str |
| 496 |
standby_availability_zone: |
| 497 |
description: |
| 498 |
- availability zone information of the standby. |
| 499 |
type: str |
| 500 |
returned: always |
| 501 |
sample: null |
| 502 |
maintenance_window: |
| 503 |
description: |
| 504 |
- Maintenance window properties of a server. |
| 505 |
type: complex |
| 506 |
returned: always |
| 507 |
contains: |
| 508 |
custom_window: |
| 509 |
description: |
| 510 |
- Indicates whether custom window is enabled or disabled. |
| 511 |
returned: always |
| 512 |
sample: Enabled |
| 513 |
type: str |
| 514 |
day_of_week: |
| 515 |
description: |
| 516 |
- Day of week for maintenance window. |
| 517 |
returned: always |
| 518 |
sample: 0 |
| 519 |
type: int |
| 520 |
start_hour: |
| 521 |
description: |
| 522 |
- Start hour for maintenance window. |
| 523 |
type: int |
| 524 |
returned: always |
| 525 |
sample: 8 |
| 526 |
start_minute: |
| 527 |
description: |
| 528 |
- Start minute for maintenance window. |
| 529 |
type: int |
| 530 |
returned: always |
| 531 |
sample: 0 |
| 532 |
network: |
| 533 |
description: |
| 534 |
- Network properties of a server. |
| 535 |
type: complex |
| 536 |
returned: always |
| 537 |
contains: |
| 538 |
delegated_subnet_resource_id: |
| 539 |
description: |
| 540 |
- Delegated subnet arm resource id. |
| 541 |
type: str |
| 542 |
returned: always |
| 543 |
sample: null |
| 544 |
private_dns_zone_arm_resource_id: |
| 545 |
description: |
| 546 |
- Private dns zone arm resource id. |
| 547 |
type: str |
| 548 |
returned: always |
| 549 |
sample: null |
| 550 |
public_network_access: |
| 551 |
description: |
| 552 |
- Public network access is enabled or not. |
| 553 |
type: str |
| 554 |
returned: always |
| 555 |
sample: Enabled |
| 556 |
point_in_time_utc: |
| 557 |
description: |
| 558 |
- Restore point creation time (ISO8601 format). |
| 559 |
type: str |
| 560 |
sample: null |
| 561 |
returned: always |
| 562 |
source_server_resource_id: |
| 563 |
description: |
| 564 |
- The source server resource ID to restore from. |
| 565 |
type: str |
| 566 |
returned: always |
| 567 |
sample: null |
| 568 |
system_data: |
| 569 |
description: |
| 570 |
- The system metadata relating to this resource. |
| 571 |
type: complex |
| 572 |
returned: always |
| 573 |
contains: |
| 574 |
created_by: |
| 575 |
description: |
| 576 |
- The identity that created the resource. |
| 577 |
type: str |
| 578 |
returned: always |
| 579 |
sample: null |
| 580 |
created_by_type: |
| 581 |
description: |
| 582 |
- The type of identity that created the resource. |
| 583 |
returned: always |
| 584 |
type: str |
| 585 |
sample: null |
| 586 |
created_at: |
| 587 |
description: |
| 588 |
- The timestamp of resource creation (UTC). |
| 589 |
returned: always |
| 590 |
sample: null |
| 591 |
type: str |
| 592 |
last_modified_by: |
| 593 |
description: |
| 594 |
- The identity that last modified the resource. |
| 595 |
type: str |
| 596 |
returned: always |
| 597 |
sample: null |
| 598 |
last_modified_by_type: |
| 599 |
description: |
| 600 |
- The type of identity that last modified the resource. |
| 601 |
returned: always |
| 602 |
sample: null |
| 603 |
type: str |
| 604 |
last_modified_at: |
| 605 |
description: |
| 606 |
- The timestamp of resource last modification (UTC). |
| 607 |
returned: always |
| 608 |
sample: null |
| 609 |
type: str |
| 610 |
tags: |
| 611 |
description: |
| 612 |
- Tags assigned to the resource. Dictionary of string:string pairs. |
| 613 |
type: dict |
| 614 |
returned: always |
| 615 |
sample: { tag1: abc } |
| 616 |
auth_config: |
| 617 |
description: |
| 618 |
- AuthConfig properties of a server. |
| 619 |
type: dict |
| 620 |
returned: always |
| 621 |
sample: {"active_directory_auth": "Disabled", "password_auth": "Enabled", "tenant_id": null} |
| 622 |
''' |
| 623 |
|
| 624 |
|
| 625 |
try: |
| 626 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common_ext import AzureRMModuleBaseExt |
| 627 |
from azure.mgmt.postgresqlflexibleservers import models as PostgreSQLFlexibleModels |
| 628 |
from azure.core.exceptions import ResourceNotFoundError |
| 629 |
from azure.core.polling import LROPoller |
| 630 |
except ImportError: |
| 631 |
|
| 632 |
pass |
| 633 |
|
| 634 |
|
| 635 |
sku_spec = dict( |
| 636 |
name=dict(type='str', required=True), |
| 637 |
tier=dict(type='str', required=True, choices=["Burstable", "GeneralPurpose", "MemoryOptimized"]) |
| 638 |
) |
| 639 |
|
| 640 |
|
| 641 |
maintenance_window_spec = dict( |
| 642 |
custom_window=dict(type='str', choices=["Enabled", "Disabled"]), |
| 643 |
start_hour=dict(type='int'), |
| 644 |
start_minute=dict(type='int'), |
| 645 |
day_of_week=dict(type='int'), |
| 646 |
) |
| 647 |
|
| 648 |
|
| 649 |
high_availability_spec = dict( |
| 650 |
mode=dict(type='str', choices=["Disabled", "ZoneRedundant", "SameZone"]), |
| 651 |
standby_availability_zone=dict(type='str') |
| 652 |
) |
| 653 |
|
| 654 |
|
| 655 |
network_spec = dict( |
| 656 |
delegated_subnet_resource_id=dict(type='str'), |
| 657 |
private_dns_zone_arm_resource_id=dict(type='str'), |
| 658 |
public_network_access=dict(type='str', choices=["Enabled", "Disabled"]) |
| 659 |
) |
| 660 |
|
| 661 |
|
| 662 |
backup_spec = dict( |
| 663 |
backup_retention_days=dict(type='int'), |
| 664 |
geo_redundant_backup=dict(type='str', choices=["Enabled", "Disabled"]), |
| 665 |
) |
| 666 |
|
| 667 |
|
| 668 |
storage_spec = dict( |
| 669 |
storage_size_gb=dict(type='int') |
| 670 |
) |
| 671 |
|
| 672 |
|
| 673 |
user_assigned_identities_spec = dict( |
| 674 |
id=dict(type='list', default=[], elements='str'), |
| 675 |
append=dict(type='bool', default=True) |
| 676 |
) |
| 677 |
|
| 678 |
|
| 679 |
managed_identity_spec = dict( |
| 680 |
type=dict(type='str', choices=['UserAssigned', 'None', 'SystemAssigned'], default='None'), |
| 681 |
user_assigned_identities=dict(type='dict', options=user_assigned_identities_spec, default={}), |
| 682 |
) |
| 683 |
|
| 684 |
|
| 685 |
class AzureRMPostgreSqlFlexibleServers(AzureRMModuleBaseExt): |
| 686 |
"""Configuration class for an Azure RM PostgreSQL Flexible Server resource""" |
| 687 |
|
| 688 |
def __init__(self): |
| 689 |
self.module_arg_spec = dict( |
| 690 |
resource_group=dict( |
| 691 |
type='str', |
| 692 |
required=True |
| 693 |
), |
| 694 |
name=dict( |
| 695 |
type='str', |
| 696 |
required=True |
| 697 |
), |
| 698 |
sku=dict( |
| 699 |
type='dict', |
| 700 |
options=sku_spec |
| 701 |
), |
| 702 |
location=dict( |
| 703 |
type='str' |
| 704 |
), |
| 705 |
administrator_login=dict( |
| 706 |
type='str' |
| 707 |
), |
| 708 |
administrator_login_password=dict( |
| 709 |
type='str', |
| 710 |
no_log=True |
| 711 |
), |
| 712 |
version=dict( |
| 713 |
type='str', |
| 714 |
choices=['11', '12', '13', '14', '15', '16', '17'] |
| 715 |
), |
| 716 |
fully_qualified_domain_name=dict( |
| 717 |
type='str', |
| 718 |
), |
| 719 |
storage=dict( |
| 720 |
type='dict', |
| 721 |
options=storage_spec |
| 722 |
), |
| 723 |
backup=dict( |
| 724 |
type='dict', |
| 725 |
options=backup_spec |
| 726 |
), |
| 727 |
network=dict( |
| 728 |
type='dict', |
| 729 |
options=network_spec |
| 730 |
), |
| 731 |
high_availability=dict( |
| 732 |
type='dict', |
| 733 |
options=high_availability_spec |
| 734 |
), |
| 735 |
maintenance_window=dict( |
| 736 |
type='dict', |
| 737 |
options=maintenance_window_spec |
| 738 |
), |
| 739 |
point_in_time_utc=dict( |
| 740 |
type='str' |
| 741 |
), |
| 742 |
availability_zone=dict( |
| 743 |
type='str' |
| 744 |
), |
| 745 |
cluster=dict( |
| 746 |
type='dict', |
| 747 |
options=dict( |
| 748 |
cluster_size=dict(type='int', required=True), |
| 749 |
default_database_name=dict(type='str'), |
| 750 |
) |
| 751 |
), |
| 752 |
create_mode=dict( |
| 753 |
type='str', |
| 754 |
choices=['Default', 'Create', 'Update', 'PointInTimeRestore'] |
| 755 |
), |
| 756 |
is_start=dict( |
| 757 |
type='bool', |
| 758 |
default=False, |
| 759 |
), |
| 760 |
is_restart=dict( |
| 761 |
type='bool', |
| 762 |
default=False |
| 763 |
), |
| 764 |
is_stop=dict( |
| 765 |
type='bool', |
| 766 |
default=False |
| 767 |
), |
| 768 |
source_server_resource_id=dict( |
| 769 |
type='str' |
| 770 |
), |
| 771 |
identity=dict(type='dict', options=managed_identity_spec), |
| 772 |
auth_config=dict( |
| 773 |
type='dict', |
| 774 |
options=dict( |
| 775 |
active_directory_auth=dict(type='str', choices=['Enabled', 'Disabled']), |
| 776 |
password_auth=dict(type='str', choices=['Enabled', 'Disabled']), |
| 777 |
tenant_id=dict(type='str') |
| 778 |
) |
| 779 |
), |
| 780 |
state=dict( |
| 781 |
type='str', |
| 782 |
default='present', |
| 783 |
choices=['present', 'absent'] |
| 784 |
) |
| 785 |
) |
| 786 |
|
| 787 |
self.resource_group = None |
| 788 |
self.name = None |
| 789 |
self.parameters = dict() |
| 790 |
self.tags = None |
| 791 |
self.is_start = None |
| 792 |
self.is_stop = None |
| 793 |
self.is_restart = None |
| 794 |
self.identity = None |
| 795 |
self.auth_config = None |
| 796 |
|
| 797 |
self.results = dict(changed=False) |
| 798 |
self.state = None |
| 799 |
|
| 800 |
self._managed_identity = None |
| 801 |
|
| 802 |
super(AzureRMPostgreSqlFlexibleServers, self).__init__(derived_arg_spec=self.module_arg_spec, |
| 803 |
supports_check_mode=True, |
| 804 |
supports_tags=True) |
| 805 |
|
| 806 |
@property |
| 807 |
def managed_identity(self): |
| 808 |
if not self._managed_identity: |
| 809 |
self._managed_identity = {"identity": PostgreSQLFlexibleModels.UserAssignedIdentity, |
| 810 |
"user_assigned": PostgreSQLFlexibleModels.UserIdentity |
| 811 |
} |
| 812 |
return self._managed_identity |
| 813 |
|
| 814 |
def exec_module(self, **kwargs): |
| 815 |
"""Main module execution method""" |
| 816 |
|
| 817 |
for key in list(self.module_arg_spec.keys()) + ['tags']: |
| 818 |
if hasattr(self, key): |
| 819 |
setattr(self, key, kwargs[key]) |
| 820 |
elif kwargs[key] is not None: |
| 821 |
self.parameters[key] = kwargs[key] |
| 822 |
|
| 823 |
response = None |
| 824 |
changed = False |
| 825 |
|
| 826 |
resource_group = self.get_resource_group(self.resource_group) |
| 827 |
|
| 828 |
if "location" not in self.parameters: |
| 829 |
self.parameters["location"] = resource_group.location |
| 830 |
|
| 831 |
old_response = self.get_postgresqlflexibleserver() |
| 832 |
|
| 833 |
update_identity = False |
| 834 |
|
| 835 |
if self.identity: |
| 836 |
|
| 837 |
curr_identity = old_response.get('identity') if old_response else {} |
| 838 |
update_identity, new_identity = self.update_managed_identity( |
| 839 |
new_identity=self.identity, |
| 840 |
curr_identity=curr_identity, |
| 841 |
allow_identities_append=True, |
| 842 |
patch_support=False |
| 843 |
) |
| 844 |
if update_identity: |
| 845 |
self.parameters['identity'] = new_identity |
| 846 |
|
| 847 |
current_tags = old_response.get('tags') if old_response else None |
| 848 |
if self.tags is not None: |
| 849 |
try: |
| 850 |
append = getattr(self, 'append_tags', True) |
| 851 |
except AttributeError: |
| 852 |
append = True |
| 853 |
self.parameters['tags'] = (current_tags or {}) |
| 854 |
if append: |
| 855 |
self.parameters['tags'].update(self.tags or {}) |
| 856 |
else: |
| 857 |
self.parameters['tags'] = self.tags or {} |
| 858 |
elif current_tags is not None: |
| 859 |
self.parameters['tags'] = current_tags |
| 860 |
|
| 861 |
if self.state == 'present': |
| 862 |
if not self.check_mode: |
| 863 |
if not old_response: |
| 864 |
|
| 865 |
response = self.create_postgresqlflexibleserver(self.parameters) |
| 866 |
changed = True |
| 867 |
else: |
| 868 |
update_fields = [ |
| 869 |
'sku', 'storage', 'cluster', 'backup', 'high_availability', |
| 870 |
'maintenance_window', 'auth_config', 'identity', 'tags', |
| 871 |
'version', 'network', 'availability_zone'] |
| 872 |
desired = {k: self.parameters.get(k) for k in update_fields} |
| 873 |
current = {k: old_response.get(k) for k in update_fields} |
| 874 |
if not self.default_compare({}, desired, current, '', dict(compare=[])): |
| 875 |
|
| 876 |
response = self.update_postgresqlflexibleserver(self.parameters) |
| 877 |
changed = True |
| 878 |
else: |
| 879 |
response = old_response |
| 880 |
changed = False |
| 881 |
|
| 882 |
if self.is_stop: |
| 883 |
self.stop_postgresqlflexibleserver() |
| 884 |
changed = True |
| 885 |
elif self.is_start: |
| 886 |
self.start_postgresqlflexibleserver() |
| 887 |
changed = True |
| 888 |
elif self.is_restart: |
| 889 |
self.restart_postgresqlflexibleserver() |
| 890 |
changed = True |
| 891 |
|
| 892 |
else: |
| 893 |
response = old_response |
| 894 |
|
| 895 |
elif self.state == 'absent': |
| 896 |
if old_response: |
| 897 |
changed = True |
| 898 |
if not self.check_mode: |
| 899 |
response = self.delete_postgresqlflexibleserver() |
| 900 |
else: |
| 901 |
self.log("PostgreSQL Flexible Server instance doesn't exist, nothing to delete.") |
| 902 |
response = {} |
| 903 |
self.results['changed'] = changed |
| 904 |
self.results['state'] = response |
| 905 |
return self.results |
| 906 |
|
| 907 |
def update_postgresqlflexibleserver(self, body): |
| 908 |
''' |
| 909 |
Updates PostgreSQL Flexible Server with the specified configuration. |
| 910 |
:return: deserialized PostgreSQL Flexible Server instance state dictionary |
| 911 |
''' |
| 912 |
self.log("Updating the PostgreSQL Flexible Server instance {0}".format(self.name)) |
| 913 |
try: |
| 914 |
response = self.postgresql_flexible_client.servers.begin_create_or_update(resource_group_name=self.resource_group, |
| 915 |
server_name=self.name, |
| 916 |
parameters=body) |
| 917 |
if isinstance(response, LROPoller): |
| 918 |
response = self.get_poller_result(response) |
| 919 |
|
| 920 |
except Exception as exc: |
| 921 |
self.log('Error attempting to update the PostgreSQL Flexible Server instance.') |
| 922 |
self.fail("Error updating the PostgreSQL Flexible Server instance: {0}".format(str(exc))) |
| 923 |
return self.format_item(response) |
| 924 |
|
| 925 |
def create_postgresqlflexibleserver(self, body): |
| 926 |
''' |
| 927 |
Creates PostgreSQL Flexible Server with the specified configuration. |
| 928 |
:return: deserialized PostgreSQL Flexible Server instance state dictionary |
| 929 |
''' |
| 930 |
self.log("Creating the PostgreSQL Flexible Server instance {0}".format(self.name)) |
| 931 |
try: |
| 932 |
response = self.postgresql_flexible_client.servers.begin_create_or_update(resource_group_name=self.resource_group, |
| 933 |
server_name=self.name, |
| 934 |
parameters=body) |
| 935 |
if isinstance(response, LROPoller): |
| 936 |
response = self.get_poller_result(response) |
| 937 |
|
| 938 |
except Exception as exc: |
| 939 |
self.log('Error attempting to create the PostgreSQL Flexible Server instance.') |
| 940 |
self.fail("Error creating the PostgreSQL Flexible Server instance: {0}".format(str(exc))) |
| 941 |
return self.format_item(response) |
| 942 |
|
| 943 |
def delete_postgresqlflexibleserver(self): |
| 944 |
''' |
| 945 |
Deletes specified PostgreSQL Flexible Server instance in the specified subscription and resource group. |
| 946 |
|
| 947 |
:return: True |
| 948 |
''' |
| 949 |
self.log("Deleting the PostgreSQL Flexible Server instance {0}".format(self.name)) |
| 950 |
try: |
| 951 |
self.postgresql_flexible_client.servers.begin_delete(resource_group_name=self.resource_group, |
| 952 |
server_name=self.name) |
| 953 |
except Exception as e: |
| 954 |
self.log('Error attempting to delete the PostgreSQL Flexible Server instance.') |
| 955 |
self.fail("Error deleting the PostgreSQL Flexible Server instance: {0}".format(str(e))) |
| 956 |
|
| 957 |
def stop_postgresqlflexibleserver(self): |
| 958 |
''' |
| 959 |
Stop PostgreSQL Flexible Server instance in the specified subscription and resource group. |
| 960 |
|
| 961 |
:return: True |
| 962 |
''' |
| 963 |
self.log("Stop the PostgreSQL Flexible Server instance {0}".format(self.name)) |
| 964 |
try: |
| 965 |
self.postgresql_flexible_client.servers.begin_stop(resource_group_name=self.resource_group, |
| 966 |
server_name=self.name) |
| 967 |
except Exception as e: |
| 968 |
self.log('Error attempting to stop the PostgreSQL Flexible Server instance.') |
| 969 |
self.fail("Error stop the PostgreSQL Flexible Server instance: {0}".format(str(e))) |
| 970 |
|
| 971 |
def start_postgresqlflexibleserver(self): |
| 972 |
''' |
| 973 |
Start PostgreSQL Flexible Server instance in the specified subscription and resource group. |
| 974 |
|
| 975 |
:return: True |
| 976 |
''' |
| 977 |
self.log("Starting the PostgreSQL Flexible Server instance {0}".format(self.name)) |
| 978 |
try: |
| 979 |
self.postgresql_flexible_client.servers.begin_start(resource_group_name=self.resource_group, |
| 980 |
server_name=self.name) |
| 981 |
except Exception as e: |
| 982 |
self.log('Error attempting to start the PostgreSQL Flexible Server instance.') |
| 983 |
self.fail("Error starting the PostgreSQL Flexible Server instance: {0}".format(str(e))) |
| 984 |
|
| 985 |
def restart_postgresqlflexibleserver(self): |
| 986 |
''' |
| 987 |
Restart PostgreSQL Flexible Server instance in the specified subscription and resource group. |
| 988 |
|
| 989 |
:return: True |
| 990 |
''' |
| 991 |
self.log("Restarting the PostgreSQL Flexible Server instance {0}".format(self.name)) |
| 992 |
try: |
| 993 |
self.postgresql_flexible_client.servers.begin_restart(resource_group_name=self.resource_group, |
| 994 |
server_name=self.name) |
| 995 |
except Exception as e: |
| 996 |
self.log('Error attempting to restart the PostgreSQL Flexible Server instance.') |
| 997 |
self.fail("Error restarting the PostgreSQL Flexible Server instance: {0}".format(str(e))) |
| 998 |
|
| 999 |
def get_postgresqlflexibleserver(self): |
| 1000 |
''' |
| 1001 |
Gets the properties of the specified PostgreSQL Flexible Server. |
| 1002 |
|
| 1003 |
:return: deserialized PostgreSQL Flexible Server instance state dictionary |
| 1004 |
''' |
| 1005 |
self.log("Checking if the PostgreSQL Flexible Server instance {0} is present".format(self.name)) |
| 1006 |
try: |
| 1007 |
response = self.postgresql_flexible_client.servers.get(resource_group_name=self.resource_group, |
| 1008 |
server_name=self.name) |
| 1009 |
self.log("Response : {0}".format(response)) |
| 1010 |
self.log("PostgreSQL Flexible Server instance : {0} found".format(self.name)) |
| 1011 |
except ResourceNotFoundError as e: |
| 1012 |
self.log('Did not find the PostgreSQL Flexible Server instance. Exception as {0}'.format(str(e))) |
| 1013 |
return None |
| 1014 |
|
| 1015 |
return self.format_item(response) |
| 1016 |
|
| 1017 |
def format_item(self, item): |
| 1018 |
result = dict( |
| 1019 |
id=item.id, |
| 1020 |
resource_group=self.resource_group, |
| 1021 |
name=item.name, |
| 1022 |
sku=dict(), |
| 1023 |
location=item.location, |
| 1024 |
tags=item.tags, |
| 1025 |
system_data=dict(), |
| 1026 |
administrator_login=item.administrator_login, |
| 1027 |
version=item.version, |
| 1028 |
minor_version=item.minor_version, |
| 1029 |
fully_qualified_domain_name=item.fully_qualified_domain_name, |
| 1030 |
storage=dict(), |
| 1031 |
backup=dict(), |
| 1032 |
network=dict(), |
| 1033 |
high_availability=dict(), |
| 1034 |
maintenance_window=dict(), |
| 1035 |
source_server_resource_id=item.source_server_resource_id, |
| 1036 |
point_in_time_utc=item.point_in_time_utc, |
| 1037 |
availability_zone=item.availability_zone, |
| 1038 |
auth_config=dict(), |
| 1039 |
cluster=dict() |
| 1040 |
) |
| 1041 |
if item.sku is not None: |
| 1042 |
result['sku']['name'] = item.sku.name |
| 1043 |
result['sku']['tier'] = item.sku.tier |
| 1044 |
if item.system_data is not None: |
| 1045 |
result['system_data']['created_by'] = item.system_data.created_by |
| 1046 |
result['system_data']['created_by_type'] = item.system_data.created_by_type |
| 1047 |
result['system_data']['created_at'] = item.system_data.created_at |
| 1048 |
result['system_data']['last_modified_by'] = item.system_data.last_modified_by |
| 1049 |
result['system_data']['last_modified_by_type'] = item.system_data.last_modified_by_type |
| 1050 |
result['system_data']['last_modified_at'] = item.system_data.last_modified_at |
| 1051 |
if item.storage is not None: |
| 1052 |
result['storage']['storage_size_gb'] = item.storage.storage_size_gb |
| 1053 |
if item.backup is not None: |
| 1054 |
result['backup']['backup_retention_days'] = item.backup.backup_retention_days |
| 1055 |
result['backup']['geo_redundant_backup'] = item.backup.geo_redundant_backup |
| 1056 |
if item.network is not None: |
| 1057 |
result['network']['public_network_access'] = item.network.public_network_access |
| 1058 |
result['network']['delegated_subnet_resource_id'] = item.network.delegated_subnet_resource_id |
| 1059 |
result['network']['private_dns_zone_arm_resource_id'] = item.network.private_dns_zone_arm_resource_id |
| 1060 |
if item.high_availability is not None: |
| 1061 |
result['high_availability']['mode'] = item.high_availability.mode |
| 1062 |
result['high_availability']['standby_availability_zone'] = item.high_availability.standby_availability_zone |
| 1063 |
if item.maintenance_window is not None: |
| 1064 |
result['maintenance_window']['custom_window'] = item.maintenance_window.custom_window |
| 1065 |
result['maintenance_window']['start_minute'] = item.maintenance_window.start_minute |
| 1066 |
result['maintenance_window']['start_hour'] = item.maintenance_window.start_hour |
| 1067 |
result['maintenance_window']['day_of_week'] = item.maintenance_window.day_of_week |
| 1068 |
if item.identity is not None: |
| 1069 |
result['identity'] = item.identity.as_dict() |
| 1070 |
else: |
| 1071 |
result['identity'] = PostgreSQLFlexibleModels.UserAssignedIdentity(type='None').as_dict() |
| 1072 |
if item.auth_config is not None: |
| 1073 |
result['auth_config']['active_directory_auth'] = item.auth_config.active_directory_auth |
| 1074 |
result['auth_config']['password_auth'] = item.auth_config.password_auth |
| 1075 |
result['auth_config']['tenant_id'] = item.auth_config.tenant_id |
| 1076 |
else: |
| 1077 |
result['auth_config'] = None |
| 1078 |
if item.cluster is not None: |
| 1079 |
result['cluster']['cluster_size'] = item.cluster.cluster_size |
| 1080 |
result['cluster']['default_database_name'] = item.cluster.default_database_name |
| 1081 |
else: |
| 1082 |
result['cluster']['cluster_size'] = None |
| 1083 |
result['cluster']['default_database_name'] = None |
| 1084 |
|
| 1085 |
return result |
| 1086 |
|
| 1087 |
|
| 1088 |
def main(): |
| 1089 |
"""Main execution""" |
| 1090 |
AzureRMPostgreSqlFlexibleServers() |
| 1091 |
|
| 1092 |
|
| 1093 |
if __name__ == '__main__': |
| 1094 |
main() |