TerraformのState FileをOracle Cloud Infrastructure Object Storageに入れる
はじめに
下記をなぞったときのメモです。
青色の文字のところはコメントです。
Object Store Backend - Terraform by HashiCorp
Using the Object Store for Terraform State Files
概要
BackendにState Fileを配置するアプローチとしては下記の2つが利用できる。
- Using an HTTP remote state backend
- Using an S3-compatible remote state backend
- S3互換の方法
※事前承認済みリクエストについて
重要 バケットまたはオブジェクトへの事前認証済アクセスのビジネス要件およびセキュリティの影響を評価します。 事前認証済リクエストURLは、URLを持っているユーザーに、リクエストで特定されたターゲットへのアクセスを提供します。URLの配布は慎重に管理してください。
上記の記載があるので、セキュリティの観点から今回はS3互換方式で検証しました。
環境
$ terraform -version Terraform v0.12.26 + provider.oci v3.87.0
Using an S3-compatible remote state backend
S3互換API Keyの作成
Keyの配置
下記のようなCredential Fileを~/.aws/credentials
に配置。
[default] aws_access_key_id=<id> aws_secret_access_key=<key>
Terraformの設定
terraform { backend "s3" { bucket = "terraform-state" key = "terraform.tfstate" region = "ap-tokyo-1" endpoint = "https://<Namespace名>.compat.objectstorage.ap-tokyo-1.oraclecloud.com" skip_region_validation = true skip_credentials_validation = true skip_requesting_account_id = true skip_get_ec2_platforms = true skip_metadata_api_check = true force_path_style = true } }
上記のskip_get_ec2_platforms
とskip_requesting_account_id
はDeprecatedだと警告が出ますが、いったん無視して実行。
疎通
OCI Object Storageに格納されていることが確認できました。
現状の制約や課題
S3互換Backendの場合はTerragruntのようなツールの利用はむずかしそうです。