ããã¯ããªã«ãããããŠæžãããã®ïŒ
Terraform 1.6ã§testing frameworkãè¿œå ãããã®ã§ã以åã«è©ŠããŠã¿ãŸããã
Terraform 1.6で追加されたTerraform testing framework(terraform test)を試す - CLOVER🍀
ãããŠTerraform 1.7ã§ã¯ããã«ã¢ãã¯ãè¿œå ãããŸããã
Terraform 1.7 adds test mocking and config-driven remove
ä»åã¯ããã®ã¢ãã¯ãè©ŠããŠã¿ãããšæããŸãã
ã¢ãã¯ïŒMocksïŒ
Terraform 1.7ã«é¢ãããªãªãŒã¹ããã°ã¯ãã¡ãã
Terraform 1.7 adds test mocking and config-driven remove
Terraform 1.6ã§ã¯HCLã䜿ã£ãŠTerraformã³ãŒãã®åäœãã¹ããçµåãã¹ããå®è¡å¯èœãªtesting frameworkãå°å ¥ãããŸããã
ãã®æç¹ã§ã¯planãapplyã§ã¯å®éã®ãããã€ããŒãåŒã³åºããŠå®è¡ããŠããŸããããTerraform 1.7ã§ã¯ããã«ã¢ãã¯ã®å©çšãå¯èœã«
ãªã£ãŠããŸãã
å©çšæ¹æ³ãšããŠã¯ã以äžã®2ã€ãããããã§ãã
- ãããã€ããŒèªäœãã¢ãã¯ã«ãã
- ç¹å®ã®ãªãœãŒã¹ãããŒã¿ãœãŒã¹ãã¢ãžã¥ãŒã«ã®ãã¡ã®ç¹å®ã®ã€ã³ã¹ã¿ã³ã¹ããªãŒããŒã©ã€ãããŠã¢ãã¯ã«ãã
åŸè
ã®ãªãŒããŒã©ã€ãã®æ¹ã¯ããã¹ãå
šäœã«é©çšããããšãã§ããã°ãrun
ãããã¯å
ã§å®çŸ©ããŠé©çšç¯å²ãçµãããšãã§ããããã§ãã
ãŸãå®éã®ãããã€ããŒãšã¢ãã¯ãããã€ããŒã®äž¡æ¹ã§äœ¿çšã§ããããã§ãã
ããããžã§ãã³ã°ã«æéã®ããããªãœãŒã¹ãã¢ãã¯ã«ããããåºåã®ã¿ã欲ããå Žåãªã©ãæ§ã ãªã±ãŒã¹ã§äœ¿ããã ããããšãããŠããŸãã
ãã詳现ãªå 容ã¯ãããã¥ã¡ã³ããåç §ããšããããšã§ã
Tests - Provider Mocking | Terraform | HashiCorp Developer
ãã¡ãã¯å®éã«äœ¿ãæã«ãããå°ã詳现ã«èŠãŠããããšæããŸãã
ãŸããã¥ãŒããªã¢ã«ã«ãã¢ãã¯ãåºãŠããããã§ãã
Write Terraform Tests | Terraform | HashiCorp Developer
ãã®ä»ãTerraform 1.7ã§ã¯ãã¹ãã«é¢ããæ©èœåŒ·åãå ¥ã£ãŠããããã§ãã
- å€æ°ãåç §ããŠãtest providerãããã¯ã§åºåãå®è¡ãã
- variableããã³providerãããã¯ã§HCLé¢æ°ã䜿ã
- ãã¹ãã«é¢ããå€ã
*.tfvars
ãã¡ã€ã«ããããŒããã
ãã¹ãã«é¢ããããã°ã¯ãã¡ãã
ä»åã¯ãã¢ãã¯ã«ã€ããŠèŠãŠãããŸãã
ç°å¢
ä»åã®ç°å¢ã¯ãã¡ãã
$ terraform version Terraform v1.7.2 on linux_amd64
ãã¹ã察象ã®ãªãœãŒã¹äœæã¯ãLocalStackã䜿ãããšã«ããŸãã
$ python3 --version Python 3.10.12 $ localstack --version 3.1.0
èµ·åã
$ localstack start
äžéšãAWS CLIã䜿ããŸãã
$ aws --version aws-cli/2.15.17 Python/3.11.6 Linux/5.15.0-92-generic exe/x86_64.ubuntu.22 prompt/off
TerraformãªãœãŒã¹å®çŸ©
ãã¹ããããã«ããTerraformã§æ§ç¯ãããªãœãŒã¹ã®å®çŸ©ããªããšå§ãŸããŸããã
ä»åã¯ãã¢ãã¯ãããã€ããŒãšãªãŒããŒã©ã€ãã®äž¡æ¹ã§è©ŠãããšæããŸããããªãœãŒã¹ã®å®çŸ©èªäœã¯åããã®ã䜿ãããšã«ããŸããã
versions.tf
terraform { required_version = "1.7.2" required_providers { aws = { source = "hashicorp/aws" version = "5.35.0" } } }
main.tf
provider "aws" { access_key = "mock_access_key" region = "us-east-1" s3_use_path_style = true secret_key = "mock_secret_key" skip_credentials_validation = true skip_metadata_api_check = true skip_requesting_account_id = true endpoints { apigateway = "http://localhost:4566" cloudformation = "http://localhost:4566" cloudwatch = "http://localhost:4566" dynamodb = "http://localhost:4566" es = "http://localhost:4566" firehose = "http://localhost:4566" iam = "http://localhost:4566" kinesis = "http://localhost:4566" lambda = "http://localhost:4566" route53 = "http://localhost:4566" redshift = "http://localhost:4566" s3 = "http://localhost:4566" secretsmanager = "http://localhost:4566" ses = "http://localhost:4566" sns = "http://localhost:4566" sqs = "http://localhost:4566" ssm = "http://localhost:4566" stepfunctions = "http://localhost:4566" sts = "http://localhost:4566" } } resource "aws_s3_bucket" "this" { bucket = var.bucket_name } resource "aws_s3_object" "this" { bucket = aws_s3_bucket.this.bucket key = var.content_key content = var.content_value }
äœæããã®ã¯Amazon S3ãã±ãããšããã±ããå ã«äœæããã³ã³ãã³ãã§ãã
resource "aws_s3_bucket" "this" { bucket = var.bucket_name } resource "aws_s3_object" "this" { bucket = aws_s3_bucket.this.bucket key = var.content_key content = var.content_value }
variables.tf
variable "bucket_name" { type = string } variable "content_key" { type = string default = "test.txt" } variable "content_value" { type = string default = "Hello World" }
å ¥åå€æ°ã¯ããã±ããåã ãã§è¯ãã£ãæ°ãããŸãâŠã
outputs.tf
output "bucket_name" { value = aws_s3_bucket.this.bucket } output "bucket_arn" { value = aws_s3_bucket.this.arn } output "object_key" { value = aws_s3_object.this.key } output "object_content_type" { value = aws_s3_object.this.content_type }
outputã¯ã¡ãã£ãšãããšãããã§ãããã¢ãã¯ã®ç¢ºèªã§äœ¿ã£ãŠãããŸãã
ãŸãã¯ããã§ãªãœãŒã¹ãæ§ç¯ã§ããããšã確èªããŸãããã
$ terraform init $ terraform plan -var 'bucket_name=my-bucket' $ terraform apply -var 'bucket_name=my-bucket'
çµæã
Apply complete! Resources: 2 added, 0 changed, 0 destroyed. Outputs: bucket_arn = "arn:aws:s3:::my-bucket" bucket_name = "my-bucket" object_content_type = "application/octet-stream" object_key = "test.txt"
ãªãœãŒã¹ãæ§ç¯ãããããšã確èªããŸãã
$ aws --endpoint-url http://localhost:4566 s3 ls 2024-02-04 20:49:10 my-bucket $ aws --endpoint-url http://localhost:4566 s3 ls my-bucket/ 2024-02-04 20:49:10 11 test.txt $ aws --endpoint-url http://localhost:4566 s3 cp s3://my-bucket/test.txt - Hello World
OKã§ããã
確èªã§ãããããªãœãŒã¹ãç Žæ£ããŠãããŸãã
$ terraform destroy -var 'bucket_name=my-bucket'
ã¢ãã¯ãããã€ããŒã䜿ã
ã§ã¯ããŸãã¯ã¢ãã¯ãããã€ããŒã䜿ããšããããå§ããŠãããŸãã
æåã«ããŒã¹ã«ãªããã¹ããæžããŸãããã
tests/create_s3_bucket.tftest.hcl
run "create_bucket" { variables { bucket_name = "my-bucket" } assert { condition = aws_s3_bucket.this.bucket == "my-bucket" error_message = "S3 bucket name did not match expected" } assert { condition = aws_s3_object.this.key == "test.txt" error_message = "content key did not match expected" } }
tests/create_s3_bucket_outputs.tftest.hcl
run "create_bucket_assert_output" { variables { bucket_name = "my-bucket" } assert { condition = output.bucket_name == "my-bucket" error_message = "S3 bucket name did not match expected" } assert { condition = output.bucket_arn == "arn:aws:s3:::my-bucket" error_message = "S3 arn did not match expected" } assert { condition = output.object_key == "test.txt" error_message = "content key did not match expected" } assert { condition = output.object_content_type == "application/octet-stream" error_message = "content type did not match expected" } }
確èªã
$ terraform test
ãã¹ããéããŸããã
Success! 2 passed, 0 failed.
ããã§ã¯ããã®ãã¹ãã«ã¢ãã¯ãããã€ããŒãå°å ¥ããŠã¿ãŸãã
ã¢ãã¯ãããã€ããŒã¯ããããã€ããŒèªäœãã¢ãã¯ã«ããŸãã
In Terraform tests, you can mock a provider with the mock_provider block.
ã¢ãã¯ãããã€ããŒã䜿çšããŠæ§ç¯ããããªãœãŒã¹ããã³ããŒã¿ãœãŒã¹ã¯ããã¹ãŠã¢ãã¯ã«ãªããŸãã
All resources and data sources retrieved by a mock provider will set the relevant values from the configuration, and generate fake data for any computed attributes.
æå°æ§æãšããŠã¯ããã¹ãå
ã«mock_provider
ãå®çŸ©ããŸãã
tests/create_s3_bucket.tftest.hcl
mock_provider "aws" {} run "create_bucket" { variables { bucket_name = "my-bucket" } ãçç¥ã
tests/create_s3_bucket_outputs.tftest.hcl
mock_provider "aws" {} run "create_bucket_assert_output" { variables { bucket_name = "my-bucket" } ãçç¥ã
ããã§AWSãããã€ããŒãã¢ãã¯ã«ãªããŸããã
ã§ã¯ãã¹ãããŠã¿ãŸãã
$ terraform test
ãããšãoutputãèŠãŠãããã¹ãã倱æããŸãã
tests/create_s3_bucket.tftest.hcl... in progress run "create_bucket"... pass tests/create_s3_bucket.tftest.hcl... tearing down tests/create_s3_bucket.tftest.hcl... pass tests/create_s3_bucket_outputs.tftest.hcl... in progress run "create_bucket_assert_output"... fail â· â Error: Test assertion failed â â on tests/create_s3_bucket_outputs.tftest.hcl line 14, in run "create_bucket_assert_output": â 14: condition = output.bucket_arn == "arn:aws:s3:::my-bucket" â âââââââââââââââââ â â output.bucket_arn is "mcjyansb" â â S3 arn did not match expected âµ â· â Error: Test assertion failed â â on tests/create_s3_bucket_outputs.tftest.hcl line 24, in run "create_bucket_assert_output": â 24: condition = output.object_content_type == "application/octet-stream" â âââââââââââââââââ â â output.object_content_type is "0z6b8a56" â â content type did not match expected âµ tests/create_s3_bucket_outputs.tftest.hcl... tearing down tests/create_s3_bucket_outputs.tftest.hcl... fail Failure! 1 passed, 1 failed.
ããã¯ãã¢ãã¯ãããã€ããŒããçæããããªãœãŒã¹ã®å€ãšãã¹ãã®æåŸ å€ãåããªãããã§ããã
ã¢ãã¯ãããã€ããŒã«ãããªãœãŒã¹ãããŒã¿ãœãŒã¹ã¯ãå€ãæå®ããªãéã以äžã®ã«ãŒã«ã§èªåçã«å€ãçæããããã§ãã
- numberåã®å Žåã¯0
- booleanåã®å Žåã¯false
- stringåã®å Žåã¯8æåã®ã©ã³ãã æååïŒã¢ã«ãã¡ããããšæ°åïŒ
- setãlistãmapãå«ãã³ã¬ã¯ã·ã§ã³ã®å Žåã空ã®ã³ã¬ã¯ã·ã§ã³
- objectåã®å Žåã¯ãäžèšã«ãŒã«ã«åŸã£ãŠã¡ã³ããŒã®å€ãèšå®ãã
Mocks / Mock Providers / Generated data
ã§ã¯ãã¢ãã¯ãããã€ããŒãçæãããªãœãŒã¹ã®å€ãæå®ããã°ããããšããããšã§ä»¥äžã®ããã«mock_resource
ã§åãªãœãŒã¹ã®
å±æ§ãã©ã®ãããªå€ãè¿ãã®ããæå®ããŸãã
tests/create_s3_bucket_outputs.tftest.hcl
mock_provider "aws" { mock_resource "aws_s3_bucket" { defaults = { arn = "arn:aws:s3:::my-bucket" } } mock_resource "aws_s3_object" { defaults = { content_type = "application/octet-stream" } } } run "create_bucket_assert_output" { variables { bucket_name = "my-bucket" } ãçç¥ã
ããã§ãåãªãœãŒã¹ã«å¯ŸããŠããã©ã«ãå€ãšããŠã©ã®ãããªå€ãè¿ãã®ãèšå®ã§ããŸããã
ããã§ãã¹ããéãããã«ãªããŸãã
$ terraform test tests/create_s3_bucket.tftest.hcl... in progress run "create_bucket"... pass tests/create_s3_bucket.tftest.hcl... tearing down tests/create_s3_bucket.tftest.hcl... pass tests/create_s3_bucket_outputs.tftest.hcl... in progress run "create_bucket_assert_output"... pass tests/create_s3_bucket_outputs.tftest.hcl... tearing down tests/create_s3_bucket_outputs.tftest.hcl... pass Success! 2 passed, 0 failed.
ã¡ãªã¿ã«ãå®è¡é床ãšããŠã¯ã¢ãã¯ãªã®ã§ãšãŠãé«éã«ãªããŸãã
ã¢ãã¯ãããã€ããŒã®äœ¿ãæ¹ã¯åºæ¬çã«ã¯ãããªæãã§ãããŒã¿ãœãŒã¹ã䜿ã£ãŠãåãã§ããã
ãŸããã¢ãã¯å ã§å®çŸ©ããã¢ãã¯ãªãœãŒã¹ãã¢ãã¯ããŒã¿ãœãŒã¹ã®å®çŸ©ã¯ä»¥äžã®ããã«ã¢ãžã¥ãŒã«ãšããŠãå ±æå¯èœãªããã§ãã
mock_provider "aws" { source = "./testing/aws" }
泚æç¹ãšããŠã¯ãmock_provider
ã¯ãããã¬ãã«ã§ããæžããªãïŒprovider
ãšåãïŒãªã®ã§ãHCLãã¡ã€ã«å
ã§æžãããåãã¹ãã§
ã¢ãã¯ãããã€ããŒã®é©çšæç¡ãåãæ¿ããããšã¯ã§ããŸããã
ãã®å Žåã¯ããã¹ããã¡ã€ã«èªäœãåããå¿
èŠããããŸãã
ãŸããèŠãŠã®ãšããã¢ãã¯ã®ãªãœãŒã¹ãããŒã¿ãœãŒã¹ãã©ã®ãããªå€ãæå®ãããã¯æ±ºããããŸãããåãçš®é¡ã®ãªãœãŒã¹ãããŒã¿ãœãŒã¹ã
è€æ°ãã£ãŠãç»äžçãªå€ãè¿ãããšã«ãªããŸãã
ããããªããšããããã£ããããªãŒããŒã©ã€ãã䜿ãã®ããªãšæããŸãã
ãªãŒããŒã©ã€ã
ããã²ãšã€ã®ããŒãããªãŒããŒã©ã€ãã§ãã
In addition to mocking providers, you can use the following block types to override specific resources, data sources, and modules:
ãã®æ©èœã§ã¯ããªãœãŒã¹ãããŒã¿ãœãŒã¹ãã¢ãžã¥ãŒã«ããªãŒããŒã©ã€ãããŠã¢ãã¯ã«ã§ããŸãã
ãªãŒããŒã©ã€ãããç®æã«ã€ããŠã¯ãTerraformã¯å
ã«ãªã£ããããã€ããŒã®åŒã³åºããè¡ããããªãŒããŒã©ã€ãã®å®çŸ©ã«åŸãããã«
ãªããŸãã
ããã¥ã¡ã³ããèŠãŠãããšèª€è§£ããããæ°ãããŸããããã®æ©èœèªäœã¯ã¢ãã¯ãããã€ããŒãšã¯ç¬ç«ãããã®ã«ãªã£ãŠããŸãã
ããã¥ã¡ã³ãã®äŸãåžžã«ã¢ãã¯ãããã€ããŒãšçµã¿åãããŠããã®ã§ã¡ãã£ãšæ··ä¹±ããŸããããç¬ç«ããŠäœ¿ããæ©èœã§ãã
ãŸããrun
ãããã¯å
ã§äœ¿çšããããšãã§ããŸãã
ããã€ãããªãšãŒã·ã§ã³ãèŠãŠãã£ãŠã¿ãŸãã
ãŸãã¯ç¹å®ã®ãªãœãŒã¹ã®ã¿ããªãŒããŒã©ã€ããããã¿ãŒã³ãã¢ãã¯ãããã€ããŒã¯äœ¿çšããŠããŸããã
tests/create_s3_bucket_outputs.tftest.hcl
override_resource { target = aws_s3_object.this values = { content_type = "application/octet-stream" } } run "create_bucket_assert_output" { variables { bucket_name = "my-bucket" } assert { condition = output.bucket_name == "my-bucket" error_message = "S3 bucket name did not match expected" } assert { condition = output.bucket_arn == "arn:aws:s3:::my-bucket" error_message = "S3 arn did not match expected" } assert { condition = output.object_key == "test.txt" error_message = "content key did not match expected" } assert { condition = output.object_content_type == "application/octet-stream" error_message = "content type did not match expected" } }
ãªãŒããŒã©ã€ãã§ã¯ã察象ãšãªããªãœãŒã¹ãããŒã¿ãœãŒã¹ãã¢ãžã¥ãŒã«ãtarget
ã§åã
ã«æå®ããŸãã
override_resource { target = aws_s3_object.this values = { content_type = "application/octet-stream" } }
ãã®äŸã§ã¯ãAmazon S3ãã±ããã¯æ¬ç©ã®AWSãããã€ããŒã«ãã£ãŠäœæãããŸããããã±ããå
ã«é
眮ãããªããžã§ã¯ãã ãã
ã¢ãã¯ã«ãªã£ããšããããšã«ãªããŸããã
次ã¯Amazon S3ãã±ããããªããžã§ã¯ãããªãŒããŒã©ã€ãã§ã¢ãã¯ã«ããŸãã
tests/create_s3_bucket_outputs2.tftest.hcl
override_resource { target = aws_s3_bucket.this values = { arn = "arn:aws:s3:::test-bucket" } } override_resource { target = aws_s3_object.this values = { content_type = "application/octet-stream" } } run "create_bucket_assert_output" { variables { bucket_name = "my-bucket" } assert { condition = output.bucket_name == "my-bucket" error_message = "S3 bucket name did not match expected" } assert { condition = output.bucket_arn == "arn:aws:s3:::test-bucket" error_message = "S3 arn did not match expected" } assert { condition = output.object_key == "test.txt" error_message = "content key did not match expected" } assert { condition = output.object_content_type == "application/octet-stream" error_message = "content type did not match expected" } }
ã¡ãã£ãšãããšãããã§ãããvariableã§æå®ãããã±ããåãç¡èŠããarnãèšå®ããããã«ããŸããã
override_resource { target = aws_s3_bucket.this values = { arn = "arn:aws:s3:::test-bucket" } }
ãã¹ãã³ãŒããèŠããšãAmazon S3ãã±ããåŽãã¢ãã¯ã«ãªã£ãŠããããšãããããŸãã
assert { condition = output.bucket_name == "my-bucket" error_message = "S3 bucket name did not match expected" } assert { condition = output.bucket_arn == "arn:aws:s3:::test-bucket" error_message = "S3 arn did not match expected" }
ä»å䜿çšããŠãããªãœãŒã¹ã¯ãaws_s3_bucket
ãšaws_s3_object
ãªã®ã§ãçµæçã«ã¯ãã¹ãŠãã¢ãã¯ã«ããããšã«ãªããŸãã
AWSãããã€ããŒèªäœã¯äœ¿ã£ãŠããŸãããããã䜿ã£ãŠäœæããããªãœãŒã¹ã¯ãªãã§ããããã ãAWSãããã€ããŒãAWSïŒä»åã¯
LocalStackã§ããïŒã«æ¥ç¶ããåŠçãªã©ã¯ãã®ãŸãŸãªã®ã§ãã¢ãã¯ãããã€ããŒã䜿ã£ãæã«æ¯ã¹ããšé床差ã¯ãããªãã«ãããŸãã
æåŸã¯ãã¢ãã¯ãããã€ããŒãšã®çµã¿åããã§ãã
tests/create_s3_bucket_outputs3.tftest.hcl
mock_provider "aws" { mock_resource "aws_s3_bucket" { defaults = { arn = "arn:aws:s3:::xxxxx" } } override_resource { target = aws_s3_bucket.this values = { arn = "arn:aws:s3:::my-bucket" } } override_resource { target = aws_s3_object.this values = { content_type = "application/octet-stream" } } } run "create_bucket_assert_output" { variables { bucket_name = "my-bucket" } assert { condition = output.bucket_name == "my-bucket" error_message = "S3 bucket name did not match expected" } assert { condition = output.bucket_arn == "arn:aws:s3:::my-bucket" error_message = "S3 arn did not match expected" } assert { condition = output.object_key == "test.txt" error_message = "content key did not match expected" } assert { condition = output.object_content_type == "application/octet-stream" error_message = "content type did not match expected" } }
AWSãããã€ããŒãã¢ãã¯ãããã€ããŒã«å·®ãæ¿ããaws_s3_bucket
ãªãœãŒã¹å
šäœã«å¯ŸããŠããã©ã«ãã®æ¯ãèããèšå®ãã€ã€ã
ç¹å®ã®aws_s3_bucket
ããã³aws_s3_object
ãªãœãŒã¹ã«ã€ããŠã¯ãªãŒããŒã©ã€ããããšããèšå®ã«ããŠããŸãã
mock_provider "aws" { mock_resource "aws_s3_bucket" { defaults = { arn = "arn:aws:s3:::xxxxx" } } override_resource { target = aws_s3_bucket.this values = { arn = "arn:aws:s3:::my-bucket" } } override_resource { target = aws_s3_object.this values = { content_type = "application/octet-stream" } } }
ãªãŒããŒã©ã€ãã®èšå®ã¯ãrun
å
ã«æžããŠãããã§ããã
ãã®ãã¿ãŒã³ã¯ãã¡ãã
tests/create_s3_bucket_outputs4.tftest.hcl
mock_provider "aws" { mock_resource "aws_s3_bucket" { defaults = { arn = "arn:aws:s3:::xxxxx" } } } run "create_bucket_assert_output" { variables { bucket_name = "my-bucket" } override_resource { target = aws_s3_bucket.this values = { arn = "arn:aws:s3:::my-bucket" } } override_resource { target = aws_s3_object.this values = { content_type = "application/octet-stream" } } assert { condition = output.bucket_name == "my-bucket" error_message = "S3 bucket name did not match expected" } assert { condition = output.bucket_arn == "arn:aws:s3:::my-bucket" error_message = "S3 arn did not match expected" } assert { condition = output.object_key == "test.txt" error_message = "content key did not match expected" } assert { condition = output.object_content_type == "application/octet-stream" error_message = "content type did not match expected" } }
ä»åã¯æ±ããŸããããã¢ãžã¥ãŒã«ã®å Žåã¯ãããªæãã®ãªãŒããŒã©ã€ãã«ãªãããã§ãã
override_module { target = module.credentials outputs = { data = { username = "username", password = "password" } } }
ããã§ã¢ãã¯ãããã€ããŒãšã¯éã£ãŠãç¹å®ã®ãªãœãŒã¹ãããŒã¿ãœãŒã¹ã«å¯ŸããŠåºæã®æ¯ãèããæå®ã§ãããããã«æããŸãã
ç¹°ãè¿ãããã¹ããããã®å¯ŸããŠã¯æ³šæãå¿
èŠã§ãã
Mocks / Repeated blocks and nested attributes
ãããã£ããã®ïŒreplica
å
ã«region
ããã¹ãããŠããããªãœãŒã¹å®çŸ©å
ã«2åç»å ŽããïŒã«ãããããç°ãªãå€ãæå®ããããšã
ã§ããŸãããæå®ããå Žåã¯ãããããã«åãå€ãèšå®ãããããšã«ãªããŸãã
resource "aws_dynamodb_table" "my_table" { name = "my_table" hash_key = "key" attribute { name = "key" type = "S" } replica { region_name = "eu-west-2" } replica { region_name = "us-east-1" } }
ç¹°ãè¿ãæ§æã䜿ã£ãŠäœæãããªãœãŒã¹ãªã©ã«ããåãããšãèšããŸãã
ãããã«
Terraform 1.7ã§è¿œå ãããã¢ãã¯ã®æ©èœãè©ŠããŠã¿ãŸããã
ããã°ãšã³ããªãŒãããã¥ã¡ã³ããèŠãŠããéã¯ã¡ãã£ãšãã³ãšæ¥ãªãïŒç¹ã«ãªãŒããŒã©ã€ãïŒãšããããã£ãã®ã§ãããå®éã«
åãããŠã¿ããã ãã¶ã€ã¡ãŒãžã€ããŸããã
䟿å©ã¯äŸ¿å©ãªã®ã§ãããã¢ãã¯ã«ãããããšãªã«ããã¹ãããŠããã®ãããããªããªã£ãŠããã®ã¯éåžžã®ããã°ã©ãã³ã°èšèªã®
ãã¹ãã«ãããã¢ãã¯ãšåãã§ãããšãããããããã€ããŒã®è£ã«ã¯ã¯ã©ãŠãã®APIããããããããã§ããã®çµæãèžãŸãã
ãªãœãŒã¹ã®outputãèšå®ããã«ã¯âŠïŒãšèããããããšãããæå³ãã£ãšå€§å€ã§ã¢ãã¯ã«ã©ã®ãããªå€ãèšå®ããã®ãã
確èªããã®ãäžèŠåŽãšããæããããŸãã
䜿ããšããã¯èããŠããããã§ããã