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: Added RDS event subscriptions #6367

Merged
merged 1 commit into from
May 5, 2016

Conversation

bigkraig
Copy link
Contributor

Addresses #5797, I still need to add more test cases and look further into the tags. You can definitely tag these subscriptions based on the AWS Console, you can see them in there, but I haven't seen how to retrieve them from the API.

return err
}

// Set tags, but theyre not in the response
Copy link
Member

@radeksimko radeksimko Apr 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tags can be queried via separate API, see how we do it for DB instances:
https://github.com/hashicorp/terraform/blob/master/builtin/providers/aws/resource_aws_db_instance.go#L650-L675
The same API seems to be used for many resources, see http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_Tagging.html#USER_Tagging.ARN

Also keep in mind we always try to avoid extra API requests for account ID like you can see in https://github.com/hashicorp/terraform/blob/master/builtin/providers/aws/resource_aws_db_instance.go#L975 where it wasn't avoidable. It is avoidable for RDS Event Subscriptions though since you have sub.CustomerAwsId available. 😺

@radeksimko
Copy link
Member

@bigkraig I left you some comments there, hopefully it helps you in moving this from WIP to "ready for final review & merge" 😉

The most important ones are regarding tags & retry logic for updates + acceptance tests.
It would be nice to have at least 1 more test which would be testing resource updates.

Also in terms of convenience I think that user would expect the subscription to be enabled = true by default, rather than disabled by default.

@radeksimko radeksimko added the waiting-response An issue/pull request is waiting for a response from the community label Apr 27, 2016
@bigkraig
Copy link
Contributor Author

@radeksimko thanks for all of the work! I'll get all of these looked at asap, a lot of helpful information in here.

@bigkraig
Copy link
Contributor Author

@radeksimko We use federated accounts here which causes iam.GetUser to fail and that means I am unable to generate ARNs for RDS resources. This becomes a problem for tag testing, which requires the ARN for making changes.

@bigkraig
Copy link
Contributor Author

bigkraig commented Apr 28, 2016

I was able to fix the ARN problem by updating the aws-sdk-go library, but my branch was off an older HEAD so it looks like it has gone into merge hell. I may rebase/rework this branch if/when #6385 is merged

@radeksimko
Copy link
Member

Thanks for the other PRs, but I don't think any of them are blockers for this PR, specifically you don't need to be querying API for account ID for this resource, as I mentioned in one of my comments:

Also keep in mind we always try to avoid extra API requests for account ID like you can see in https://github.com/hashicorp/terraform/blob/master/builtin/providers/aws/resource_aws_db_instance.go#L975 where it wasn't avoidable. It is avoidable for RDS Event Subscriptions though since you have sub.CustomerAwsId available. 😺

@bigkraig
Copy link
Contributor Author

@radeksimko I don't think its avoidable in resourceAwsDbEventSubscriptionUpdate. I can get the account id from ModifyEventSubscription, but that only happens if something has changed. If only the tags are different I wouldn't have made that call.

@radeksimko
Copy link
Member

I can get the account id from ModifyEventSubscription

You can get it in resourceAwsDbEventSubscriptionRead and save it to the schema, just create a new field in the schema, e.g. customer_aws_id and make it Computed: true. Then you can leverage that account ID anywhere else, in other methods.

@bigkraig
Copy link
Contributor Author

@radeksimko done! is this a wrap?

@bigkraig bigkraig changed the title WIP: Adding RDS event subscriptions Added RDS event subscriptions Apr 29, 2016
@bigkraig bigkraig force-pushed the rds-event-subscription branch 2 times, most recently from a78b496 to de4725e Compare April 29, 2016 23:13
_, err = stateConf.WaitForState()
if err != nil {
return fmt.Errorf("Modifying RDS Event Subscription %s failed: %s", d.Id(), err)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also be calling setPartial for all fields that have been successfully modified here - i.e. enabled, event_categories, sns_topic and source_type, otherwise if an error occurs when setting tags below, these changes might be lost, or rather treated as unsaved.

@radeksimko
Copy link
Member

radeksimko commented May 1, 2016

I left you some (hopefully last before merge) comments there, otherwise this is looking pretty good.

Also I appreciate you squashed the changes into 1 commit 👍

@radeksimko radeksimko self-assigned this May 1, 2016
@bigkraig bigkraig changed the title Added RDS event subscriptions provider/aws: Added RDS event subscriptions May 2, 2016
@bigkraig
Copy link
Contributor Author

bigkraig commented May 2, 2016

@radeksimko Got everything addressed. I have had some problems running the update acceptance test, it deletes before it runs the update. I'm not sure what I am doing wrong here, I looked at TestAccAWSRDSCluster_backupsUpdate to compare and I am missing whatever is different.

I was able to verify by running terraform against my own configurations, so its just a matter of fixing the test at this point.

@radeksimko radeksimko removed the waiting-response An issue/pull request is waiting for a response from the community label May 3, 2016
// set tags
conn := meta.(*AWSClient).rdsconn
arn := buildRDSEventSubscriptionARN(d.Get("customer_aws_id").(string), d.Id(), meta.(*AWSClient).region)
d.Set("arn", arn)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no arn field defined in the schema. I don't think it necessarily needs to be, but in such case we shouldn't be trying to save the ARN to state.

@radeksimko
Copy link
Member

Except the ARN, there's just one last thing - probably misunderstanding of my previous comment:

if d.HasChange("enabled") {
    d.SetPartial("enabled")

the SetPartial function is (in the current version if this PR) confirming the value should be changed at a stage where you cannot be sure whether the update operation is actually going to be successful - i.e. too early.

Better use of that function would be something like this:

if requestUpdate {
    log.Printf("[DEBUG] RDS Event Subscription modification request: %#v", req)
...
    // Wait, catching any errors
    _, err = stateConf.WaitForState()
    if err != nil {
        return fmt.Errorf("Modifying RDS Event Subscription %s failed: %s", d.Id(), err)
    }
    d.SetPartial("event_categories")
    d.SetPartial("enabled")
    d.SetPartial("sns_topic")
    d.SetPartial("...another field...")
}
...

i.e. only call SetPartial when you're sure that the field was actually updated successfully.

See how we do this in aws_elb for example.

I will try to run the acceptance tests to see what the issue is there.

@radeksimko
Copy link
Member

So the acceptance tests need some tuning - possibly a copy-paste error:

diff --git a/builtin/providers/aws/resource_aws_db_event_subscription_test.go b/builtin/providers/aws/resource_aws_db_event_subscription_test.go
index 5aa5f51..26de043 100644
--- a/builtin/providers/aws/resource_aws_db_event_subscription_test.go
+++ b/builtin/providers/aws/resource_aws_db_event_subscription_test.go
@@ -24,13 +24,13 @@ func TestAccAWSDBEventSubscription_basicUpdate(t *testing.T) {
                                Check: resource.ComposeTestCheckFunc(
                                        testAccCheckAWSDBEventSubscriptionExists("aws_db_event_subscription.bar", &v),
                                        resource.TestCheckResourceAttr(
-                                               "aws_db_instance.bar", "enabled", "true"),
+                                               "aws_db_event_subscription.bar", "enabled", "true"),
                                        resource.TestCheckResourceAttr(
-                                               "aws_db_instance.bar", "source_type", "db-instance"),
+                                               "aws_db_event_subscription.bar", "source_type", "db-instance"),
                                        resource.TestCheckResourceAttr(
-                                               "aws_db_instance.bar", "name", "baz"),
+                                               "aws_db_event_subscription.bar", "name", "tf-acc-test-rds-event-subs"),
                                        resource.TestCheckResourceAttr(
-                                               "aws_db_instance.bar", "tags.Name", "name"),
+                                               "aws_db_event_subscription.bar", "tags.Name", "name"),
                                ),
                        },
                        resource.TestStep{
@@ -38,11 +38,11 @@ func TestAccAWSDBEventSubscription_basicUpdate(t *testing.T) {
                                Check: resource.ComposeTestCheckFunc(
                                        testAccCheckAWSDBEventSubscriptionExists("aws_db_event_subscription.bar", &v),
                                        resource.TestCheckResourceAttr(
-                                               "aws_db_instance.bar", "enabled", "false"),
+                                               "aws_db_event_subscription.bar", "enabled", "false"),
                                        resource.TestCheckResourceAttr(
-                                               "aws_db_instance.bar", "source_type", "db-parameter-group"),
+                                               "aws_db_event_subscription.bar", "source_type", "db-parameter-group"),
                                        resource.TestCheckResourceAttr(
-                                               "aws_db_instance.bar", "tags.Name", "new-name"),
+                                               "aws_db_event_subscription.bar", "tags.Name", "new-name"),
                                ),
                        },
                },

then it will work as expected:

TF_ACC=1 go test ./builtin/providers/aws -v -run=AWSDBEventSubscription -timeout 120m
=== RUN   TestAccAWSDBEventSubscription_basicUpdate
--- PASS: TestAccAWSDBEventSubscription_basicUpdate (1455.29s)
PASS
ok      github.com/hashicorp/terraform/builtin/providers/aws    1455.318s

@radeksimko radeksimko added the waiting-response An issue/pull request is waiting for a response from the community label May 4, 2016
@bigkraig
Copy link
Contributor Author

bigkraig commented May 5, 2016

@radeksimko Done!!! Thanks for all of the help with this.

@radeksimko radeksimko removed the waiting-response An issue/pull request is waiting for a response from the community label May 5, 2016
@radeksimko
Copy link
Member

radeksimko commented May 5, 2016

Thanks @bigkraig for finishing this. I reran acceptance tests and re-checked the code and it LGTM.

@radeksimko radeksimko merged commit 1f80ec4 into hashicorp:master May 5, 2016
@bigkraig bigkraig deleted the rds-event-subscription branch May 5, 2016 13:59
bigkraig added a commit to ticketmaster/terraform that referenced this pull request May 5, 2016
cristicalin pushed a commit to cristicalin/terraform that referenced this pull request May 24, 2016
@ghost
Copy link

ghost commented Apr 25, 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 25, 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.

2 participants