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: aws_ses_receipt_rule: fix off-by-one errors #12961

Merged
merged 1 commit into from
Mar 27, 2017

Conversation

dougneal
Copy link
Contributor

In function resourceAwsSesReceiptRuleRead the position of the receipt rules in the rule set was taken directly from the index of the rule's position in the slice returned by the AWS API call. As the slice is zero-based and the ruleset is one-based, this results in an incorrect representation.

This manifests as aws_ses_receipt_rule resources always showing a diff during plan or apply.

In function `resourceAwsSesReceiptRuleRead` the position of the receipt
rules in the rule set was taken directly from the index of the rule's
position in the slice returned by the AWS API call. As the slice is
zero-based and the ruleset is one-based, this results in an incorrect
representation.

This manifests as `aws_ses_receipt_rule` resources always showing a
diff during plan or apply.
@stack72
Copy link
Contributor

stack72 commented Mar 27, 2017

Hi @dougneal

Thanks for the work here - is it possible to post a config that shows the error manifesting itself? I'd like to understand if there is a potential issue for users who upgrade

Thanks

Paul

@dougneal
Copy link
Contributor Author

Hi @stack72, yeah sure, I'll put something together.

@stack72
Copy link
Contributor

stack72 commented Mar 27, 2017

<3 for this :)

@dougneal
Copy link
Contributor Author

dougneal commented Mar 27, 2017

With the following configuration:

variable "s3_bucket_name" {
  type = "string"
}

resource "aws_ses_receipt_rule" "terraform-pr-12961" {
  name = "terraform-pr-12961"
  rule_set_name = "default-rule-set"
  recipients = ["admin@example.com"]
  enabled = true
  s3_action = {
    position = 1
    bucket_name = "${var.s3_bucket_name}"
    object_key_prefix = "ses/terraform-pr-12961"
  }
}

Then applying from a blank state:

$ terraform apply .
aws_ses_receipt_rule.terraform-pr-12961: Creating...
  enabled:                               "" => "true"
  name:                                  "" => "terraform-pr-12961"
  recipients.#:                          "" => "1"
  recipients.1433171261:                 "" => "admin@example.com"
  rule_set_name:                         "" => "default-rule-set"
  s3_action.#:                           "" => "1"
  s3_action.618256378.bucket_name:       "" => "<redacted>"
  s3_action.618256378.kms_key_arn:       "" => ""
  s3_action.618256378.object_key_prefix: "" => "ses/terraform-pr-12961"
  s3_action.618256378.position:          "" => "1"
  s3_action.618256378.topic_arn:         "" => ""
  scan_enabled:                          "" => "<computed>"
  tls_policy:                            "" => "<computed>"
aws_ses_receipt_rule.terraform-pr-12961: Creation complete (ID: terraform-pr-12961)

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

The state of your infrastructure has been saved to the path
below. This state is required to modify and destroy your
infrastructure, so keep it safe. To inspect the complete state
use the `terraform show` command.

State path:

And running apply again immediately afterwards, showing that the state of the resource as read from the API doesn't match the representation as computed from the config:

$ terraform apply .
aws_ses_receipt_rule.terraform-pr-12961: Refreshing state... (ID: terraform-pr-12961)
aws_ses_receipt_rule.terraform-pr-12961: Modifying... (ID: terraform-pr-12961)
  s3_action.1036183227.bucket_name:       "<redacted>" => ""
  s3_action.1036183227.kms_key_arn:       "" => ""
  s3_action.1036183227.object_key_prefix: "ses/terraform-pr-12961" => ""
  s3_action.1036183227.position:          "0" => "0"
  s3_action.1036183227.topic_arn:         "" => ""
  s3_action.618256378.bucket_name:        "" => "<redacted>"
  s3_action.618256378.kms_key_arn:        "" => ""
  s3_action.618256378.object_key_prefix:  "" => "ses/terraform-pr-12961"
  s3_action.618256378.position:           "" => "1"
  s3_action.618256378.topic_arn:          "" => ""
aws_ses_receipt_rule.terraform-pr-12961: Modifications complete (ID: terraform-pr-12961)

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

@stack72
Copy link
Contributor

stack72 commented Mar 27, 2017

Awesome! Thanks for this @dougneal :)

This is exactly what I needed

LGTM

@stack72 stack72 merged commit e7e35b5 into hashicorp:master Mar 27, 2017
@dougneal dougneal deleted the fix-aws_ses_recipt_rule-offbyone branch March 27, 2017 13:07
@ghost
Copy link

ghost commented Apr 14, 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 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants