Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/aws: Weird behavior around ignore_changes #5352

Closed
Bowbaq opened this issue Feb 27, 2016 · 4 comments
Closed

provider/aws: Weird behavior around ignore_changes #5352

Bowbaq opened this issue Feb 27, 2016 · 4 comments

Comments

@Bowbaq
Copy link
Contributor

Bowbaq commented Feb 27, 2016

Use case: ignore changes to the shard count on a kinesis stream

TL/DR

  • there appears to be some weird interactions between ignore_changes and fields marked as ForceNew: true
  • changing the shard_count on a kinesis stream managed by terraform causes that stream to be replaced by a new one, deleting all the data
  • replacing a resource doesn't always cause its ARN to change. It would be nice if a change that causes a resource to be replaced but retain its ARN didn't trickle down to all dependent resources

Problem 1: can't create a stream while ignore changes to shard_count

resource "aws_kinesis_stream" "test" {
  name = "tf-test-stream"
  shard_count = 1

  lifecycle {
    ignore_changes = [ "shard_count" ]
  }
}

Expected behavior: kinesis stream gets created, subsequent changes to shard_count are ignored
Actual:

* aws_kinesis_stream.test: [WARN] Error creating Kinesis Stream: "1 validation error detected: Value '0' at 'shardCount' failed to satisfy constraint: Member must have value greater than or equal to 1", code: "ValidationException"

Problem 2: external changes to the shard count cause terraform to re-create the stream

  • create stream without the ignore_changes modifier
resource "aws_kinesis_stream" "test" {
  name = "tf-test-stream"
  shard_count = 1
}
bowbaq@bowbaq-originate [03:53:16] [/tmp/tf] 
-> % terraform apply
aws_kinesis_stream.test: Creating...
  arn:              "" => "<computed>"
  name:             "" => "tf-test-stream"
  retention_period: "" => "24"
  shard_count:      "" => "1"
aws_kinesis_stream.test: Creation complete

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
  • add the ignore_changes modifier
  • manually re-shard the stream
    Expected behavior: nothing happens
    Actual: terraform plan wants to re-create the stream
bowbaq@bowbaq-originate [03:56:40] [/tmp/tf] 
-> % terraform plan
Refreshing Terraform state prior to plan...

aws_kinesis_stream.test: Refreshing state... (ID: arn:aws:kinesis:us-east-1:314531994667:stream/tf-test-stream)

The Terraform execution plan has been generated and is shown below.
Resources are shown in alphabetical order for quick scanning. Green resources
will be created (or destroyed and then created if an existing resource
exists), yellow resources are being changed in-place, and red resources
will be destroyed.

Note: You didn't specify an "-out" parameter to save this plan, so when
"apply" is called, Terraform can't guarantee this is what will execute.

-/+ aws_kinesis_stream.test
    arn:              "arn:aws:kinesis:us-east-1:314531994667:stream/tf-test-stream" => "<computed>"
    name:             "tf-test-stream" => "tf-test-stream"
    retention_period: "24" => "24"


Plan: 1 to add, 0 to change, 1 to destroy.

Problem 3: number of shards read by terraform includes closed shards

Expected: terraform only considers open shards in the shard count. closed shards expire after a while.
Actual: number of open shards: 2, number of closed shards: 1

-/+ aws_kinesis_stream.test
    arn:              "arn:aws:kinesis:us-east-1:314531994667:stream/tf-test-stream" => "<computed>"
    name:             "tf-test-stream" => "tf-test-stream"
    retention_period: "24" => "24"
    shard_count:      "3" => "1" (forces new resource)


Plan: 1 to add, 0 to change, 1 to destroy.

Problem 4: resource replacement causes dependents to be updated, even if ARN remains the same

resource "aws_kinesis_stream" "test" {
  name = "tf-test-stream"
  shard_count = 1

  lifecycle {
    ignore_changes = [ "shard_count" ]
  }
}

resource "aws_iam_policy" "test" {
  name = "tf-test-stream-read"
  policy = <<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "kinesis:GetRecords",
        "kinesis:GetShardIterator",
        "kinesis:DescribeStream",
        "kinesis:ListStreams"
      ],
      "Resource": "${aws_kinesis_stream.test.arn}"
    }
  ]
}
EOF
}
bowbaq@bowbaq-originate [04:34:51] [/tmp/tf] 
-> % terraform plan
Refreshing Terraform state prior to plan...

aws_kinesis_stream.test: Refreshing state... (ID: arn:aws:kinesis:us-east-1:314531994667:stream/tf-test-stream)
aws_iam_policy.test: Refreshing state... (ID: arn:aws:iam::314531994667:policy/tf-test-stream-read)

The Terraform execution plan has been generated and is shown below.
Resources are shown in alphabetical order for quick scanning. Green resources
will be created (or destroyed and then created if an existing resource
exists), yellow resources are being changed in-place, and red resources
will be destroyed.

Note: You didn't specify an "-out" parameter to save this plan, so when
"apply" is called, Terraform can't guarantee this is what will execute.

~ aws_iam_policy.test
    policy: "{\n  \"Version\": \"2012-10-17\",\n  \"Statement\": [\n    {\n      \"Effect\": \"Allow\",\n      \"Action\": [\n        \"kinesis:GetRecords\",\n        \"kinesis:GetShardIterator\",\n        \"kinesis:DescribeStream\",\n        \"kinesis:ListStreams\"\n      ],\n      \"Resource\": \"arn:aws:kinesis:us-east-1:314531994667:stream/tf-test-stream\"\n    }\n  ]\n}\n" => "{\n  \"Version\": \"2012-10-17\",\n  \"Statement\": [\n    {\n      \"Effect\": \"Allow\",\n      \"Action\": [\n        \"kinesis:GetRecords\",\n        \"kinesis:GetShardIterator\",\n        \"kinesis:DescribeStream\",\n        \"kinesis:ListStreams\"\n      ],\n      \"Resource\": \"${aws_kinesis_stream.test.arn}\"\n    }\n  ]\n}\n"

-/+ aws_kinesis_stream.test
    arn:              "arn:aws:kinesis:us-east-1:314531994667:stream/tf-test-stream" => "<computed>"
    name:             "tf-test-stream" => "tf-test-stream"
    retention_period: "24" => "24"


Plan: 1 to add, 1 to change, 1 to destroy.
@joshuaspence
Copy link
Contributor

+1

@Bowbaq
Copy link
Contributor Author

Bowbaq commented Mar 11, 2016

@phinze @catsby do you guys have any ideas about this?

@phinze
Copy link
Contributor

phinze commented Mar 14, 2016

Hi @Bowbaq - thanks for this report - I'm diving into ignore_changes issues today. Consolidating these problems up into: #5627

@phinze phinze closed this as completed Mar 14, 2016
@ghost
Copy link

ghost commented Apr 27, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants