{
  "id": "kv/data-write",
  "description": "Allows reading and writing data to key-value stores",
  "platforms": {
    "aws": [
      {
        "grant": {
          "actions": [
            "dynamodb:GetItem",
            "dynamodb:Query",
            "dynamodb:Scan",
            "dynamodb:PutItem",
            "dynamodb:UpdateItem",
            "dynamodb:DeleteItem",
            "dynamodb:DescribeTable"
          ]
        },
        "binding": {
          "stack": {
            "resources": ["arn:aws:dynamodb:${awsRegion}:${awsAccountId}:table/${stackPrefix}-*"]
          },
          "resource": {
            "resources": ["arn:aws:dynamodb:${awsRegion}:${awsAccountId}:table/${resourceName}"]
          }
        }
      }
    ],
    "gcp": [
      {
        "grant": {
          "permissions": [
            "datastore.entities.get",
            "datastore.entities.list",
            "datastore.entities.create",
            "datastore.entities.update",
            "datastore.entities.delete"
          ]
        },
        "binding": {
          "stack": {
            "scope": "projects/${projectName}",
            "condition": {
              "title": "KV data write access",
              "expression": "resource.type == 'datastore.googleapis.com/Entity' && resource.name.startsWith('projects/${projectName}/databases/(default)/documents/kv-${stackPrefix}-')"
            }
          },
          "resource": {
            "scope": "projects/${projectName}",
            "condition": {
              "title": "KV data write access",
              "expression": "resource.type == 'datastore.googleapis.com/Entity' && resource.name.startsWith('projects/${projectName}/databases/(default)/documents/kv-${stackPrefix}-${resourceName}/')"
            }
          }
        }
      }
    ],
    "azure": [
      {
        "grant": {
          "actions": [
            "Microsoft.Storage/storageAccounts/tableServices/read",
            "Microsoft.Storage/storageAccounts/tableServices/tables/read"
          ],
          "dataActions": [
            "Microsoft.Storage/storageAccounts/tableServices/tables/entities/read",
            "Microsoft.Storage/storageAccounts/tableServices/tables/entities/write",
            "Microsoft.Storage/storageAccounts/tableServices/tables/entities/delete"
          ]
        },
        "binding": {
          "stack": {
            "scope": "/subscriptions/${subscriptionId}/resourceGroups/${resourceGroup}/providers/Microsoft.Storage/storageAccounts/${storageAccountName}"
          },
          "resource": {
            "scope": "/subscriptions/${subscriptionId}/resourceGroups/${resourceGroup}/providers/Microsoft.Storage/storageAccounts/${storageAccountName}"
          }
        }
      }
    ]
  }
}
