1
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?

More than 3 years have passed since last update.

TerraformでAWS backupの設定を入れる

Last updated at Posted at 2021-08-02

これは何

TerraformでAWS backupの設定を入れた際の記録です。

早速やってみた

$ vi aws_backup.tf
resource "aws_backup_plan" "bastion" {
  name = "tf_backup_plan_bastion"

  rule {
    rule_name         = "tf_backup_plan_rule_bastion"
    target_vault_name = aws_backup_vault.bastion.name
    
        #UTC 17時 = JTC 2
        schedule          = "cron(0 17 * * ? *)"
    
        #二日後に削除
    lifecycle {
      delete_after = 2
    }
  }
}

resource "aws_backup_vault" "bastion" {
  name = "tf_backup_plan_vault_bastion"
}

resource "aws_backup_selection" "bastion" {
  iam_role_arn = "arn:aws:iam::<Account ID>:role/service-role/AWSBackupDefaultServiceRole"
  name         = "aws_backup_selection_bastion"
  plan_id      = aws_backup_plan.bastion.id

#<VolumeのID>は、コンソール上のEC2>Volume から確認できます。

resources = [
    "arn:aws:ec2:ap-northeast-1:<Account ID>:volume/<VolumeのID>"
  ]
}

総じて

構築している最中は、aws_backup_selectionのresourceでvolumeの指定の仕方がよくわからず、苦戦していたのですが、どうやらRegion,Account ID,Volume IDを指定すればいけるっぽいですね。
*実環境で運用される際には、バックアップが実際に取れるか、まで確認してからをオススメいたしますm(__)m

参考

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/backup_selection
https://www.jisakeisan.com/?y=2021&m=08&d=02&hh=02&mm=00&t1=jst&t2=utc
1
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
1
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?