Resource: aws_appsync_datasource

Provides an AppSync Data Source.

Example Usage

resource "aws_dynamodb_table" "example" {
  name           = "example"
  read_capacity  = 1
  write_capacity = 1
  hash_key       = "UserId"

  attribute {
    name = "UserId"
    type = "S"
  }
}

data "aws_iam_policy_document" "assume_role" {
  statement {
    effect = "Allow"

    principals {
      type        = "Service"
      identifiers = ["appsync.amazonaws.com"]
    }

    actions = ["sts:AssumeRole"]
  }
}
resource "aws_iam_role" "example" {
  name               = "example"
  assume_role_policy = data.aws_iam_policy_document.assume_role.json
}

data "aws_iam_policy_document" "example" {
  statement {
    effect    = "Allow"
    actions   = ["dynamodb:*"]
    resources = [aws_dynamodb_table.example.arn]
  }
}

resource "aws_iam_role_policy" "example" {
  name   = "example"
  role   = aws_iam_role.example.id
  policy = data.aws_iam_policy_document.example.json
}

resource "aws_appsync_graphql_api" "example" {
  authentication_type = "API_KEY"
  name                = "tf_appsync_example"
}

resource "aws_appsync_datasource" "example" {
  api_id           = aws_appsync_graphql_api.example.id
  name             = "tf_appsync_example"
  service_role_arn = aws_iam_role.example.arn
  type             = "AMAZON_DYNAMODB"

  dynamodb_config {
    table_name = aws_dynamodb_table.example.name
  }
}

Argument Reference

This resource supports the following arguments:

DynamoDB Config

This argument supports the following arguments:

Delta Sync Config

ElasticSearch Config

This argument supports the following arguments:

Event Bridge Config

This argument supports the following arguments:

HTTP Config

This argument supports the following arguments:

Authorization Config

This argument supports the following arguments:

AWS IAM Config

This argument supports the following arguments:

Lambda Config

This argument supports the following arguments:

OpenSearch Service Config

This argument supports the following arguments:

Relational Database Config

This argument supports the following arguments:

HTTP Endpoint Config

This argument supports the following arguments:

Attribute Reference

This resource exports the following attributes in addition to the arguments above:

Import

In Terraform v1.5.0 and later, use an import block to import aws_appsync_datasource using the api_id, a hyphen, and name. For example:

import {
  to = aws_appsync_datasource.example
  id = "abcdef123456-example"
}

Using terraform import, import aws_appsync_datasource using the api_id, a hyphen, and name. For example:

% terraform import aws_appsync_datasource.example abcdef123456-example