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

Issue #143 - Add aws_iot_policy resource based on work from @jhedev #986

Merged
merged 2 commits into from
Jul 19, 2017

Conversation

AlexMabry
Copy link
Contributor

My goal is to add support for the AWS IoT service. This is my first time committing, so I just wanted to add a simple resource to get my feet wet. I believe I am followed the guidelines, but please point out anything that needs to be added or change.

@grubernaut grubernaut added enhancement Requests to existing resources that expand the functionality or scope. new-resource Introduces a new resource. labels Jun 28, 2017
@AlexMabry AlexMabry changed the title [WIP] Issues #143 - Add aws_iot_policy resource based on work from @jhedev Issues #143 - Add aws_iot_policy resource based on work from @jhedev Jun 29, 2017
@AlexMabry AlexMabry changed the title Issues #143 - Add aws_iot_policy resource based on work from @jhedev Issue #143 - Add aws_iot_policy resource based on work from @jhedev Jun 29, 2017
Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

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

This is looking very good for a first contribution! Well done.

I just left you some comments there, especially around testing. I feel this is quite close to a merge-able state though.

Let me know if you have any questions.

Config: testAccAWSIoTPolicy_basic,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSIoTPolicyExists_basic("aws_iot_policy.pubsub"),
),
Copy link
Member

Choose a reason for hiding this comment

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

Because we run all acceptance tests nightly in parallel (and because tests sometimes do fail and leave named resources behind, blocking the same test from running again) we need to avoid static names.

Have a look at what we do in other resources, e.g.
https://github.com/terraform-providers/terraform-provider-aws/blob/master/aws/resource_aws_dynamodb_table_test.go#L19

Also do you mind adding a few more checks here? e.g.

resource.TestCheckResourceAttr("aws_iot_policy.pubsub", "name", rName),
resource.TestCheckResourceAttrSet("aws_iot_policy.pubsub", "arn"),
resource.TestCheckResourceAttrSet("aws_iot_policy.pubsub", "default_version_id"),

continue
}

out, err := conn.ListPolicies(&iot.ListPoliciesInput{})
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be easier to call GetPolicy here as we only care about the single policy we created as part of the test in this context?

}

d.Set("arn", out.PolicyArn)
d.Set("defaultVersionId", out.DefaultVersionId)
Copy link
Member

Choose a reason for hiding this comment

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

👀 I think the field name should be default_version_id.

sidebar_current: "docs-aws-resource-iot-policy"
description: |-
Provides an IoT policy.
---
Copy link
Member

Choose a reason for hiding this comment

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

We also need to add a link to the sidebar to make this page discoverable, see https://github.com/terraform-providers/terraform-provider-aws/blob/master/website/aws.erb

return nil
}

func testAccCheckAWSIoTPolicyExists_basic(name string) resource.TestCheckFunc {
Copy link
Member

Choose a reason for hiding this comment

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

We usually leverage helpers like resource.TestCheckResourceAttr and resource.TestCheckResourceAttrSet to check whether the resource was recorded in the state.

The point of having a function like this is to allow more thorough check of the API/SDK struct, take a look how we do it in a VPC test: https://github.com/terraform-providers/terraform-provider-aws/blob/master/aws/resource_aws_vpc_test.go#L25-L26

It's not mandatory to perform such thorough checking, but if you decide not to do it there's no point of having this function when the standard helpers can do the job.

@radeksimko radeksimko added the waiting-response Maintainers are waiting on response from community or contributor. label Jul 18, 2017
Copy link
Member

@radeksimko radeksimko 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 for making those changes.

@radeksimko radeksimko merged commit 4cc7378 into hashicorp:master Jul 19, 2017
@radeksimko radeksimko removed the waiting-response Maintainers are waiting on response from community or contributor. label Jul 19, 2017
@ghost
Copy link

ghost commented Apr 11, 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 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. new-resource Introduces a new resource.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants