CodeBuild IAM terraform

iamポリシーのjsonをHCLで書き直すパズル集 #AWS - Qiita

https://docs.aws.amazon.com/ja_jp/codebuild/latest/userguide/auth-and-access-control-iam-identity-based-access-control.html#customer-managed-policies-example-create-vpc-network-interface

https://docs.aws.amazon.com/codebuild/latest/userguide/auth-and-access-control-iam-identity-based-access-control.html#customer-managed-policies-example-create-vpc-network-interface

data "aws_caller_identity" "current" {}

locals {
  region     = "ap-northeast-1"
  account_id = data.aws_caller_identity.current.account_id
}

resource "aws_subnet" "private_1a" {
...
}

resource "aws_subnet" "private_1c" {
...
}

data "aws_iam_policy_document" "codebuild_vpc" {
  statement {
    sid = ""
    actions = [
      "ec2:CreateNetworkInterface",
      "ec2:DescribeDhcpOptions",
      "ec2:DescribeNetworkInterfaces",
      "ec2:DeleteNetworkInterface",
      "ec2:DescribeSubnets",
      "ec2:DescribeSecurityGroups",
      "ec2:DescribeVpcs"
    ]
    effect = "Allow"
    resources = [
      "*"
    ]
  }

  statement {
    sid = ""
    actions = [
      "ec2:CreateNetworkInterfacePermission"
    ]
    effect = "Allow"
    resources = [
      "arn:aws:ec2:${local.region}:${local.account_id}:network-interface/*"
    ]
    condition {
      test = "StringEquals"
      values = [
        "${aws_subnet.private_1a.arn}",
        "${aws_subnet.private_1c.arn}"
      ]
      variable = "ec2:Subnet"
    }
    condition {
      test = "StringEquals"
      values = [
        "codebuild.amazonaws.com"
      ]
      variable = "ec2:AuthorizedService"
    }
  }
}

参考

CodeBuildでCloudformationを使ってIAMロールを作成する #CloudFormation - Qiita 2020

CloudFormationでCodeBuildを作成しようとしたら「Not authorized to perform DescribeSecurityGroups」になった #AWS - Qiita 2022

Terraform RDS証明書更新

つまり、最初にterraform applyを実行したときは「メンテナンスウィンドウを待って証明書の切り替えを実施する」という設定になってしまっていたことがわかります。

この引数をtrueに設定すると変更が即時反映される設定になるので、apply_immediately = trueを追加してリトライしてみます。
Terraformを使ってAurora Serverless v2(PostgreSQL)のSSL証明書を更新してみた | iret.media 2023

即時反映させる場合は apply_immediately = true

S3 AccessControlListNotSupported: The bucket does not allow ACLs

事前のお知らせ: 2023 年 4 月より、Amazon S3 で、すべての新しいバケットに対して自動的に S3 パブリックアクセスブロックが有効化、アクセスコントロールリストが無効化 2023

今S3のIaCで「AccessControlListNotSupported: The bucket does not allow ACLs」というエラーが出たならそれは2023年4月に行われたS3の仕様変更が原因かもしれない | DevelopersIO 2023

terraform

resource "aws_s3_bucket_ownership_controls" "this" {
  bucket = aws_s3_bucket.this.id

  rule {
    object_ownership = "ObjectWriter"
  }
}

参考

Error during terraform apply after importing manually created private S3 bucket using TF v1.0.11 · Issue #22271 · hashicorp/terraform-provider-aws · GitHub

RDS MySQL 8.0 PHP 5

MySQL 8.0 + PHP 5のデータベース接続エラー

MySQLを5から8にバージョンアップする際に注意

utf8mb4

PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2054] Server sent charset unknown to the client. Please, report to the developers'

PDO::__construct(): Server sent charset (255) unknown to the client. Please, report to the developers

MySQL charset (255) unknown to the client in MySQL and AWS RDS - DEV Community 2021

PHP5.6とMySQL8で「Server sent charset (255) unknown to the client.」ハマった…

参考

PHP :: Bug #74461 :: mysqlnd error on utf8mb4 charset used by MySQL 8.0

まとめ2
mysql はもう使われない古い拡張モジュール
mysqli は推奨されている拡張モジュール
pdo_mysql は他の DB に繋ぐことも考えた抽象化層である PDO を一個挟んだ拡張モジュール
PHP の mysqli, mysqlnd, pdo_mysql, PDO, libmysqlclient まとめ #PHP - Qiita 2019

WAF ホワイトリスト

この状態であれば、他のルールより先にIP_whitelist_ruleによる評価が行なわれることになります。
また先のRule type画面で“Action”をAllowにしたので、IP_whitelist_ruleの条件に合致する、つまりIPセットにあるIPの通信だった場合には、その通信はIP_whitelist_ruleによる評価が終了した段階で他のルールによる評価を飛び越えてWAFを通過します。
これにより、指定IPの通信が他のルールに引っかかる要素を含んでいたとしても、通信先に通すことができるようになるのです。
【AWS】WAFにIPホワイトリストとなるルールを設定する方法 - BFT名古屋 TECH BLOG 2022

AWS Billing IAM

廃止されるアクション
aws-portal:*
purchase-orders:ViewPurchaseOrders
purchase-orders:ModifyPurchaseOrders
[アップデート] 請求・コスト管理・アカウントのコンソールの権限廃止・変更に向けて、事前に切り替えが出来るようになりました | DevelopersIO 2023

【2023/12/11まで】IAMポリシーを更新しないとAWS Billing、Cost Management、Account Consoleへの接続に影響がでるかも #AWS - Qiita 2023