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_glue_trigger #4464

Merged
merged 2 commits into from
May 22, 2018
Merged

New Resource: aws_glue_trigger #4464

merged 2 commits into from
May 22, 2018

Conversation

bflad
Copy link
Contributor

@bflad bflad commented May 6, 2018

Closes #3882

make testacc TEST=./aws TESTARGS='-run=TestAccAWSGlueTrigger'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSGlueTrigger -timeout 120m
=== RUN   TestAccAWSGlueTrigger_Basic
--- PASS: TestAccAWSGlueTrigger_Basic (9.86s)
=== RUN   TestAccAWSGlueTrigger_Description
--- PASS: TestAccAWSGlueTrigger_Description (11.44s)
=== RUN   TestAccAWSGlueTrigger_Enabled
--- PASS: TestAccAWSGlueTrigger_Enabled (51.44s)
=== RUN   TestAccAWSGlueTrigger_Predicate
--- PASS: TestAccAWSGlueTrigger_Predicate (47.30s)
=== RUN   TestAccAWSGlueTrigger_Schedule
--- PASS: TestAccAWSGlueTrigger_Schedule (48.42s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	168.495s

@bflad bflad added new-resource Introduces a new resource. service/glue Issues and PRs that pertain to the glue service. labels May 6, 2018
@bflad bflad added this to the v1.18.0 milestone May 6, 2018
@bflad bflad requested a review from a team May 6, 2018 19:30
@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label May 6, 2018
@bflad bflad modified the milestones: v1.18.0, v1.19.0 May 10, 2018
@bflad bflad modified the milestones: v1.19.0, v1.20.0 May 17, 2018
Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

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

a bunch of mostly minor comments - but this otherwise LGTM 👍

"actions": {
Type: schema.TypeList,
Required: true,
MinItems: 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

this is implied, since it's required

Copy link
Contributor Author

Choose a reason for hiding this comment

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

MinItems: 1 is not implied by Required: true on schema.TypeList

Given the below configuration and removing MinItems: 1 in the schema, it allows the 0 element list to pass through and error in the API:

resource "aws_glue_trigger" "test" {
  name = "%s"
  type = "ON_DEMAND"

  actions = []
}
	testing.go:518: Step 0 error: Error applying: 1 error(s) occurred:

		* aws_glue_trigger.test: 1 error(s) occurred:

		* aws_glue_trigger.test: error creating Glue Trigger (tf-acc-test-123ih): InvalidInputException: Actions cannot be null or empty
			status code: 400, request id: f6ad3e4b-5de6-11e8-9ff4-73cc05d78525

Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.NoZeroValues,
Copy link
Contributor

Choose a reason for hiding this comment

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

off-topic: it feels like this should be set by default in TF Core when a fields required?

Copy link
Contributor

Choose a reason for hiding this comment

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

minor we generally sort Required -> Optional -> Computed in the schema

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it feels like this should be set by default in TF Core when a fields required?

Some resource attributes (not here) use "" to denote removing or zero-ing out something currently. When Terraform 0.12 is released, maybe we can become more strict, but for now the validation is required.

we generally sort Required -> Optional -> Computed in the schema

Yikes, there are probably hundreds of AWS resources that need to be updated then. It would be nice if there was documentation or linting for this.

},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(5 * time.Minute),
Delete: schema.DefaultTimeout(5 * time.Minute),
Copy link
Contributor

Choose a reason for hiding this comment

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

what about updating?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently the resource does not wait for updates so there's no timeout to configure. Acceptance testing so far has not triggered any issues with the enabled attribute on import which seems to imply updates are happening instantly (for now).

"conditions": {
Type: schema.TypeList,
Required: true,
MinItems: 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

(as above)

log.Printf("[DEBUG] Reading Glue Trigger: %s", input)
output, err := conn.GetTrigger(input)
if err != nil {
if isAWSErr(err, glue.ErrCodeEntityNotFoundException, "") {
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 are we missing a generic "is not found" function? we added this in the AzureRM Provider to work around crashes when the connection dropped

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Luckily, we don't get crashes from the SDK in these situations. The SDK will bubble up some sort of networking error (I believe always RequestError), which is related to handling like this I just added: https://github.com/terraform-providers/terraform-provider-aws/blob/master/aws/config.go#L354-L372

As for a generic "is not found" function -- all the AWS service APIs return something different in this regard (status codes and error codes, some services have error codes for each different resource as well), so unfortunately it would probably be more trouble than its worth to try and create a single function to handle that.

func flattenGlueActions(actions []*glue.Action) []interface{} {
l := []interface{}{}

for _, action := range actions {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add some crash protection here incase actions is nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not believe anything is required here: https://play.golang.org/p/-ShUuLbE9cc

func flattenGlueConditions(conditions []*glue.Condition) []interface{} {
l := []interface{}{}

for _, condition := range conditions {
Copy link
Contributor

Choose a reason for hiding this comment

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

(same here)


input := &glue.GetTriggersInput{}
err = conn.GetTriggersPages(input, func(page *glue.GetTriggersOutput, lastPage bool) bool {
if len(page.Triggers) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

what if page is nil though?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch -- will update 👍


# aws_glue_trigger

Provides a Glue Job resource.
Copy link
Contributor

Choose a reason for hiding this comment

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

minor Provides -> Manages

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

Glue Triggers can be imported using `name`, e.g.

```
$ terraform import aws_glue_trigger.MyTrigger Myrigger
Copy link
Contributor

Choose a reason for hiding this comment

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

Myrigger -> MyTrigger

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label May 22, 2018
@bflad
Copy link
Contributor Author

bflad commented May 22, 2018

Acceptance testing still passes after resource code update -- merging!

make testacc TEST=./aws TESTARGS='-run=TestAccAWSGlueTrigger'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSGlueTrigger -timeout 120m
=== RUN   TestAccAWSGlueTrigger_Basic
--- PASS: TestAccAWSGlueTrigger_Basic (18.29s)
=== RUN   TestAccAWSGlueTrigger_Description
--- PASS: TestAccAWSGlueTrigger_Description (25.88s)
=== RUN   TestAccAWSGlueTrigger_Enabled
--- PASS: TestAccAWSGlueTrigger_Enabled (71.09s)
=== RUN   TestAccAWSGlueTrigger_Predicate
--- PASS: TestAccAWSGlueTrigger_Predicate (60.66s)
=== RUN   TestAccAWSGlueTrigger_Schedule
--- PASS: TestAccAWSGlueTrigger_Schedule (61.78s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	237.741s

@bflad bflad merged commit 6aeeb4d into master May 22, 2018
@bflad bflad deleted the f-aws_glue_trigger branch May 22, 2018 18:24
bflad added a commit that referenced this pull request May 22, 2018
@bflad
Copy link
Contributor Author

bflad commented May 23, 2018

This has been released in version 1.20.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 5, 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 5, 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/glue Issues and PRs that pertain to the glue 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.

Feature Request: Resource for managing AWS Glue Triggers
2 participants