terraform-provider-yandex icon indicating copy to clipboard operation
terraform-provider-yandex copied to clipboard

Add resource to create Yandex Database table

Open vyablokov opened this issue 3 years ago • 7 comments

When initializing Terraform remote state it is a good practice to use not only s3 bucket for keeping the state file itself, but also DynamoDB-compatible database to control state locks. For this purpose I have created a serverless YDB instance as a yandex_ydb_database_serverless resource. But then I have discovered that it is not currently possible to create the lock table in the database. I have found a related example provided by yandex-cloud team, where it is advised to create the table manually.

I think that it would be very useful to have a YDB table resource in Yandex Terraform provider: for comparison, there is a similar dynamodb_table resource in the official AWS Terraform provider. If such resource is provided, the process of creating Terraform remote state backend can be completely automatized.

vyablokov avatar Aug 10 '21 12:08 vyablokov

Thanks for reaching out. Let us investigate this and get back to you with the results. Stay tuned!

apilikov avatar Aug 10 '21 14:08 apilikov

BTW have you tried combining AWS's dynamodb_table with YDB Serverless?

apilikov avatar Aug 10 '21 14:08 apilikov

BTW have you tried combining AWS's dynamodb_table with YDB Serverless?

Actually, I did not. Thanks for advice, I'll check it out.

vyablokov avatar Aug 10 '21 14:08 vyablokov

Hello,

I've tried to use AWS provider with Yandex config to create table, but unfortunately failed: error describing DynamoDB Table (cui) Continuous Backups: InvalidAction: Unsupported action "DescribeContinuousBackups" │ status code: 400, request id:

my tricks (actual credentials were set in env vars):

provider "aws" {
  alias = "aws-compatible-yandex"
  region = "ru-central1"
  endpoints {
    dynamodb = "${yandex_ydb_database_serverless.db.document_api_endpoint}"
  }

  skip_credentials_validation = true
  skip_region_validation = true
  skip_requesting_account_id = true
  skip_metadata_api_check = true
}

resource "aws_dynamodb_table" "db-table" {
  provider = aws.aws-compatible-yandex

  name           = var.stack-name
  billing_mode = "PAY_PER_REQUEST"
  hash_key       = "uid"
  range_key      = "type"

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

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

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

  global_secondary_index {
    name               = "uuid"
    hash_key           = "uuid"
    projection_type    = "ALL"
  }
}

So it would be really helpful to have table resource implemented in Yandex TF provider.

A-Shevchenko avatar Nov 04 '21 21:11 A-Shevchenko

I can confirm I had the same problem when tried to use AWS Terraform Provider to create DocumentDB tables in YDB:

Error: reading Amazon DynamoDB Table (sections/news): continuous backups: InvalidAction: Unsupported action "DescribeContinuousBackups"

I would be glad to create tables using Terraform way. Currently, the only option is to use scripting for this purpose.

My Terraform config:

resource "yandex_ydb_database_serverless" "sections" {
  name = "sections"
}

provider "aws" {
  access_key                  = var.YC_SERVICE_ACCOUNT_STATIC_ACCESS_KEY
  secret_key                  = var.YC_SERVICE_ACCOUNT_STATIC_SECRET_KEY
  region                      = "ru-central1"
  skip_credentials_validation = true
  skip_metadata_api_check     = true
  skip_requesting_account_id  = true
  skip_get_ec2_platforms      = true
  skip_region_validation      = true

  endpoints {
    dynamodb = yandex_ydb_database_serverless.sections.document_api_endpoint
  }
}

resource "aws_dynamodb_table" "sections_news" {
  name         = "sections/news"
  hash_key     = "PostId"
  billing_mode = "PAY_PER_REQUEST"

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

flaksp avatar Aug 06 '22 19:08 flaksp

Any updates ?

patsevanton avatar May 22 '23 10:05 patsevanton