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で管理したくない時のちょっとしたtips

1
Posted at

terraform以外からのリソース変更を適用しない方法。

普段は便利に使っているterraformですが、何でもかんでもterraformで〜っていう事が偶に煩わしく感じるのもまた事実ということで
一部のリソース変更を無視する対処をしたい。

今回はリソースにつけられているタグが変更されても無視する書き方です。

対象リソースの該当部分を指定して ignore_changes = [tags] を記述する。
下記のような場合、subnetのtagがterraform外で更新があっても、planやapply時に上書きされないようにしてくれる。

  lifecycle {
    ignore_changes = [tags]
  }
# public subnet

resource "aws_subnet" "public" {
  count                   = 6
  vpc_id                  = aws_vpc.main.id
  availability_zone       = element(lookup(var.az, "${terraform.workspace}.az"), count.index)
  cidr_block              = element(lookup(var.public_subnet_cidr, "${terraform.workspace}.public_cidr"), count.index)
  map_public_ip_on_launch = element(var.launch_ip, count.index)
  tags = {
    Name = element(var.public_tags, count.index)
  }
  lifecycle {
    ignore_changes = [tags]
  }
}
1
0
0

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?