質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Terraform

Terraformは、インフラ構築のためのツールです。AWS/DigitalOcean/GoogleCloudといった様々なインフラに対応。インフラ構成のコード管理や変更の作業などの手間を自動化し、インフラ構築の効率化を図ることができます。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

Q&A

2回答

3824閲覧

TerraformでのAWS IAMユーザー "iam_user_login_profile" pgpkey 設定方法について

NakamuraSystems

総合スコア0

Terraform

Terraformは、インフラ構築のためのツールです。AWS/DigitalOcean/GoogleCloudといった様々なインフラに対応。インフラ構成のコード管理や変更の作業などの手間を自動化し、インフラ構築の効率化を図ることができます。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

0グッド

1クリップ

投稿2021/10/31 02:35

前提・実現したいこと

TerraformでIAMユーザーの作成を実装しており、以下の実現をしたいです。

  • IAMユーザーの作成
  • 初期パスワードの作成
  • 初回ログイン時、パスワード強制リセット有効
  • 当該ユーザーによるパスワード変更の許可

公式ドキュメントを参考に、aws_iam_user_login_profileを実装してますが、エラーが出力され、IAMユーザーのパスワード作成に失敗します。

パスワード付きIAMユーザーの作成ができればと思っています。
解消方法を教えていただきたいです。

  • リソースファイル
- .terraform - iam_user.tf - main.tf - variables.tf - version.tf - terraform.tfstate - cert(ディレクトリ) - iam_test.public.gpg

エラーメッセージ

Error: error encrypting password during IAM User Login Profile (iam_test.test_operator) creation: Error encrypting Password: error parsing given PGP key: openpgp: unsupported feature: unsupported oid: 2b060104019755010501 on iam_user.tf line 21, in resource "aws_iam_user_login_profile" "iam_test_login_profile": 21: resource "aws_iam_user_login_profile" "iam_test_login_profile" { Error: error encrypting password during IAM User Login Profile (iam_test.test_admin) creation: Error encrypting Password: error parsing given PGP key: openpgp: unsupported feature: unsupported oid: 2b060104019755010501 on iam_user.tf line 21, in resource "aws_iam_user_login_profile" "iam_test_login_profile": 21: resource "aws_iam_user_login_profile" "iam_test_login_profile" { Error: error encrypting password during IAM User Login Profile (iam_test.test_developer) creation: Error encrypting Password: error parsing given PGP key: openpgp: unsupported feature: unsupported oid: 2b060104019755010501 on iam_user.tf line 21, in resource "aws_iam_user_login_profile" "iam_test_login_profile": 21: resource "aws_iam_user_login_profile" "iam_test_login_profile" {

該当のソースコード

  • iam_user.tf
resource "aws_iam_user" "iam_test" { count = length(var.aws_iam_user) name = element(var.aws_iam_user, count.index) path = "/" force_destroy = true } resource "aws_iam_user_group_membership" "iam_test_group_membership" { count = length(var.aws_iam_group) user = element(var.aws_iam_user, count.index) groups = [ element(var.aws_iam_group, count.index), ] depends_on = [ aws_iam_user.iam_test ] } resource "aws_iam_user_login_profile" "iam_test_login_profile" { count = length(var.aws_iam_user) user = element(var.aws_iam_user, count.index) pgp_key = filebase64("./cert/iam_test.public.gpg") password_reset_required = true password_length = "20" } output "aws_iam_user_password" { value = aws_iam_user_login_profile.iam_test_login_profile.*.encrypted_password }
  • variables.tf
variable "aws_iam_user" { type = list(string) default = [ "iam_test.test_admin", "iam_test.test_developer", "iam_test.test_operator", ] } variable "aws_iam_group" { type = list(string) default = [ "iam_test_administrator", "iam_test_development", "iam_test_operators", ] }
  • main.tf
provider "aws" { access_key = "xxx" secret_key = "xxx" region = "ap-northeast-1" default_tags { tags = { env = "iam_test" } } }
  • version.tf
terraform { required_providers { aws = { source = "hashicorp/aws" version = ">= 3.24.0" } } required_version = ">= 0.14.0" }
  • terraform.tfstate
{ "version": 4, "terraform_version": "0.14.6", "serial": 281, "lineage": "xxx", "outputs": {}, "resources": [] }
  • cert/iam_test.public.gpg(公開鍵バイナリファイル)

試したこと

  • terraform plan時に特にエラーなし
  • terraform apply後、エラー出力される

補足情報(FW/ツールのバージョンなど)

$ tfenv version-name 0.14.6 $ terraform version Terraform v0.14.6 + provider registry.terraform.io/hashicorp/aws v3.63.0 Your version of Terraform is out of date! The latest version is 1.0.10. You can update by downloading from https://www.terraform.io/downloads.html

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

$ terraform version
Terraform v0.14.6

Terraformのバージョンが原因かと思い、質問者さんにバージョンを合わせてみましたが、apply成功しました。

lang

1$ terraform destroy # リソース削除 2... 3Destroy complete! Resources: 12 destroyed.

lang

1$ tfenv use 0.14.6 2Switching default version to v0.14.6 3Switching completed 4$ terraform --version 5Terraform v0.14.6 6+ provider registry.terraform.io/hashicorp/aws v3.63.0

lang

1$ terraform apply 2... 3Apply complete! Resources: 3 added, 0 changed, 0 destroyed. 4 5Outputs: 6 7aws_iam_user_password = [ 8 "wcDMA04...==", 9 "wcDMA04...==", 10 "wcDMA04...==", 11]

あとは原因として考えられるのは、iam_test.public.gpgぐらいでしょうか。

投稿2021/10/31 04:49

jhashimoto

総合スコア838

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

こちらで確認したところ、applyに成功しました。

確認した手順を載せておきます。

Terraformのversion。

lang

1terraform -version 2Terraform v1.0.3 3on linux_amd64 4+ provider registry.terraform.io/hashicorp/aws v3.63.0

GPG鍵の作成。途中でパスフレーズを2回入力。

lang

1$ gpg --gen-key 2Real name: iam-test 3Email address: hoge@example.com 4 5gpg -o ./iam_user.public.gpg --export iam_test 6gpg -o ./iam_user.private.gpg --export-secret-key iam_test 7mv ./iam_user.public.gpg ./iam_test.public.gpg # ファイル名を間違ったので修正

参考: アクセスキー有りのIAMユーザー作成 (Terraform) - Qiita

ソースコードはiam_user.tfだけ修正しました。aws_iam_group.iam_testを追加しています。他のファイルは提示されたままです。

lang

1// Add: グループ作成 2resource "aws_iam_group" "iam_test" { 3 count = length(var.aws_iam_group) 4 name = element(var.aws_iam_group, count.index) 5 path = "/" 6} 7 8resource "aws_iam_user" "iam_test" { 9 count = length(var.aws_iam_user) 10 name = element(var.aws_iam_user, count.index) 11 path = "/" 12 force_destroy = true 13} 14 15resource "aws_iam_user_group_membership" "iam_test_group_membership" { 16 count = length(var.aws_iam_group) 17 user = element(var.aws_iam_user, count.index) 18 19 groups = [ 20 element(var.aws_iam_group, count.index), 21 ] 22 depends_on = [ 23 // Mod: グループへの依存を追加 24 aws_iam_user.iam_test, aws_iam_group.iam_test 25 ] 26} 27 28resource "aws_iam_user_login_profile" "iam_test_login_profile" { 29 count = length(var.aws_iam_user) 30 user = element(var.aws_iam_user, count.index) 31 pgp_key = filebase64("./cert/iam_test.public.gpg") 32 password_reset_required = true 33 password_length = "20" 34} 35 36output "aws_iam_user_password" { 37 value = aws_iam_user_login_profile.iam_test_login_profile.*.encrypted_password 38}

apply。

尚、addedと実際のリソース数が一致していないのは、グループがなくエラーになったので、複数回applyしたためです。

lang

1Apply complete! Resources: 2 added, 0 changed, 0 destroyed. 2 3Outputs: 4 5aws_iam_user_password = [ 6 "wcDMA04...==", 7 "wcDMA04...==", 8 "wcDMA04...==", 9]

作成されたstate。

lang

1$ terraform state list 2aws_iam_group.iam_test[0] 3aws_iam_group.iam_test[1] 4aws_iam_group.iam_test[2] 5aws_iam_user.iam_test[0] 6aws_iam_user.iam_test[1] 7aws_iam_user.iam_test[2] 8aws_iam_user_group_membership.iam_test_group_membership[0] 9aws_iam_user_group_membership.iam_test_group_membership[1] 10aws_iam_user_group_membership.iam_test_group_membership[2] 11aws_iam_user_login_profile.iam_test_login_profile[0] 12aws_iam_user_login_profile.iam_test_login_profile[1] 13aws_iam_user_login_profile.iam_test_login_profile[2]

投稿2021/10/31 03:52

編集2021/11/02 03:43
jhashimoto

総合スコア838

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

NakamuraSystems

2021/11/01 13:26

ご回答ありがとうございます。 回答いただきました手順で試しましたが、未だ同じエラーがでてしまいます。 原因がまだわかっておりません。
NakamuraSystems

2021/11/01 13:27

またmacOSでGPGキー作成しておりますが、パスフレーズなしのGPGキーの作成ができず、それが原因の可能性もあるのかと思っています、、、 パスフレーズ入力画面にて何も入力せずエンターを押下しても永遠にパスフレーズの入力を求めらます。 どうしたらよいのか、、、
jhashimoto

2021/11/02 03:45

こちらでは、作成時にパスフレーズ入力したGPG鍵でapplyできています。回答に追記しました。
jhashimoto

2021/11/02 03:46

> GPG鍵の作成。途中でパスフレーズを2回入力。
jhashimoto

2021/11/02 12:43

同様の事象がありました。こちらのissueによると、ECC鍵ではエラーになるようです。 https://github.com/hashicorp/terraform-provider-aws/issues/15384 私がapplyに使った鍵は、RSA 3072で生成されていました。 ``` $ gpg --list-secret-keys --keyid-format=long /c/Users/xxxx/.gnupg/pubring.kbx ---------------------------------------------- sec rsa3072/xxxxxxxxxxxxxxxx 2021-10-31 [SC] [expires: 2023-10-31] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx uid [ultimate] iam_test <hoge@example.com> ssb rsa3072/xxxxxxxxxxxxxxxx 2021-10-31 [E] [expires: 2023-10-31] ``` 質問者さんの環境で、上のコマンドを試してみてもらえますか?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問