-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Support for Azure Batch - Pool #2461
Conversation
@jcorioland thanks for splitting this out :) Given this is dependent on #2427 - just to let you know I'm going to take a look through the commit specific to this PR, rather than attempting to re-review the bits present in the other PR (to hopefully avoids any conflicts) |
…provider-azurerm into feat/batch-pool
…provider-azurerm into feat/batch-pool
…provider-azurerm into feat/batch-pool
@jcorioland I've merged master into this branch so those changes don't appear in the diff now that the other PR's been merged, I hope you don't mind |
@tombuildsstuff nope, this is perfect, thank you. What do you think about? Better to do it in this PR or a new one? |
…vider-azurerm into feat/batch-pool
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.
Thank you for the resource! I've left some comments inline and its off to a good start. My main concern is that i think the autoscale settings should be moved into sub blocks to match the API, as well as allow for some simpler logic.
With regards to the Start Task i think it should be a sub block in this resource. It could be part of this PR or another 🙂
azurerm/data_source_batch_pool.go
Outdated
}, | ||
"storage_image_reference": { | ||
Type: schema.TypeSet, | ||
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.
I believe we can remove this as it's a datasource?
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.
OK.
azurerm/data_source_batch_pool.go
Outdated
Type: schema.TypeSet, | ||
Optional: true, | ||
Computed: true, | ||
ForceNew: 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.
I believe we can remove this as it's a datasource?
ForceNew: 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.
OK.
azurerm/data_source_batch_pool.go
Outdated
Optional: true, | ||
Computed: true, | ||
ForceNew: true, | ||
MaxItems: 1, |
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 believe we can remove this as it's a datasource?
MaxItems: 1, |
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.
OK.
azurerm/data_source_batch_pool.go
Outdated
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Type: schema.TypeString, | ||
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.
Should the ForceNew be removed and optional changed to Computed?
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.
Yep, it should. Done.
azurerm/data_source_batch_pool.go
Outdated
|
||
"offer": { | ||
Type: schema.TypeString, | ||
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.
Should the ForceNew be removed and optional changed to Computed?
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.
Yep it should. Done.
vm_size = "Standard_A1" | ||
scale_mode = "Fixed" | ||
target_dedicated_nodes = 2 | ||
node_agent_sku_id = "batch.node.ubuntu 16.04" |
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.
Could we fix the alignment 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.
Done.
scale_mode = "Auto" | ||
autoscale_evaluation_interval = "PT15M" | ||
autoscale_formula = <<EOF | ||
startingNumberOfVMs = 1; |
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.
Could we fix the assignment alignment 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.
Done.
examples/batch/main.tf
Outdated
resource_group_name = "${azurerm_resource_group.rg.name}" | ||
account_name = "${azurerm_batch_account.batch.name}" | ||
display_name = "Fixed Scale Pool" | ||
vm_size = "Standard_A1" |
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.
Could we run terraform ft on this file to fix the alignment? you can just point it at the folder and it'll find and fmt all terraform files 🙂
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.
Done.
} | ||
|
||
resource "azurerm_batch_pool" "test" { | ||
name = "testaccpool" |
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.
Could we fix the alignment 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.
Done.
|
||
* `autoscale_formula` - The formula used to autoscale the pool when using scale mode `Auto`. | ||
|
||
* `storage_image_reference` - The reference of the storage image used by the nodes in the Batch pool. |
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.
Could we add an import section 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.
Done.
@katbyte - Thanks for the review. I've done some refactoring and most of the changes you've asked for are done. |
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.
hey @jcorioland
Thanks for pushing those changes - I've taken a look though and left some comments inline, in general this is off to a good start but I've got some questions/thoughts around the design of the schema (such as making things Lists rather than Sets)
Thanks!
azurerm/data_source_batch_pool.go
Outdated
Required: true, | ||
ValidateFunc: azure.ValidateAzureRMBatchPoolName, | ||
}, | ||
"resource_group_name": resourceGroupNameDiffSuppressSchema(), |
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.
unfortunately whilst this is case insensitive in some Azure API's - in others (where these ID's can be use) they're not; as such we treat Resource Group Name's as case sensitive - and we need to update this to be case-sensitive:
"resource_group_name": resourceGroupNameDiffSuppressSchema(), | |
"resource_group_name": resourceGroupNameForDataSourceSchema(), |
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.
Ok, got it. Thanks for the explanation.
azurerm/data_source_batch_pool.go
Outdated
}, | ||
"fixed_scale": azure.SchemaBatchPoolFixedScaleForDataSource(), | ||
"auto_scale": azure.SchemaBatchPoolAutoScaleForDataSource(), | ||
"storage_image_reference": azure.SchemaBatchPoolImageReferenceForDataSource(), |
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.
since these are only used in a single place (and unlikely to be used outside of this resource) - we can define these in-line rather than splitting these out
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.
Ok.
azurerm/data_source_batch_pool.go
Outdated
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"start_task": azure.SchemaBatchPoolStartTaskForDataSource(), |
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.
(same 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.
Ok.
azurerm/data_source_batch_pool.go
Outdated
d.Set("name", name) | ||
d.Set("account_name", accountName) | ||
d.Set("resource_group_name", resourceGroup) | ||
d.Set("vm_size", resp.VMSize) |
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.
since these properties are present at properties
in the response, can we access them via:
if props := resp.PoolProperties; props != nil {
d.Set("vm_size", props.VMSize)
// ...
}
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. I am curious about the exact reason behind this?
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 Azure API returns the representation of a resource at the last time it was modified; meaning if it’s not been modified in a while (for example if it was made during a Preview API) the structure returned from the API may not necessarily match the result we expect. As such we ensure we access these fields in the Properties block, since that’s where we expect them
azurerm/data_source_batch_pool.go
Outdated
d.Set("resource_group_name", resourceGroup) | ||
d.Set("vm_size", resp.VMSize) | ||
|
||
if resp.ScaleSettings != 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.
(same here) we should be able to make this:
if props := ...; props != nil {
if settings := props.ScaleSettings; settings != nil {
if err := d.Set("auto_scale", flattenBatchPoolAutoScaleSettings(settings.AutoScale)); err != nil {
return fmt.Errorf("Error flattening `auto_scale`: %+v", err)
}
if err := d.Set("fixed_scale", flattenBatchPoolFixedScaleSettings(settings.FixedScale)); err != nil {
return fmt.Errorf("Error flattening `fixed_scale `: %+v", err)
}
}
}
in this updated snippet we also handle settings.AutoScale
and settings.FixedScale
being nil within the flatten function and return an empty list if that's the case
azurerm/resource_arm_batch_pool.go
Outdated
d.Set("resource_group_name", resourceGroup) | ||
d.Set("vm_size", resp.VMSize) | ||
|
||
if resp.ScaleSettings != 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.
(as above) can we access these within the properties
block e.g.
if props := resp.PoolProperties; props != nil {
// ...
}
azurerm/resource_arm_batch_pool.go
Outdated
TargetLowPriorityNodes: &targetLowPriorityNodes, | ||
} | ||
} else { | ||
return nil, fmt.Errorf("Error: scale mode should be either AutoScale of FixedScale") |
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.
this is covered above - so we should be able to remove this else
block here?
examples/batch/main.tf
Outdated
# client_id = "..." | ||
# client_secret = "..." | ||
# tenant_id = "..." | ||
# if you're using a Service Principal (shared account) then either set the environment variables, or fill these in: # subscription_id = "..." # client_id = "..." # client_secret = "..." # tenant_id = "..." |
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.
can we put this back on multiple lines?
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.
for the record, terraform fmt
inline the comments :-)
examples/batch/main.tf
Outdated
pendingTaskSamples = pendingTaskSamplePercent < 70 ? startingNumberOfVMs : avg($PendingTasks.GetSample(180 * TimeInterval_Second)); | ||
$TargetDedicatedNodes=min(maxNumberofVMs, pendingTaskSamples); | ||
EOF |
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.
for this to be detected correctly the EOF
needs to be at the start of the line here:
EOF | |
EOF |
pendingTaskSamplePercent = $PendingTasks.GetSamplePercent(180 * TimeInterval_Second); | ||
pendingTaskSamples = pendingTaskSamplePercent < 70 ? startingNumberOfVMs : avg($PendingTasks.GetSample(180 * TimeInterval_Second)); | ||
$TargetDedicatedNodes=min(maxNumberofVMs, pendingTaskSamples); | ||
EOF |
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.
(as above) this needs to be at the start of the line to take effect:
EOF | |
EOF |
@tombuildsstuff @katbyte - I've done updates after Tom's review. I have issues with the acceptance tests now. They all end with the following error:
I am not sure of what happens exactly, if you have any clue that would be really helpful. Thanks! |
It appears to be a casing issue with |
@katbyte thanks a lot, making the |
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 @jcorioland,
I've tried running the tests again and gotten this error:
------- Stdout: -------
=== RUN TestAccAzureRMBatchPool_autoScale_complete
=== PAUSE TestAccAzureRMBatchPool_autoScale_complete
=== CONT TestAccAzureRMBatchPool_autoScale_complete
--- FAIL: TestAccAzureRMBatchPool_autoScale_complete (853.77s)
testing.go:538: Step 0 error: After applying this step, the plan was not empty:
DIFF:
UPDATE: azurerm_batch_pool.test
auto_scale.0.formula: "startingNumberOfVMs = 1;\n maxNumberofVMs = 25;\n pendingTaskSamplePercent = $PendingTasks.GetSamplePercent(180 * TimeInterval_Second);\n pendingTaskSamples = pendingTaskSamplePercent < 70 ? startingNumberOfVMs : avg($PendingTasks.GetSample(180 * TimeInterval_Second));\n $TargetDedicatedNodes=min(maxNumberofVMs, pendingTaskSamples);" => " startingNumberOfVMs = 1;\n maxNumberofVMs = 25;\n pendingTaskSamplePercent = $PendingTasks.GetSamplePercent(180 * TimeInterval_Second);\n pendingTaskSamples = pendingTaskSamplePercent < 70 ? startingNumberOfVMs : avg($PendingTasks.GetSample(180 * TimeInterval_Second));\n $TargetDedicatedNodes=min(maxNumberofVMs, pendingTaskSamples);\n"
FAIL
The difference:
"startingNumberOfVMs = 1;\n maxNumberofVMs = 25;\n pendingTaskSamplePercent = $PendingTasks.GetSamplePercent(180 * TimeInterval_Second);\n pendingTaskSamples = pendingTaskSamplePercent < 70 ? startingNumberOfVMs : avg($PendingTasks.GetSample(180 * TimeInterval_Second));\n $TargetDedicatedNodes=min(maxNumberofVMs, pendingTaskSamples);"
" startingNumberOfVMs = 1;\n maxNumberofVMs = 25;\n pendingTaskSamplePercent = $PendingTasks.GetSamplePercent(180 * TimeInterval_Second);\n pendingTaskSamples = pendingTaskSamplePercent < 70 ? startingNumberOfVMs : avg($PendingTasks.GetSample(180 * TimeInterval_Second));\n $TargetDedicatedNodes=min(maxNumberofVMs, pendingTaskSamples);\n"
It seems the API is trimming the value and adding a newline to the end, might best to add a suppress diff function to this property. Also i noticed a bunch of other properties don't have any validation, it would be great to add some in.
Type: schema.TypeInt, | ||
Optional: true, | ||
Default: 1, | ||
}, |
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.
Could we get some validation 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.
OK.
azurerm/resource_arm_batch_pool.go
Outdated
"target_low_priority_nodes": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Default: 0, |
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.
Could we get some validation 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.
OK.
"id": { | ||
Type: schema.TypeString, | ||
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.
Could we validate the ID: azure.ValidateResourceID
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: 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.
Could we get at least a validate.NoEmptyStrings
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.
OK.
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: 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.
Could we get at least a validate.NoEmptyStrings
here?
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: 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.
Could we get at least a validate.NoEmptyStrings
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.
OK.
Required: true, | ||
ForceNew: true, | ||
DiffSuppressFunc: suppress.CaseDifference, | ||
}, |
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.
Could we get at least a validate.NoEmptyStrings
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.
OK.
Type: schema.TypeString, | ||
Optional: true, | ||
ForceNew: 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.
Could we get at least a validate.NoEmptyStrings
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.
OK.
"command_line": { | ||
Type: schema.TypeString, | ||
Required: 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.
Could we get at least a validate.NoEmptyStrings
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.
OK.
|
||
"user_identity": { | ||
Type: schema.TypeList, | ||
Required: 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.
Should this we required when all the sub properties are optional?
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 not sure for this one: user identity is mandatory, but you should specify either a user name or an auto identity. This is why I put the user_identity
block mandatory but the two properties inside optional. What the best way to handle that? Adding some extra validation to the user_identity
block to check that at least one type of identity has been specified?
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.
If one of those values is required i would add an additional check & document it in the create/update functions for now.
Hi @katbyte @tombuildsstuff - Happy New Year! I've added some validations, except for the Thank you |
Happy new year @jcorioland! Thanks for the commits. If one of those values is required i would add a check for it into the create/update functions. A |
@katbyte thanks! I've just added validation for user identity. Should be good now. |
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 @jcorioland! LGTM now 🙂
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. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks! |
This PR brings support for Azure Batch Pool.
Fixes #2427 and #2458
Depends on #2428
Azure Batch Pool: