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

New Resource: aws_sns_sms_preferences #3858

Merged
merged 3 commits into from
May 11, 2018

Conversation

lbrucher
Copy link
Contributor

There is currently no way to set the SMS preferences in SNS from Terraform.

This PR is an attempt at providing this feature.

@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Mar 21, 2018
@bflad bflad added new-resource Introduces a new resource. service/sns Issues and PRs that pertain to the sns service. labels Mar 21, 2018
@radeksimko radeksimko changed the title Add a resource to allow setting SNS SMS preferences New Resource: aws_sns_sms_preferences Mar 23, 2018
@lbrucher
Copy link
Contributor Author

Hello, I was wondering if anyone has had a chance to look at this PR? Any blocker or changes to be made? Any potential of it being merged soon? Thanks!

@bcornils
Copy link
Contributor

bcornils commented Apr 4, 2018

Hello @lbrucher apologies for the delay. We are looking into several PR's and requests atm. Let me work on where we are and get back to you with something concrete. I'm the new PM for the project so I believe the slow down is my fault.


const resourceId = "aws_sns_sms_id"

var SMSAttributeMap = map[string]string{
Copy link
Contributor

Choose a reason for hiding this comment

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

no need to export this I don't think? (same with the var below as well)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, corrected

defaultSmsType := d.Get("default_sms_type").(string)
usageReportS3Bucket := d.Get("usage_report_s3_bucket").(string)

// Validation
Copy link
Contributor

Choose a reason for hiding this comment

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

Please move validation in to ValidateFunc in the schema above like this: https://github.com/terraform-providers/terraform-provider-aws/blob/3f9a830038f20f819ba947e90770c50d470d164b/aws/resource_aws_s3_bucket.go#L249

(for these other validations as well, more validations available in the validation package, int ranges, string in slice, etc)


Schema: map[string]*schema.Schema{
"monthly_spend_limit": {
Type: schema.TypeString,
Copy link
Contributor

Choose a reason for hiding this comment

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

This probably should be a TypeInt string so TF can do the proper type validation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is tricky because the AWS API treats all those attributes as Strings, including monthly spend limit and delivery sampling rate, and an empty string "" (not defined) is not the same as a "0" (explicit 0).
Using int values in TF won't allow us to distinguish between the 2 cases and will always set those values as "0" when retrieved as "", which would be incorrect.

},

"delivery_status_success_sampling_rate": {
Type: schema.TypeString,
Copy link
Contributor

Choose a reason for hiding this comment

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

This probably should be a TypeInt string so TF can do the proper type validation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See above comment

@paultyng
Copy link
Contributor

paultyng commented Apr 9, 2018

@lbrucher appreciate this PR, this is pretty close, just some minor Terraform specific stuff to clean up I think.

@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Apr 25, 2018
@lbrucher
Copy link
Contributor Author

@paultyng thanks for the feedback, please see my comments above, thanks.

Copy link
Contributor

@paultyng paultyng left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@bflad
Copy link
Contributor

bflad commented May 2, 2018

I'm seeing a bunch of test failures but they are likely from our testing being parallelized:

=== RUN   TestAccAWSSNSSMSPreferences_almostAll
--- FAIL: TestAccAWSSNSSMSPreferences_almostAll (6.24s)
    testing.go:518: Step 0 error: After applying this step and refreshing, the plan was not empty:
        
        DIFF:
        
        UPDATE: aws_sns_sms_preferences.test_pref
          default_sms_type:                      "" => "Transactional"
          delivery_status_iam_role_arn:          "arn:aws:iam::*******:role/test_smsdelivery_role" => ""
          delivery_status_success_sampling_rate: "75" => ""
          monthly_spend_limit:                   "" => "1"
          usage_report_s3_bucket:                "" => "some-bucket"
=== RUN   TestAccAWSSNSSMSPreferences_defaultSMSType
--- FAIL: TestAccAWSSNSSMSPreferences_defaultSMSType (6.70s)
    testing.go:518: Step 0 error: After applying this step and refreshing, the plan was not empty:
        
        DIFF:
        
        UPDATE: aws_sns_sms_preferences.test_pref
          default_sms_type:                      "" => "Transactional"
          delivery_status_iam_role_arn:          "arn:aws:iam::*******:role/test_smsdelivery_role" => ""
          delivery_status_success_sampling_rate: "75" => ""

=== RUN   TestAccAWSSNSSMSPreferences_deliveryRole
--- FAIL: TestAccAWSSNSSMSPreferences_deliveryRole (9.55s)
    testing.go:579: Error destroying resource! WARNING: Dangling resources
        may exist. The full state and error is shown below.
        
        Error: Check failed: SNS SMS Preferences resource exists when it should be destroyed!
        
        State: <no state>

=== RUN   TestAccAWSSNSSMSPreferences_empty
--- FAIL: TestAccAWSSNSSMSPreferences_empty (6.10s)
    testing.go:518: Step 0 error: After applying this step and refreshing, the plan was not empty:
        
        DIFF:
        
        UPDATE: aws_sns_sms_preferences.test_pref
          delivery_status_iam_role_arn:          "arn:aws:iam::*******:role/test_smsdelivery_role" => ""
          delivery_status_success_sampling_rate: "75" => ""

This will need to be adjusted on merge

@bflad bflad added this to the v1.18.0 milestone May 2, 2018
@rahuljain1311
Copy link

@bflad @paultyng
Thanks for approving this PR. It will significantly help us while playing with SMSs. If you guys can tell possible time frame for releasing v1.18.0 it would be super helpful

@bflad bflad modified the milestones: v1.18.0, v1.19.0 May 11, 2018
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

Testing serialized and the destroy check function fixed in 0cbaba3

Passes acceptance testing now:

make testacc TEST=./aws TESTARGS='-run=TestAccAWSSNSSMSPreferences'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSSNSSMSPreferences -timeout 120m
=== RUN   TestAccAWSSNSSMSPreferences
=== RUN   TestAccAWSSNSSMSPreferences/almostAll
=== RUN   TestAccAWSSNSSMSPreferences/defaultSMSType
=== RUN   TestAccAWSSNSSMSPreferences/deliveryRole
=== RUN   TestAccAWSSNSSMSPreferences/empty
--- PASS: TestAccAWSSNSSMSPreferences (40.16s)
    --- PASS: TestAccAWSSNSSMSPreferences/almostAll (10.71s)
    --- PASS: TestAccAWSSNSSMSPreferences/defaultSMSType (9.13s)
    --- PASS: TestAccAWSSNSSMSPreferences/deliveryRole (10.78s)
    --- PASS: TestAccAWSSNSSMSPreferences/empty (9.55s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	40.211s

@bflad bflad merged commit c0eab44 into hashicorp:master May 11, 2018
bflad added a commit that referenced this pull request May 11, 2018
@bflad
Copy link
Contributor

bflad commented May 17, 2018

This has been released in version 1.19.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@ghost
Copy link

ghost commented Apr 6, 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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
new-resource Introduces a new resource. service/sns Issues and PRs that pertain to the sns service. size/L Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants