-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Add support for batch_job_definition and batch_job_queue #1710
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ashinohara
thanks for crafting this!
I left you some comments in the code, some are more important than others, I hope they all make sense though.
Let me know if you have any questions.
The PR otherwise looks pretty good and fairly close to shippable state.
Type: schema.TypeString, | ||
Optional: true, | ||
ForceNew: true, | ||
StateFunc: func(v interface{}) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you add this StateFunc just to suppress the JSON formatting differences in plan
? If so, then we have a little bit more elegant solution which doesn't hide the JSON from the plan:
https://github.com/terraform-providers/terraform-provider-aws/blob/90d698c66db80d676e2db197be97c1a9977e5393/aws/resource_aws_cloudwatch_dashboard.go#L36-L40
Whether the user wants to see full JSON in the plan is questionable, but it seems some folks find it useful and it would be nice to avoid breaking change later on, like here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that was the intent. Thanks for pointing me to that function.
Elem: schema.TypeString, | ||
}, | ||
"retry_strategy": { | ||
Type: schema.TypeSet, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any particular reason this field should be TypeSet
and not TypeList
? We could make it easier to reference with TypeList
, i.e. retry_strategy.0.attempts
, instead of retry_strategy.<computed-hash>.attempts
.
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason why revision
and arn
should be Optional
? I don't see them being used anywhere in the CRUD other than in Set()
which makes me think they should be Computed
-only... 🤔
if err != nil { | ||
return fmt.Errorf("%s %q", err, arn) | ||
} | ||
d.Set("arn", *job.JobDefinitionArn) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We tend to avoid dereferencing simple data types in this context as we burnt our fingers in the past by doing that - i.e. API returned empty field which then caused a crash due to nil dereferencing.
The Set
function is capable of safe dereferencing, so we can just let it do the job. 😉
https://github.com/hashicorp/terraform/blob/d78b575536ddf862946521e03b3c57402e3201be/helper/schema/resource_data.go#L169-L185
TL;DR just pass the pointer.
} | ||
d.Set("arn", *job.JobDefinitionArn) | ||
d.Set("container_properties", *job.ContainerProperties) | ||
d.Set("parameters", job.Parameters) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we'll need to convert the map[string]*string
to map[string]string
here. Feel free to use the SDK helper aws.StringValueMap
.
aws/resource_aws_batch_job_queue.go
Outdated
Priority: aws.Int64(int64(d.Get("priority").(int))), | ||
State: aws.String(d.Get("state").(string)), | ||
} | ||
_, err := conn.UpdateJobQueue(updateInput) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we also wait here for the job until it goes from batch.JQStatusUpdating
to batch.JQStatusValid
?
aws/resource_aws_batch_job_queue.go
Outdated
return nil | ||
} | ||
|
||
func createComputeEnvironmentOrder(d *schema.ResourceData) (envs []*batch.ComputeEnvironmentOrder) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a nitpick, but the interface here seems to be quite greedy - any reason we can't just pass an []interface{}
and call d.Get()
outside of this function since it only needs access to a single field, not all ResourceData?
aws/resource_aws_batch_job_queue.go
Outdated
return nil | ||
} | ||
return resource.RetryableError(err) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any particular reason why this should fail and/or why we should retry? Can we retry on a specific error code, instead of any error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also if we really need the retry logic, then we should also catch the err
coming from it - right now it seems to be shadowed on line 152.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was using it to wait until the Job Queue was disabled, but I think a more elegant solution is to use WaitForState
. I am working on that change.
aws/validators.go
Outdated
value := v.(string) | ||
if !(regexp.MustCompile(`^[A-Za-z0-9_]*$`).MatchString(value) && len(value) <= 128) { | ||
errors = append(errors, fmt.Errorf("computeEnvironmentName must be up to 128 letters (uppercase and lowercase), numbers, and underscores.")) | ||
errors = append(errors, fmt.Errorf("Name must be up to 128 letters (uppercase and lowercase), numbers, and underscores.")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have raised https://github.com/terraform-providers/terraform-provider-aws/pull/1760/files to address the generic-ness of this function - I agree it can be still renamed, but either way - do you mind rebasing?
|
||
```hcl | ||
resource "aws_batch_job_definition" "test" { | ||
name = "tf-test-batch-job-definition" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should replace hyphens with underscores here, per validation function.
ce4a18a
to
7bb5184
Compare
@radeksimko Thank you very much for your insightful review. I believe I have addressed all of your comments and made sure that tests are still passing. Let me know if there is anything else you would like me to change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing my comments.
}, | ||
"revision": { | ||
Type: schema.TypeInt, | ||
Optional: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The revision
here is still Optional
, but I will take care of that prior to merging.
Hi, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pat-nomalab Check my comment. With that change destroy will work correctly.
_, err = conn.DeleteJobQueue(&batch.DeleteJobQueueInput{ | ||
JobQueue: aws.String(sn), | ||
}) | ||
if err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ashinohara This is probably bug and it should be:
if err !=nil {
return err
}
Otherwise it's not possible to run destroy because compute environment couldn't be deleted with JobQueue defined.
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! |
Description
Adding resources
aws_batch_job_definition
andaws_batch_job_queue
.Additionally, I found an issue with some of the tests for
aws_batch_compute_environment
which seems to be a condition where theaws_iam_role_policy_attachment
gets deleted before the compute environment and causes theaws_batch_compute_environment
to be a dangling resource. I have added a note in the documentation about it, and have also fixed the tests by adding adepends_on
link in theaws_batch_compute_environment
to theaws_iam_role_policy_attachment
.Tests