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_platform_application #3283

Merged
merged 12 commits into from Feb 9, 2018
Merged

Conversation

bflad
Copy link
Member

@bflad bflad commented Feb 7, 2018

This PR is a continuation of #1101

make testacc TEST=./aws TESTARGS='-run=TestAccAwsSnsPlatformApplication'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAwsSnsPlatformApplication -timeout 120m
=== RUN   TestAccAwsSnsPlatformApplication_basic
--- SKIP: TestAccAwsSnsPlatformApplication_basic (0.00s)
	resource_aws_sns_platform_application_test.go:94: no SNS Platform Application environment variables found
=== RUN   TestAccAwsSnsPlatformApplication_basicAttributes
--- SKIP: TestAccAwsSnsPlatformApplication_basicAttributes (0.00s)
	resource_aws_sns_platform_application_test.go:154: no SNS Platform Application environment variables found
=== RUN   TestAccAwsSnsPlatformApplication_iamRoleAttributes
--- SKIP: TestAccAwsSnsPlatformApplication_iamRoleAttributes (0.00s)
	resource_aws_sns_platform_application_test.go:213: no SNS Platform Application environment variables found
=== RUN   TestAccAwsSnsPlatformApplication_snsTopicAttributes
--- SKIP: TestAccAwsSnsPlatformApplication_snsTopicAttributes (0.00s)
	resource_aws_sns_platform_application_test.go:267: no SNS Platform Application environment variables found
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	0.040s

export APNS_SANDBOX_CREDENTIAL_PATH="/path/to/valid-private-key.pem"
export APNS_SANDBOX_PRINCIPAL_PATH="/path/to/valid-certificate.pem"

make testacc TEST=./aws TESTARGS='-run=TestAccAwsSnsPlatformApplication'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAwsSnsPlatformApplication -timeout 120m
=== RUN   TestAccAwsSnsPlatformApplication_basic
=== RUN   TestAccAwsSnsPlatformApplication_basic/APNS_SANDBOX
--- PASS: TestAccAwsSnsPlatformApplication_basic (14.76s)
    --- PASS: TestAccAwsSnsPlatformApplication_basic/APNS_SANDBOX (14.76s)
=== RUN   TestAccAwsSnsPlatformApplication_basicAttributes
=== RUN   TestAccAwsSnsPlatformApplication_basicAttributes/APNS_SANDBOX
=== RUN   TestAccAwsSnsPlatformApplication_basicAttributes/APNS_SANDBOX/success_feedback_sample_rate
--- PASS: TestAccAwsSnsPlatformApplication_basicAttributes (19.05s)
    --- PASS: TestAccAwsSnsPlatformApplication_basicAttributes/APNS_SANDBOX/success_feedback_sample_rate (19.05s)
    --- PASS: TestAccAwsSnsPlatformApplication_basicAttributes/APNS_SANDBOX (19.05s)
=== RUN   TestAccAwsSnsPlatformApplication_iamRoleAttributes
=== RUN   TestAccAwsSnsPlatformApplication_iamRoleAttributes/APNS_SANDBOX
=== RUN   TestAccAwsSnsPlatformApplication_iamRoleAttributes/APNS_SANDBOX/failure_feedback_role_arn
=== RUN   TestAccAwsSnsPlatformApplication_iamRoleAttributes/APNS_SANDBOX/success_feedback_role_arn
--- PASS: TestAccAwsSnsPlatformApplication_iamRoleAttributes (87.31s)
    --- PASS: TestAccAwsSnsPlatformApplication_iamRoleAttributes/APNS_SANDBOX/failure_feedback_role_arn (43.24s)
    --- PASS: TestAccAwsSnsPlatformApplication_iamRoleAttributes/APNS_SANDBOX/success_feedback_role_arn (44.07s)
    --- PASS: TestAccAwsSnsPlatformApplication_iamRoleAttributes/APNS_SANDBOX (87.31s)
=== RUN   TestAccAwsSnsPlatformApplication_snsTopicAttributes
=== RUN   TestAccAwsSnsPlatformApplication_snsTopicAttributes/APNS_SANDBOX
=== RUN   TestAccAwsSnsPlatformApplication_snsTopicAttributes/APNS_SANDBOX/event_delivery_failure_topic_arn
=== RUN   TestAccAwsSnsPlatformApplication_snsTopicAttributes/APNS_SANDBOX/event_endpoint_created_topic_arn
=== RUN   TestAccAwsSnsPlatformApplication_snsTopicAttributes/APNS_SANDBOX/event_endpoint_deleted_topic_arn
=== RUN   TestAccAwsSnsPlatformApplication_snsTopicAttributes/APNS_SANDBOX/event_endpoint_updated_topic_arn
--- PASS: TestAccAwsSnsPlatformApplication_snsTopicAttributes (97.73s)
    --- PASS: TestAccAwsSnsPlatformApplication_snsTopicAttributes/APNS_SANDBOX/event_delivery_failure_topic_arn (25.26s)
    --- PASS: TestAccAwsSnsPlatformApplication_snsTopicAttributes/APNS_SANDBOX/event_endpoint_created_topic_arn (24.64s)
    --- PASS: TestAccAwsSnsPlatformApplication_snsTopicAttributes/APNS_SANDBOX/event_endpoint_deleted_topic_arn (23.88s)
    --- PASS: TestAccAwsSnsPlatformApplication_snsTopicAttributes/APNS_SANDBOX/event_endpoint_updated_topic_arn (23.96s)
    --- PASS: TestAccAwsSnsPlatformApplication_snsTopicAttributes/APNS_SANDBOX (97.73s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	218.903s

@bflad bflad added new-resource Introduces a new resource. service/sns Issues and PRs that pertain to the sns service. labels Feb 7, 2018
@bflad bflad requested a review from radeksimko February 7, 2018 20:32
@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Feb 7, 2018
@bflad bflad requested a review from a team February 8, 2018 21:16
"success_feedback_sample_rate": {
Type: schema.TypeString,
Optional: true,
},
Copy link
Member

Choose a reason for hiding this comment

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

I'm 👌 with the extra abstraction we built by turning all available attributes to lower_case format, but I still feel that we should stick to the API structure and nest all the attributes under attributes, what do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure, honestly, 🙁 . The precedent here is that the other SNS resources (topic/topic_subscription) don't nest them. In this case, I think we're okay because the AWS API nesting is really just an implementation detail and its slightly easier Terraform code and user experience to keep these as top level attributes. Of course that's not valid if we were planning on supporting something like a aws_sns_platform_application_attribute resource (and do the same to the others).

If you feel strongly I can definitely change it. 👍

Copy link
Member

Choose a reason for hiding this comment

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

It really depends how is the API going to evolve going forward - i.e. whether there is going to be more arguments on the root level (which could potentially clash with any nested ones).

I think it's a guessing game at this point and we have quite good deprecation mechanisms available in the schema, so it's fine to keep it as is for now.


attributes := make(map[string]*string)

for k, _ := range resourceAwsSnsPlatformApplication().Schema {
Copy link
Member

Choose a reason for hiding this comment

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

Not sure this is a good idea, sometimes more verbose code is more than "clever abstraction" 😃

Copy link
Member Author

Choose a reason for hiding this comment

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

Same as my other comment, this was probably just copypasta of the SNS topic resource in its original implementation. It was working correctly (currently anyways) so I didn't touch it.

"was provided %q and received error: %s", platformApplicationArn.String(), err)
}

platformApplicationArnResourceParts := strings.Split(platformApplicationArn.Resource, "/")
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: It would be nice to move this into a function so it's more readable, e.g.

platform, name, err := splitSnsPlatformApplicationArn(platformApplicationArn.Resource)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes it would 😄


if attributeOutput.Attributes != nil && len(attributeOutput.Attributes) > 0 {
attrmap := attributeOutput.Attributes
resource := *resourceAwsSnsPlatformApplication()
Copy link
Member

Choose a reason for hiding this comment

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

🤔 This feels little strange as no other resources I know of ever access the schema like this.

Copy link
Member Author

@bflad bflad Feb 9, 2018

Choose a reason for hiding this comment

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

Precedent (and likely where it was copied from): https://github.com/terraform-providers/terraform-provider-aws/blob/master/aws/resource_aws_sns_topic.go#L227

I'm not saying its valid/better though. It is harder to grok. If you want me to change the original PR implementation to loop through each attribute specifically by name, I can certainly do that.


func hashSum(contents interface{}) string {
return fmt.Sprintf("%x", sha256.Sum256([]byte(contents.(string))))
}
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: Do you mind moving this function into the test file as it's only used there?

Copy link
Member Author

Choose a reason for hiding this comment

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

See StateFunc: hashSum, above in the attributes. If you look in #1101 there are some comments asking about this. We don't do this anywhere else that I know off the top of my head for storing obfuscated attribute values (to keep secrets out of the state). I don't have a strong opinion either which way on keeping it or not. It does make the acceptance testing harder when working with actual files rather than strings.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, doh 🤦‍♂️ , not sure why I didn't notice that.

Regarding hashing sensitive data - I don't want to set precedent either way, but I'm slightly more inclined to keeping it plain-text and adding a warning we have in docs of other similarly affected resources, like these:

https://www.terraform.io/docs/providers/aws/r/rds_cluster.html

instead of giving people false hope or setting expectation that it's ok to keep plain-text state file anywhere.

PrincipalHash string
}

func testAccAwsSnsPlatformApplicationPlatformFromEnv() ([]*testAccAwsSnsPlatformApplicationPlatform, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: This function could theoretically take *testing.T as argument and do the skipping which would save us ~3 lines in each test and more importantly allow us to t.Fatal() on actual errors.

Copy link
Member Author

Choose a reason for hiding this comment

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

That is a fantastic idea!

t.Run(platform.Name, func(*testing.T) {
for _, tc := range testCases {
t.Run(fmt.Sprintf("%s/%s", platform.Name, tc), func(*testing.T) {
iamRoleName1 := fmt.Sprintf("tf-acc-%d", acctest.RandInt())
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: Have you considered extracting the actual test logic into a function so it's slightly easier to read this?

@radeksimko radeksimko added this to the v1.9.0 milestone Feb 9, 2018
… function, use testing.T in testAccAwsSnsPlatformApplicationPlatformFromEnv
@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Feb 9, 2018
@bflad
Copy link
Member Author

bflad commented Feb 9, 2018

@radeksimko did the ID and test environment variables refactoring mentioned above. Everything still passes. If there are further items I should adjust here, I think we should probably chat in person since as you've noted, this is quite a complicated resource with the abstractions. 👍

 make test TEST=./aws
==> Checking that code complies with gofmt requirements...
go test ./aws -timeout=30s -parallel=4
ok  	github.com/terraform-providers/terraform-provider-aws/aws	1.953s

make testacc TEST=./aws TESTARGS='-run=TestAccAwsSnsPlatformApplication'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAwsSnsPlatformApplication -timeout 120m
=== RUN   TestAccAwsSnsPlatformApplication_basic
--- SKIP: TestAccAwsSnsPlatformApplication_basic (0.00s)
	resource_aws_sns_platform_application_test.go:73: no SNS Platform Application environment variables found
=== RUN   TestAccAwsSnsPlatformApplication_basicAttributes
--- SKIP: TestAccAwsSnsPlatformApplication_basicAttributes (0.00s)
	resource_aws_sns_platform_application_test.go:73: no SNS Platform Application environment variables found
=== RUN   TestAccAwsSnsPlatformApplication_iamRoleAttributes
--- SKIP: TestAccAwsSnsPlatformApplication_iamRoleAttributes (0.00s)
	resource_aws_sns_platform_application_test.go:73: no SNS Platform Application environment variables found
=== RUN   TestAccAwsSnsPlatformApplication_snsTopicAttributes
--- SKIP: TestAccAwsSnsPlatformApplication_snsTopicAttributes (0.00s)
	resource_aws_sns_platform_application_test.go:73: no SNS Platform Application environment variables found
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	0.038s

export APNS_SANDBOX_CREDENTIAL_PATH="/path/to/valid-private-key.pem"
export APNS_SANDBOX_PRINCIPAL_PATH="/path/to/valid-certificate.pem"

make testacc TEST=./aws TESTARGS='-run=TestAccAwsSnsPlatformApplication'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAwsSnsPlatformApplication -timeout 120m
=== RUN   TestAccAwsSnsPlatformApplication_basic
=== RUN   TestAccAwsSnsPlatformApplication_basic/APNS_SANDBOX
--- PASS: TestAccAwsSnsPlatformApplication_basic (14.33s)
    --- PASS: TestAccAwsSnsPlatformApplication_basic/APNS_SANDBOX (14.33s)
=== RUN   TestAccAwsSnsPlatformApplication_basicAttributes
=== RUN   TestAccAwsSnsPlatformApplication_basicAttributes/APNS_SANDBOX
=== RUN   TestAccAwsSnsPlatformApplication_basicAttributes/APNS_SANDBOX/success_feedback_sample_rate
--- PASS: TestAccAwsSnsPlatformApplication_basicAttributes (18.84s)
    --- PASS: TestAccAwsSnsPlatformApplication_basicAttributes/APNS_SANDBOX/success_feedback_sample_rate (18.84s)
    --- PASS: TestAccAwsSnsPlatformApplication_basicAttributes/APNS_SANDBOX (18.84s)
=== RUN   TestAccAwsSnsPlatformApplication_iamRoleAttributes
=== RUN   TestAccAwsSnsPlatformApplication_iamRoleAttributes/APNS_SANDBOX
=== RUN   TestAccAwsSnsPlatformApplication_iamRoleAttributes/APNS_SANDBOX/failure_feedback_role_arn
=== RUN   TestAccAwsSnsPlatformApplication_iamRoleAttributes/APNS_SANDBOX/success_feedback_role_arn
--- PASS: TestAccAwsSnsPlatformApplication_iamRoleAttributes (86.20s)
    --- PASS: TestAccAwsSnsPlatformApplication_iamRoleAttributes/APNS_SANDBOX/failure_feedback_role_arn (42.68s)
    --- PASS: TestAccAwsSnsPlatformApplication_iamRoleAttributes/APNS_SANDBOX/success_feedback_role_arn (43.52s)
    --- PASS: TestAccAwsSnsPlatformApplication_iamRoleAttributes/APNS_SANDBOX (86.20s)
=== RUN   TestAccAwsSnsPlatformApplication_snsTopicAttributes
=== RUN   TestAccAwsSnsPlatformApplication_snsTopicAttributes/APNS_SANDBOX
=== RUN   TestAccAwsSnsPlatformApplication_snsTopicAttributes/APNS_SANDBOX/event_delivery_failure_topic_arn
=== RUN   TestAccAwsSnsPlatformApplication_snsTopicAttributes/APNS_SANDBOX/event_endpoint_created_topic_arn
=== RUN   TestAccAwsSnsPlatformApplication_snsTopicAttributes/APNS_SANDBOX/event_endpoint_deleted_topic_arn
=== RUN   TestAccAwsSnsPlatformApplication_snsTopicAttributes/APNS_SANDBOX/event_endpoint_updated_topic_arn
--- PASS: TestAccAwsSnsPlatformApplication_snsTopicAttributes (93.48s)
    --- PASS: TestAccAwsSnsPlatformApplication_snsTopicAttributes/APNS_SANDBOX/event_delivery_failure_topic_arn (23.45s)
    --- PASS: TestAccAwsSnsPlatformApplication_snsTopicAttributes/APNS_SANDBOX/event_endpoint_created_topic_arn (23.58s)
    --- PASS: TestAccAwsSnsPlatformApplication_snsTopicAttributes/APNS_SANDBOX/event_endpoint_deleted_topic_arn (22.08s)
    --- PASS: TestAccAwsSnsPlatformApplication_snsTopicAttributes/APNS_SANDBOX/event_endpoint_updated_topic_arn (24.36s)
    --- PASS: TestAccAwsSnsPlatformApplication_snsTopicAttributes/APNS_SANDBOX (93.48s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	212.893s

@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Feb 9, 2018
@bflad bflad merged commit ae1d4ce into master Feb 9, 2018
@bflad bflad deleted the f-aws_sns_application branch February 9, 2018 17:50
bflad added a commit that referenced this pull request Feb 9, 2018
@bflad
Copy link
Member Author

bflad commented Feb 9, 2018

This has been released in terraform-provider-aws version 1.9.0. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

jocgir added a commit to coveord/terraform-provider-aws that referenced this pull request Feb 12, 2018
* commit '5293a0e3b1366ee16d8742b9b2354781a79bfbd9': (224 commits)
  v1.9.0
  Update CHANGELOG for hashicorp#1101 and hashicorp#3283
  docs/resource/aws_sns_platform_application: Add note about platform_credential and platform_principal hashing
  resource/aws_sns_platform_application: Refactor ID parsing to its own function, use testing.T in testAccAwsSnsPlatformApplicationPlatformFromEnv
  Add lambda example (hashicorp#3168)
  Update CHANGELOG for hashicorp#3157
  docs/data-source/aws_region: Remove now deprecated current argument
  data-source/aws_region: Refactor logic into findRegionByEc2Endpoint and findRegionByName functions
  Update CHANGELOG for hashicorp#3301
  Update CHANGELOG for hashicorp#2559 and hashicorp#3240
  Update CHANGELOG.md
  resource/aws_kinesis_stream: Retry deletion on LimitExceededException (hashicorp#3108)
  Update CHANGELOG.md
  resource/aws_dynamodb_table_item: Cleanup + add missing bits
  Added dynamodb_table_item resource hashicorp#517
  Update CHANGELOG.md
  New Resource: aws_cloud9_environment_ec2
  Update CHANGELOG.md
  Fixed markdown typo in docs
  resource/aws_kinesis_firehose_delivery_stream: Prevent crashes on empty CloudWatchLoggingOptions and fix extended_s3_configuration kms_key_arn
  ...

# Conflicts:
#	aws/validators.go
jocgir added a commit to coveord/terraform-provider-aws that referenced this pull request Feb 12, 2018
…parameters-features

* commit '5293a0e3b1366ee16d8742b9b2354781a79bfbd9': (752 commits)
  v1.9.0
  Update CHANGELOG for hashicorp#1101 and hashicorp#3283
  docs/resource/aws_sns_platform_application: Add note about platform_credential and platform_principal hashing
  resource/aws_sns_platform_application: Refactor ID parsing to its own function, use testing.T in testAccAwsSnsPlatformApplicationPlatformFromEnv
  Add lambda example (hashicorp#3168)
  Update CHANGELOG for hashicorp#3157
  docs/data-source/aws_region: Remove now deprecated current argument
  data-source/aws_region: Refactor logic into findRegionByEc2Endpoint and findRegionByName functions
  Update CHANGELOG for hashicorp#3301
  Update CHANGELOG for hashicorp#2559 and hashicorp#3240
  Update CHANGELOG.md
  resource/aws_kinesis_stream: Retry deletion on LimitExceededException (hashicorp#3108)
  Update CHANGELOG.md
  resource/aws_dynamodb_table_item: Cleanup + add missing bits
  Added dynamodb_table_item resource hashicorp#517
  Update CHANGELOG.md
  New Resource: aws_cloud9_environment_ec2
  Update CHANGELOG.md
  Fixed markdown typo in docs
  resource/aws_kinesis_firehose_delivery_stream: Prevent crashes on empty CloudWatchLoggingOptions and fix extended_s3_configuration kms_key_arn
  ...

# Conflicts:
#	aws/resource_aws_ssm_parameter_test.go
@ghost
Copy link

ghost commented Apr 8, 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 8, 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/XL Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants