0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AWSリソースをTerraformにImportする(SecretsManager関連)

Last updated at Posted at 2024-04-14

前提

全体の概略はこちらから

構成図

👆の図のように、

  • SecretsManagerで管理するのは、RDSProxyが使うDB認証とLambdaが使うDB認証。

環境構築用のmain.tf, variable.tf

main.tf

# secret used by application
resource "aws_secretsmanager_secret" "dbstring" {
  name          = "${var.project}-${var.env}-db-connection-string"
  description   = "PGconnection string will be used for connecting to database"
  tags = {
    Env     = var.env
    Account = var.account
    Project = var.project
  }   
}
# secret used by rds proxy
resource "aws_secretsmanager_secret" "dbpw" {
  name          = "${var.project}-${var.env}-db-connection-pw"
  description   = "RDSProxy"
  tags = {
    Env     = var.env
    Account = var.account
    Project = var.project
  }   
}

variable.tf

# common variable 
variable "project" {
    type        = string
    description = "project name"
}
variable "account" {
    type        = string
    description = "prod or no-prod"
}
variable "env" {
    type        = string
    description = "dev, test, stage or prod"
}

outputs.tf

output "secretsmanager_dbstring_arn"{
  value       = aws_secretsmanager_secret.dbstring.arn
  description = "arn of secrets manager' secret used by application"
}
output "secretsmanager_dbpw_arn"{
  value       = aws_secretsmanager_secret.dbpw.arn
  description = "arn of secrets manager' secret used by rds proxy"
}

設計思想

  • importする場合、secret情報そのものはtfファイルに記載しない。
    (outputs.tfで他リソースから利用できさえすればいい)
  • 最初からterraform でインフラ構築する場合、注意が必要!
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?