# Postgres Cluster

## postgres\_cluster

This is a module that supports creating, updating, restoring or destroying Postgres Clusters

### Example Syntax

```yaml

name: Create Cluster
ionoscloudsdk.ionoscloud.postgres_cluster:
  postgres_version: 12
  instances: 1
  cores: 1
  ram: 2048
  storage_size: 20480
  storage_type: SSD Premium
  location: de/fra
  backup_location: eu-central-2
  connections:
  - cidr: 192.168.1.106/24
    datacenter: 'AnsibleAutoTestDBaaS - DBaaS'
    lan: test_lan1
  display_name: backuptest-04
  synchronization_mode: ASYNCHRONOUS
  db_username: clusteruser
  db_password: 7357cluster
  wait: true
register: cluster_response


name: Update Cluster
ionoscloudsdk.ionoscloud.postgres_cluster:
  postgres_cluster: ''
  instances: 2
  cores: 2
  ram: 4096
  storage_size: 30480
  state: update
  wait: true
register: updated_cluster_response


name: Delete Cluster
ionoscloudsdk.ionoscloud.postgres_cluster:
  postgres_cluster: ''
  state: absent
  wait: false

```

&#x20; &#x20;

### Returned object

```json
{
    "changed": true,
    "failed": false,
    "action": "create",
    "postgres_cluster": {
        "type": "cluster",
        "id": "46c151c7-55f8-42a4-86c3-06ad6b4b91ea",
        "metadata": {
            "created_date": "2023-05-30T14:35:40+00:00",
            "created_by": "<USER_EMAIL>",
            "created_by_user_id": "<USER_ID>",
            "last_modified_date": null,
            "last_modified_by": null,
            "last_modified_by_user_id": null,
            "state": "BUSY"
        },
        "properties": {
            "display_name": "backuptest-04",
            "postgres_version": "12",
            "location": "de/fra",
            "backup_location": "eu-central-2",
            "instances": 1,
            "ram": 2048,
            "cores": 1,
            "storage_size": 20480,
            "storage_type": "SSD Premium",
            "connections": [
                {
                    "datacenter_id": "03a8fdf1-fbc4-43f6-91ce-0506444e17dd",
                    "lan_id": "2",
                    "cidr": "<CIDR>"
                }
            ],
            "maintenance_window": {
                "time": "12:15:19",
                "day_of_the_week": "Monday"
            },
            "synchronization_mode": "ASYNCHRONOUS"
        }
    }
}

```

#### For more examples please check out the tests [here](https://github.com/ionos-cloud/module-ansible/tree/master/tests/dbaas-postgres).

&#x20;

***NOTE:*** **If you are using a versions 7.0.0 and up**: modules can replace resources if certain set parameters differ from the results found in the API!

### Parameters that can trigger a resource replacement:

* connections
* backup\_location
* location
* synchronization\_mode
* storage\_type &#x20;

## state: **present**

```yaml
  
name: Create Cluster
ionoscloudsdk.ionoscloud.postgres_cluster:
  postgres_version: 12
  instances: 1
  cores: 1
  ram: 2048
  storage_size: 20480
  storage_type: SSD Premium
  location: de/fra
  backup_location: eu-central-2
  connections:
  - cidr: 192.168.1.106/24
    datacenter: 'AnsibleAutoTestDBaaS - DBaaS'
    lan: test_lan1
  display_name: backuptest-04
  synchronization_mode: ASYNCHRONOUS
  db_username: clusteruser
  db_password: 7357cluster
  wait: true
register: cluster_response

```

#### Available parameters for state **present**:

&#x20;

<table data-full-width="true"><thead><tr><th width="70">Name</th><th width="40" align="center">Required</th><th>Description</th></tr></thead><tbody><tr><td>maintenance_window<br><mark style="color:blue;">dict</mark></td><td align="center">False</td><td>A weekly 4 hour-long window, during which maintenance might occur.</td></tr><tr><td>postgres_version<br><mark style="color:blue;">str</mark></td><td align="center">True</td><td>The PostgreSQL version of your cluster.</td></tr><tr><td>instances<br><mark style="color:blue;">int</mark></td><td align="center">True</td><td>The total number of instances in the cluster (one master and n-1 standbys).</td></tr><tr><td>cores<br><mark style="color:blue;">int</mark></td><td align="center">True</td><td>The number of CPU cores per instance.</td></tr><tr><td>ram<br><mark style="color:blue;">int</mark></td><td align="center">True</td><td>The amount of memory per instance in megabytes. Has to be a multiple of 1024.</td></tr><tr><td>storage_size<br><mark style="color:blue;">int</mark></td><td align="center">True</td><td>The amount of storage per instance in megabytes.</td></tr><tr><td>storage_type<br><mark style="color:blue;">str</mark></td><td align="center">True</td><td>The storage type used in your cluster. (Value "SSD" is deprecated. Use the equivalent "SSD Premium" instead)<br>Options: ['HDD', 'SSD', 'SSD Standard', 'SSD Premium']</td></tr><tr><td>connections<br><mark style="color:blue;">list</mark></td><td align="center">True</td><td>Array of datacenters to connect to your cluster.</td></tr><tr><td>location<br><mark style="color:blue;">str</mark></td><td align="center">True</td><td>The physical location where the cluster will be created. This will be where all of your instances live. Property cannot be modified after datacenter creation.</td></tr><tr><td>display_name<br><mark style="color:blue;">str</mark></td><td align="center">True</td><td>The friendly name of your cluster.</td></tr><tr><td>db_username<br><mark style="color:blue;">str</mark></td><td align="center">True</td><td>The username for the initial PostgreSQL user. Some system usernames are restricted (e.g. "postgres", "admin", "standby").</td></tr><tr><td>db_password<br><mark style="color:blue;">str</mark></td><td align="center">True</td><td>The password for the initial postgres user.</td></tr><tr><td>synchronization_mode<br><mark style="color:blue;">str</mark></td><td align="center">True</td><td>Represents different modes of replication.</td></tr><tr><td>backup_location<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The S3 location where the backups will be stored.</td></tr><tr><td>backup_id<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The ID of the backup to be used.</td></tr><tr><td>recovery_target_time<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>Recovery target time.</td></tr><tr><td>allow_replace<br><mark style="color:blue;">bool</mark></td><td align="center">False</td><td>Boolean indicating if the resource should be recreated when the state cannot be reached in another way. This may be used to prevent resources from being deleted from specifying a different value to an immutable property. An error will be thrown instead<br>Default: False</td></tr><tr><td>api_url<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos API base URL.</td></tr><tr><td>certificate_fingerprint<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos API certificate fingerprint.</td></tr><tr><td>username<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos username. Overrides the IONOS_USERNAME environment variable.</td></tr><tr><td>password<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos password. Overrides the IONOS_PASSWORD environment variable.</td></tr><tr><td>token<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos token. Overrides the IONOS_TOKEN environment variable.</td></tr><tr><td>wait<br><mark style="color:blue;">bool</mark></td><td align="center">False</td><td>Wait for the resource to be created before returning.<br>Default: True<br>Options: [True, False]</td></tr><tr><td>wait_timeout<br><mark style="color:blue;">int</mark></td><td align="center">False</td><td>How long before wait gives up, in seconds.<br>Default: 600</td></tr><tr><td>state<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>Indicate desired state of the resource.<br>Default: present<br>Options: ['present', 'absent', 'update', 'restore']</td></tr></tbody></table>

&#x20;

&#x20;

## state: **absent**

```yaml
  
name: Delete Cluster
ionoscloudsdk.ionoscloud.postgres_cluster:
  postgres_cluster: ''
  state: absent
  wait: false

```

#### Available parameters for state **absent**:

&#x20;

<table data-full-width="true"><thead><tr><th width="70">Name</th><th width="40" align="center">Required</th><th>Description</th></tr></thead><tbody><tr><td>postgres_cluster<br><mark style="color:blue;">str</mark></td><td align="center">True</td><td>The ID or name of an existing Postgres Cluster.</td></tr><tr><td>api_url<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos API base URL.</td></tr><tr><td>certificate_fingerprint<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos API certificate fingerprint.</td></tr><tr><td>username<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos username. Overrides the IONOS_USERNAME environment variable.</td></tr><tr><td>password<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos password. Overrides the IONOS_PASSWORD environment variable.</td></tr><tr><td>token<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos token. Overrides the IONOS_TOKEN environment variable.</td></tr><tr><td>wait<br><mark style="color:blue;">bool</mark></td><td align="center">False</td><td>Wait for the resource to be created before returning.<br>Default: True<br>Options: [True, False]</td></tr><tr><td>wait_timeout<br><mark style="color:blue;">int</mark></td><td align="center">False</td><td>How long before wait gives up, in seconds.<br>Default: 600</td></tr><tr><td>state<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>Indicate desired state of the resource.<br>Default: present<br>Options: ['present', 'absent', 'update', 'restore']</td></tr></tbody></table>

&#x20;

&#x20;

## state: **update**

```yaml
  
name: Update Cluster
ionoscloudsdk.ionoscloud.postgres_cluster:
  postgres_cluster: ''
  instances: 2
  cores: 2
  ram: 4096
  storage_size: 30480
  state: update
  wait: true
register: updated_cluster_response

```

#### Available parameters for state **update**:

&#x20;

<table data-full-width="true"><thead><tr><th width="70">Name</th><th width="40" align="center">Required</th><th>Description</th></tr></thead><tbody><tr><td>maintenance_window<br><mark style="color:blue;">dict</mark></td><td align="center">False</td><td>A weekly 4 hour-long window, during which maintenance might occur.</td></tr><tr><td>postgres_version<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The PostgreSQL version of your cluster.</td></tr><tr><td>instances<br><mark style="color:blue;">int</mark></td><td align="center">False</td><td>The total number of instances in the cluster (one master and n-1 standbys).</td></tr><tr><td>cores<br><mark style="color:blue;">int</mark></td><td align="center">False</td><td>The number of CPU cores per instance.</td></tr><tr><td>ram<br><mark style="color:blue;">int</mark></td><td align="center">False</td><td>The amount of memory per instance in megabytes. Has to be a multiple of 1024.</td></tr><tr><td>storage_size<br><mark style="color:blue;">int</mark></td><td align="center">False</td><td>The amount of storage per instance in megabytes.</td></tr><tr><td>display_name<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The friendly name of your cluster.</td></tr><tr><td>postgres_cluster<br><mark style="color:blue;">str</mark></td><td align="center">True</td><td>The ID or name of an existing Postgres Cluster.</td></tr><tr><td>allow_replace<br><mark style="color:blue;">bool</mark></td><td align="center">False</td><td>Boolean indicating if the resource should be recreated when the state cannot be reached in another way. This may be used to prevent resources from being deleted from specifying a different value to an immutable property. An error will be thrown instead<br>Default: False</td></tr><tr><td>api_url<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos API base URL.</td></tr><tr><td>certificate_fingerprint<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos API certificate fingerprint.</td></tr><tr><td>username<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos username. Overrides the IONOS_USERNAME environment variable.</td></tr><tr><td>password<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos password. Overrides the IONOS_PASSWORD environment variable.</td></tr><tr><td>token<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos token. Overrides the IONOS_TOKEN environment variable.</td></tr><tr><td>wait<br><mark style="color:blue;">bool</mark></td><td align="center">False</td><td>Wait for the resource to be created before returning.<br>Default: True<br>Options: [True, False]</td></tr><tr><td>wait_timeout<br><mark style="color:blue;">int</mark></td><td align="center">False</td><td>How long before wait gives up, in seconds.<br>Default: 600</td></tr><tr><td>state<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>Indicate desired state of the resource.<br>Default: present<br>Options: ['present', 'absent', 'update', 'restore']</td></tr></tbody></table>

&#x20;

&#x20;

## state: **restore**

```yaml
  
```

#### Available parameters for state **restore**:

&#x20;

<table data-full-width="true"><thead><tr><th width="70">Name</th><th width="40" align="center">Required</th><th>Description</th></tr></thead><tbody><tr><td>backup_id<br><mark style="color:blue;">str</mark></td><td align="center">True</td><td>The ID of the backup to be used.</td></tr><tr><td>recovery_target_time<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>Recovery target time.</td></tr><tr><td>postgres_cluster<br><mark style="color:blue;">str</mark></td><td align="center">True</td><td>The ID or name of an existing Postgres Cluster.</td></tr><tr><td>api_url<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos API base URL.</td></tr><tr><td>certificate_fingerprint<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos API certificate fingerprint.</td></tr><tr><td>username<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos username. Overrides the IONOS_USERNAME environment variable.</td></tr><tr><td>password<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos password. Overrides the IONOS_PASSWORD environment variable.</td></tr><tr><td>token<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos token. Overrides the IONOS_TOKEN environment variable.</td></tr><tr><td>wait<br><mark style="color:blue;">bool</mark></td><td align="center">False</td><td>Wait for the resource to be created before returning.<br>Default: True<br>Options: [True, False]</td></tr><tr><td>wait_timeout<br><mark style="color:blue;">int</mark></td><td align="center">False</td><td>How long before wait gives up, in seconds.<br>Default: 600</td></tr><tr><td>state<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>Indicate desired state of the resource.<br>Default: present<br>Options: ['present', 'absent', 'update', 'restore']</td></tr></tbody></table>

&#x20;

&#x20;
