terraform ステートを強制スキップする

遭遇したエラー Error: reading Secrets Manager Secret (arn:aws:secretsmanager:ap-northeast-1:xxxxxxxxxxxx:secret:sample-secret-xxxxxx): couldn't find resource 環境構築時、デプロイ中にいきなりTokenの有効期限切れエラーが発生した。 terraformのステート管理はS3に保存している。 99designs/aws-vault を使ってローカルでシークレット管理していたら急に.. ここの原因はわかってないけど、デプロイ中でしかもステート保存失敗のエラーが出たので、完全に状態がおかしくなった。 rdb接続情報のSecret保存部分でエラー 幸い新規構築中だったので、一度 destroy してから再度作成しようとしていた。 このタイミングで上記エラーが発生しだした。 コンソールから削除しても、refresh しても何してもだめなので、ステータスが壊れたのだと思う。 まずは、削除する上でもリソースのスキップが必要 下記内容で強制スキップし、リソースは手動削除するなどして、削除完了できた。 terraform で持っている状態の一覧 $ terraform state list : (省略) module.db.aws_secretsmanager_secret.sample : (省略) 調べたステート名を指定して削除 $ terraform state rm module.db.aws_secretsmanager_secret.sample

2023-05-08 ·  2023-05-08 · 1 分 · 41 文字

The bucket does not allow ACLs エラーに出くわしたので調べる

Bucket作成時のACLエラー Terraform で環境構築時に下記エラーが発生 ACL周りのデフォルト動作が変更となったようなので、少しメモ Error: error creating S3 bucket ACL for sample-bucket: AccessControlListNotSupported: The bucket does not allow ACLs status code: 400, request id: xxxxxxxxxxxxxxxx, host id: xxxxxxxxxxxxxxxxxxxxxxxxxxx+xxxxxxxxxxxxxxxxx/xxxxxxx/xxxxxxxxxxxxxxxxxxxxxx with module.s3.aws_s3_bucket_acl.sample, on ../../module_aws/s3/main.tf line 13, in resource "aws_s3_bucket_acl" "sample": 13: resource "aws_s3_bucket_acl" "sample" { S3作成時のデフォルトの設定の変更 2023年4月より新規S3バケットは、デフォルトでパブリック・アクセスブロック有効化、ACL無効化 ACLは利用しないことが推奨される s3オブジェクトのACL有効・無効設定は aws_s3_bucket_ownership_controls で設定する resource "aws_s3_bucket_ownership_controls" "sample" { bucket = aws_s3_bucket.sample.bucket rule { object_ownership = "BucketOwnerEnforced" } } object_ownership に設定できるのは以下 ObjectWriter: 所有者はアップローダ BucketOwnerPreferred: バケット所有アカウントを指定可能(bucket-owner-full-control) BucketOwnerEnforced: バケット所有アカウント強制 BucketOwnerEnforced ではACL併用できない S3 ポリシー適用時のエラー S3 policy: AccessDenied: Access Denied 一部ディレクトリのみ公開したい場合など、ACLを指定する場合は、ObjectWriter & ACL設定 & ポリシーにはアカウントを指定する...

2023-05-08 ·  2023-09-22 · 1 分 · 107 文字

Serverless で ApiGw のロギングいれようとして、`CloudWatch Logs role ARN must be set in account settings to enable logging` となったのでメモ

問題 Serverless Framework で、以下のようにロギング設定を追加して、以下エラーになった provider: # 省略 logs: restApi: accessLogging: false # Optional configuration which enables or disables access logging. Defaults to true. executionLogging: true # Optional configuration which enables or disables execution logging. Defaults to true. level: ERROR # Optional configuration which specifies the log level to use for execution logging. May be set to either INFO or ERROR. fullExecutionData: false # Optional configuration which specifies whether or not to log full requests/responses for execution logging....

2023-02-13 ·  2023-04-24 · 1 分 · 130 文字

firebase-admin で使用する秘密鍵を SecretManager に登録する

FCM Push用秘密鍵を SecretManager に登録する FCM 秘密鍵を取得 FireBaseへログイン プロジェクトを選択 プロジェクトの設定 サービスアカウント FireBase Admin SDK > 新しい秘密鍵の生成 FCM 秘密鍵を SecretManager に登録 取得した秘密鍵を ./fcm.json で配置する 以下コマンドで登録 aws secretsmanager put-secret-value --secret-id ${SECRET_ID} --secret-string "$(cat<./fcm.json)" 使う SecretManager を扱い易いようにクラス化する 'use strict'; const { SecretsManagerClient, GetSecretValueCommand } = require('@aws-sdk/client-secrets-manager'); const clazz = class Sm { constructor() { this.client = new SecretsManagerClient({ region: process.env.REGION }); // REGION で環境変数へRegionを設定している前提 } async get(key) { const command = new GetSecretValueCommand({ SecretId: key }); const res = await this....

2023-02-13 ·  2023-04-23 · 1 分 · 170 文字

アクセス制限ポリシーを当てたRoleへスイッチできるユーザをaws cli で作成する

案件で作る機会があったので、さっと IAM.yml AWSTemplateFormatVersion: "2010-09-09" Description: "SampleApp - IAM" Parameters: ProjectName: Description: "Project name" Type: "String" Default: "SampleApp" Resources: IamSampleDeveloperRole: Type: AWS::IAM::Role Properties: RoleName: !Sub ${ProjectName}SampleDeveloper AssumeRolePolicyDocument: Version: 2012-10-17 Statement: - Effect: Allow Principal: AWS: !Sub arn:aws:iam::${AWS::AccountId}:root Action: sts:AssumeRole ManagedPolicyArns: - arn:aws:iam::aws:policy/CloudWatchReadOnlyAccess IamSampleDeveloperPolicies: Type: AWS::IAM::Policy Properties: PolicyName: IamSampleDeveloperPolicy PolicyDocument: Version: 2012-10-17 Statement: - Effect: Allow Action: - dynamodb:List* - dynamodb:DescribeReservedCapacity* - dynamodb:DescribeLimits - dynamodb:DescribeTimeToLive Resource: '*' - Effect: Allow Action: - dynamodb:BatchGet* - dynamodb:DescribeStream - dynamodb:DescribeTable - dynamodb:Get* - dynamodb:Query - dynamodb:Scan - dynamodb:BatchWrite* - dynamodb:CreateTable - dynamodb:Delete* - dynamodb:Update* - dynamodb:PutItem Resource: - arn:aws:dynamodb:*:*:table/dev-* - Effect: Allow Action: - s3:ListAllMyBuckets Resource: - arn:aws:s3:::* - Effect: Allow Action: - s3:* Resource: - arn:aws:s3:::*dev* Roles: - Ref: IamSampleDeveloperRole IamSampleDevelopersGroup: Type: AWS::IAM::Group Properties: GroupName: !...

2023-01-06 ·  2023-01-06 · 1 分 · 210 文字