github.com/adrian-bl/terraform@v0.7.0-rc2.0.20160705220747-de0a34fc3517/website/source/docs/providers/aws/d/iam_policy_document.html.markdown (about)

     1  ---
     2  layout: "aws"
     3  page_title: "AWS: aws_iam_policy_document"
     4  sidebar_current: "docs-aws-datasource-iam-policy-document"
     5  description: |-
     6    Generates an IAM policy document in JSON format
     7  ---
     8  
     9  # aws\_iam\_policy\_document
    10  
    11  Generates an IAM policy document in JSON format.
    12  
    13  This is a data source which can be used to construct a JSON representation of
    14  an IAM policy document, for use with resources which expect policy documents,
    15  such as the `aws_iam_policy` resource.
    16  
    17  ```
    18  data "aws_iam_policy_document" "example" {
    19      statement {
    20          actions = [
    21              "s3:ListAllMyBuckets",
    22              "s3:GetBucketLocation",
    23          ]
    24          resources = [
    25              "arn:aws:s3:::*",
    26          ]
    27      }
    28  
    29      statement {
    30          actions = [
    31              "s3:ListBucket",
    32          ]
    33          resources = [
    34              "arn:aws:s3:::${var.s3_bucket_name}",
    35          ]
    36          condition {
    37              test = "StringLike"
    38              variable = "s3:prefix"
    39              values = [
    40                  "",
    41                  "home/",
    42                  "home/&{aws:username}/",
    43              ]
    44          }
    45      }
    46  
    47      statement {
    48          actions = [
    49              "s3:*",
    50          ]
    51          resources = [
    52              "arn:aws:s3:::${var.s3_bucket_name}/home/&{aws:username}",
    53              "arn:aws:s3:::${var.s3_bucket_name}/home/&{aws:username}/*",
    54          ]
    55      }
    56  
    57  }
    58  
    59  resource "aws_iam_policy" "example" {
    60      name = "example_policy"
    61      path = "/"
    62      policy = "${data.aws_iam_policy.example.json}"
    63  }
    64  ```
    65  
    66  Using this data source to generate policy documents is *optional*. It is also
    67  valid to use literal JSON strings within your configuration, or to use the
    68  `file` interpolation function to read a raw JSON policy document from a file.
    69  
    70  ## Argument Reference
    71  
    72  The following arguments are supported:
    73  
    74  * `id` (Optional) - An ID for the policy document.
    75  * `statement` (Required) - A nested configuration block (described below)
    76    configuring one *statement* to be included in the policy document.
    77  
    78  Each document configuration must have one or more `statement` blocks, which
    79  each accept the following arguments:
    80  
    81  * `id` (Optional) - An ID for the policy statement.
    82  * `effect` (Optional) - Either "Allow" or "Deny", to specify whether this
    83    statement allows or denies the given actions. The default is "Allow".
    84  * `actions` (Optional) - A list of actions that this statement either allows
    85    or denies. For example, ``["ec2:RunInstances", "s3:*"]``.
    86  * `not_actions` (Optional) - A list of actions that this statement does *not*
    87    apply to. Used to apply a policy statement to all actions *except* those
    88    listed.
    89  * `resources` (Optional) - A list of resource ARNs that this statement applies
    90    to.
    91  * `not_resources` (Optional) - A list of resource ARNs that this statement
    92    does *not* apply to. Used to apply a policy statement to all resources
    93    *except* those listed.
    94  * `principals` (Optional) - A nested configuration block (described below)
    95    specifying a resource (or resource pattern) to which this statement applies.
    96  * `not_principals` (Optional) - Like `principals` except gives resources that
    97    the statement does *not* apply to.
    98  * `condition` (Optional) - A nested configuration block (described below)
    99    that defines a further, possibly-service-specific condition that constrains
   100    whether this statement applies.
   101  
   102  Each policy may have either zero or more `principals` blocks or zero or more
   103  `not_principals` blocks, both of which each accept the following arguments:
   104  
   105  * `type` (Required) The type of principal. For AWS accounts this is "AWS".
   106  * `identifiers` (Required) List of identifiers for principals. When `type`
   107    is "AWS", these are IAM user or role ARNs.
   108  
   109  Each policy statement may have zero or more `condition` blocks, which each
   110  accept the following arguments:
   111  
   112  * `test` (Required) The name of the
   113    [IAM condition type](http://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements.html#AccessPolicyLanguage_ConditionType)
   114    to evaluate.
   115  * `variable` (Required) The name of a
   116    [Context Variable](http://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements.html#AvailableKeys)
   117    to apply the condition to. Context variables may either be standard AWS
   118    variables starting with `aws:`, or service-specific variables prefixed with
   119    the service name.
   120  * `values` (Required) The values to evaluate the condition against. If multiple
   121    values are provided, the condition matches if at least one of them applies.
   122    (That is, the tests are combined with the "OR" boolean operation.)
   123  
   124  When multiple `condition` blocks are provided, they must *all* evaluate to true
   125  for the policy statement to apply. (In other words, the conditions are combined
   126  with the "AND" boolean operation.)
   127  
   128  ## Context Variable Interpolation
   129  
   130  The IAM policy document format allows context variables to be interpolated
   131  into various strings within a statement. The native IAM policy document format
   132  uses `${...}`-style syntax that is in conflict with Terraform's interpolation
   133  syntax, so this data source instead uses `&{...}` syntax for interpolations that
   134  should be processed by AWS rather than by Terraform.
   135  
   136  ## Attributes Reference
   137  
   138  The following attribute is exported:
   139  
   140  * `json` - The above arguments serialized as a standard JSON policy document.
   141