-
Notifications
You must be signed in to change notification settings - Fork 51
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 calling REST API endpoints for non-stateful actions #565
Comments
I'm a little naive here but what does |
Hello @jaredfholgate , Thank you for taking time to report this issue. Here's an example of how to use azapi_resource_action resource to perform an HTTP request. resource "azapi_resource_action" "start" {
type = "Microsoft.App/containerApps@2024-03-01"
resource_id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-ai-studio/providers/Microsoft.App/containerApps/ai-studio-project"
action = "start"
body = {
}
}
resource "azapi_resource_action" "scheduleRun" {
type = "Microsoft.ContainerRegistry/registries@2023-07-01"
resource_id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-ai-studio/providers/Microsoft.ContainerRegistry/registries/acr-ai-studio"
action = "scheduleRun"
body = {
type = "EncodedTaskRunRequest"
values = [
{
name = "mytestargument"
value = "mytestvalue"
isSecret = false
},
{
name = "mysecrettestargument"
value = "mysecrettestvalue"
isSecret = true
}
]
platform = {
os = "Linux"
}
agentConfiguration = {
cpu = 2
}
encodedTaskContent = "c3RlcHM6Cnt7IGlmIFZhbHVlcy5lbnZpcm9ubWVudCA9PSAncHJvZCcgfX0KICAtIHJ1bjogcHJvZCBzZXR1cAp7eyBlbHNlIGlmIFZhbHVlcy5lbnZpcm9ubWVudCA9PSAnc3RhZ2luZycgfX0KICAtIHJ1bjogc3RhZ2luZyBzZXR1cAp7eyBlbHNlIH19CiAgLSBydW46IGRlZmF1bHQgc2V0dXAKe3sgZW5kIH19CgogIC0gcnVuOiBidWlsZCAtdCBGYW5jeVRoaW5nOnt7LlZhbHVlcy5lbnZpcm9ubWVudH19LXt7LlZhbHVlcy52ZXJzaW9ufX0gLgoKcHVzaDogWydGYW5jeVRoaW5nOnt7LlZhbHVlcy5lbnZpcm9ubWVudH19LXt7LlZhbHVlcy52ZXJzaW9ufX0nXQ=="
encodedValuesContent = "ZW52aXJvbm1lbnQ6IHByb2QKdmVyc2lvbjogMQ=="
}
}
|
@ms-henglu and @stemaMSFT Perhaps it is just my googling skills, but I don't see a way to trigger a container job manual run via the ARM API? https://learn.microsoft.com/en-us/azure/templates/microsoft.app/jobs?pivots=deployment-language-terraform Given that, then how would it be possible to trigger a run with azapi? I don't believe it can hit the REST API endpoint? Only the ARM API endpoint. It is very possible I am just missing something here, so apologies if that is the case. |
you make a great point, @jaredfholgate that you can't find it within the current AzAPI reference documentation. Resource actions require a synthesis of understanding of the ARM API behavior and the REST API command. The fusion of these two helps you create the exact example you're looking for. |
Hi. I was able to get this working for a container app job using this code: resource "azapi_resource_action" "placeholder_trigger" {
type = "Microsoft.App/jobs@2024-03-01"
resource_id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-h95qg9/providers/Microsoft.App/jobs/my-job"
action = "start"
body = {}
lifecycle {
replace_triggered_by = [ azapi_resource.placeholder ]
}
} Thank you for pointing me in the right direction and apologies for my lack of understanding around this. It makes more sense now, but I think it could potentially be called out more in the docs since it is a fantastic feature. I don't see a reference to the action resource in here? https://learn.microsoft.com/en-us/azure/developer/terraform/overview-azapi-provider The docs here could possibly be clearer on this use case: https://registry.terraform.io/providers/Azure/azapi/latest/docs/resources/azapi_resource_action I do appreciate that the example code shows stopping and starting something, but the description could be expanded a little maybe? Let me know if you'd like me to raise a PR to update the docs, would be happy to. |
I believe I have a PR under review that mentions this. On the other hand, would love if you wanted to contribute to the docs to improve some of the examples regardless. Still wondering if there’s a way for us to autogenerate some examples. |
There are some use cases in that cannot be achieved with the ARM API, but can be achieved with the REST API.
Examples being triggering immediate runs of jobs, such as:
There are REST API endpoints for this and therefore the azurerm provider can support these actions, e.g. https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/container_registry_task_schedule_run_now
In order for azapi to be a full replacement for azurerm, I believe it would need to be able to handle this type of action. I don't believe it can at present, but happy to be corrected on that.
Example endpoints:
The text was updated successfully, but these errors were encountered: