OpenStack SwiftでS3 APIを有効化して、Terraform S3 backendとして利用する

タイトルママですが、若干手間取ったのでメモとして残しておきます。

swift-proxyの設定

`swift-proxy` サーバのコンフィグに `s3api` と `s3token` が `authtoken` と `keystoneauth` に挟まれるような形で追加します。

[pipeline:main]
pipeline = catch_errors gatekeeper healthcheck proxy-logging cache container_sync bulk ratelimit authtoken s3api s3token keystoneauth container-quotas account-quotas slo dlo versioned_writes proxy-logging proxy-server

`[filter:s3api]` セクションでお好みに `location` (regionに該当)を修正します。

[filter:s3api]
location = nova

`[filter:s3token]` セクションで keystone auth url を自分の環境に合わせます。

[filter:s3token]
auth_uri = https://<keystoneのhostname>/v3

ここまで設定したら `swift-proxy` サーバを再起動します。

aws profileの設定

`awscli` と `awscli-plugin-endpoint` の pipでインストール

pip install awscli awscli-plugin-endpoint

`~/.aws/config` を以下のように設定します

[plugins]
endpoint = awscli_plugin_endpoint

[profile openstack]
region = <locationで設定した値>
s3 =
  endpoint_url = https://<swiftのhostname>
s3api =
  endpoint_url = https://<swiftのhostname>

`openstack ec2 credentials create` コマンドでaccess key idと secret access keyを発行します。 

openstack ec2 credentials create
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
| Field      | Value                                                                                                                                         |
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
| access     | <access key id>                                                                                                              |
| links      | {'self': 'https://<keystone hostname>/v3/users/xxxxx/credentials/OS-EC2/xxxxx'} |
| project_id | xxxxx                                                                                                              |
| secret     | <secret access key>                                                                                                              |
| trust_id   | None                                                                                                                                          |
| user_id    | xxxxx                                                                                                              |
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------+

ここまでくると、 `aws s3 ls` を叩けるようになっているはず。

aws s3 ls --profile openstack

2009-02-04 01:45:09 registry
2009-02-04 01:45:09 volumebackups

Terraformバックエンドの設定

あとは、Terraformバックエンドの設定方法は以下の通り。

terraform {
  backend "s3" {
    bucket = "<tfstate保存用コンテナ名>"
    key = "<実際のtfstateファイルのキー>"
    endpoints = {
      s3 = "https://<swiftのhostname>/"
    }
    region = "<locationで設定した値>"
    profile = "openstack"
    skip_credentials_validation = true
    skip_region_validation      = true
    skip_requesting_account_id  = true
    skip_metadata_api_check     = true
    skip_s3_checksum            = true
    use_path_style = true
  }
}

この記事が気に入ったらサポートをしてみませんか?