github.com/nathanielks/terraform@v0.6.1-0.20170509030759-13e1a62319dc/website/source/docs/providers/postgresql/r/postgresql_schema.html.markdown (about)

     1  ---
     2  layout: "postgresql"
     3  page_title: "PostgreSQL: postgresql_schema"
     4  sidebar_current: "docs-postgresql-resource-postgresql_schema"
     5  description: |-
     6    Creates and manages a schema within a PostgreSQL database.
     7  ---
     8  
     9  # postgresql\_schema
    10  
    11  The ``postgresql_schema`` resource creates and manages [schema
    12  objects](https://www.postgresql.org/docs/current/static/ddl-schemas.html) within
    13  a PostgreSQL database.
    14  
    15  
    16  ## Usage
    17  
    18  ```hcl
    19  resource "postgresql_role" "app_www" {
    20    name = "app_www"
    21  }
    22  
    23  resource "postgresql_role" "app_dba" {
    24    name = "app_dba"
    25  }
    26  
    27  resource "postgresql_role" "app_releng" {
    28    name = "app_releng"
    29  }
    30  
    31  resource "postgresql_schema" "my_schema" {
    32    name  = "my_schema"
    33    owner = "postgres"
    34  
    35    policy {
    36      usage = true
    37      role  = "${postgresql_role.app_www.name}"
    38    }
    39  
    40    # app_releng can create new objects in the schema.  This is the role that
    41    # migrations are executed as.
    42    policy {
    43      create = true
    44      usage  = true
    45      role   = "${postgresql_role.app_releng.name}"
    46    }
    47  
    48    policy {
    49      create_with_grant = true
    50      usage_with_grant  = true
    51      role              = "${postgresql_role.app_dba.name}"
    52    }
    53  }
    54  ```
    55  
    56  ## Argument Reference
    57  
    58  * `name` - (Required) The name of the schema. Must be unique in the PostgreSQL
    59    database instance where it is configured.
    60  * `owner` - (Optional) The ROLE who owns the schema.
    61  * `policy` - (Optional) Can be specified multiple times for each policy.  Each
    62      policy block supports fields documented below.
    63  
    64  The `policy` block supports:
    65  
    66  * `create` - (Optional) Should the specified ROLE have CREATE privileges to the specified SCHEMA.
    67  * `create_with_grant` - (Optional) Should the specified ROLE have CREATE privileges to the specified SCHEMA and the ability to GRANT the CREATE privilege to other ROLEs.
    68  * `role` - (Optional) The ROLE who is receiving the policy.  If this value is empty or not specified it implies the policy is referring to the [`PUBLIC` role](https://www.postgresql.org/docs/current/static/sql-grant.html).
    69  * `usage` - (Optional) Should the specified ROLE have USAGE privileges to the specified SCHEMA.
    70  * `usage_with_grant` - (Optional) Should the specified ROLE have USAGE privileges to the specified SCHEMA and the ability to GRANT the USAGE privilege to other ROLEs.
    71  
    72  ~> **NOTE on `policy`:** The permissions of a role specified in multiple policy blocks is cumulative.  For example, if the same role is specified in two different `policy` each with different permissions (e.g. `create` and `usage_with_grant`, respectively), then the specified role with have both `create` and `usage_with_grant` privileges.
    73  
    74  ## Import Example
    75  
    76  `postgresql_schema` supports importing resources.  Supposing the following
    77  Terraform:
    78  
    79  ```hcl
    80  resource "postgresql_schema" "public" {
    81    name = "public"
    82  }
    83  
    84  resource "postgresql_schema" "schema_foo" {
    85    name  = "my_schema"
    86    owner = "postgres"
    87  
    88    policy {
    89      usage = true
    90    }
    91  }
    92  ```
    93  
    94  It is possible to import a `postgresql_schema` resource with the following
    95  command:
    96  
    97  ```
    98  $ terraform import postgresql_schema.schema_foo my_schema
    99  ```
   100  
   101  Where `my_schema` is the name of the schema in the PostgreSQL database and
   102  `postgresql_schema.schema_foo` is the name of the resource whose state will be
   103  populated as a result of the command.