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

azapi supports dynamic schema #446

Merged
merged 7 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions docs/data-sources/azapi_resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ data "azapi_resource" "example" {

// it will output "registry1.azurecr.io"
output "login_server" {
value = jsondecode(data.azapi_resource.example.output).properties.loginServer
value = data.azapi_resource.example.output_payload.properties.loginServer
}

// it will output "disabled"
output "quarantine_policy" {
value = jsondecode(data.azapi_resource.example.output).properties.policies.quarantinePolicy.status
value = data.azapi_resource.example.output_payload.properties.policies.quarantinePolicy.status
}
```

Expand Down Expand Up @@ -86,14 +86,14 @@ The following arguments are supported:

* `response_export_values` - (Optional) A list of path that needs to be exported from response body.
Setting it to `["*"]` will export the full response body.
Here's an example. If it sets to `["properties.loginServer", "properties.policies.quarantinePolicy.status"]`, it will set the following json to computed property `output`.
Here's an example. If it sets to `["properties.loginServer", "properties.policies.quarantinePolicy.status"]`, it will set the HCL object to computed property `output_payload`.
```
{
"properties" : {
"loginServer" : "registry1.azurecr.io"
"policies" : {
"quarantinePolicy" = {
"status" = "disabled"
properties = {
loginServer = "registry1.azurecr.io"
policies = {
quarantinePolicy = {
status = "disabled"
}
}
}
Expand All @@ -110,16 +110,16 @@ In addition to the Arguments listed above - the following Attributes are exporte

* `location` - The Azure Region where the azure resource should exist.

* `output` - The output json containing the properties specified in `response_export_values`. Here're some examples to decode json and extract the value.
* `output_payload` - The output HCL object containing the properties specified in `response_export_values`. Here are some examples to use the values.
```
// it will output "registry1.azurecr.io"
output "login_server" {
value = jsondecode(azapi_resource.example.output).properties.loginServer
value = azapi_resource.example.output_payload.properties.loginServer
}

// it will output "disabled"
output "quarantine_policy" {
value = jsondecode(azapi_resource.example.output).properties.policies.quarantinePolicy.status
value = azapi_resource.example.output_payload.properties.policies.quarantinePolicy.status
}
```

Expand Down
28 changes: 14 additions & 14 deletions docs/data-sources/azapi_resource_action.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ resource "azapi_resource_action" "test" {
type = "Microsoft.Cache@2023-04-01"
resource_id = "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Cache"
action = "CheckNameAvailability"
body = jsonencode({
payload = {
type = "Microsoft.Cache/Redis"
name = "cacheName"
})
}
}
```

Expand All @@ -101,25 +101,25 @@ The following arguments are supported:
* `action` - (Optional) The name of the resource action. It's also possible to make Http requests towards the resource ID if leave this field empty.

---
* `body` - (Optional) A JSON object that contains the request body.
* `payload` - (Optional) A dynamic attribute that contains the request body.

* `method` - (Optional) Specifies the Http method of the azure resource action. Allowed values are `POST` and `GET`. Defaults to `POST`.

* `response_export_values` - (Optional) A list of path that needs to be exported from response body.
Setting it to `["*"]` will export the full response body.
Here's an example. If it sets to `["keys"]`, it will set the following json to computed property `output`.
Here's an example. If it sets to `["keys"]`, it will set the following HCL object to computed property `output_payload`.
```
{
"keys": [
keys = [
{
"KeyName": "Primary",
"Permissions": "Full",
"Value": "nHGYNd******i4wdug=="
KeyName = "Primary"
Permissions = "Full"
Value = "nHGYNd******i4wdug=="
},
{
"KeyName": "Secondary",
"Permissions": "Full",
"Value": "6yoCad******SLzKzg=="
KeyName = "Secondary"
Permissions = "Full"
Value = "6yoCad******SLzKzg=="
}
]
}
Expand All @@ -131,16 +131,16 @@ In addition to the Arguments listed above - the following Attributes are exporte

* `id` - The ID of the azure resource action.

* `output` - The output json containing the properties specified in `response_export_values`. Here are some examples to decode json and extract the value.
* `output` - The output HCL object containing the properties specified in `response_export_values`. Here are some examples to use the values.
```hcl
// it will output "nHGYNd******i4wdug=="
output "primary_key" {
value = jsondecode(azapi_resource_action.test.output).keys.0.Value
value = azapi_resource_action.test.output_payload.keys.0.Value
}

// it will output "6yoCad******SLzKzg=="
output "secondary_key" {
value = jsondecode(azapi_resource_action.test.output).keys.1.Value
value = azapi_resource_action.test.output_payload.keys.1.Value
}
```

Expand Down
14 changes: 7 additions & 7 deletions docs/data-sources/azapi_resource_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ The following arguments are supported:

* `response_export_values` - (Optional) A list of path that needs to be exported from response body.
Setting it to `["*"]` will export the full response body.
Here's an example. If it sets to `["value"]`, it will set the following json to computed property `output`.
Here's an example. If it sets to `["value"]`, it will set the following HCL object to computed property `output_payload`.
```
{
"value": [
value = [
{
"id": "id1",
"Permissions": "Full"
id = "id1"
Permissions = "Full"
},
{
"id": "id2",
"Permissions": "Full"
id = "id2"
Permissions = "Full"
}
]
}
Expand All @@ -79,7 +79,7 @@ In addition to the Arguments listed above - the following Attributes are exporte

* `id` - The ID of the azure resource list.

* `output` - The output json containing the properties specified in `response_export_values`. Here are some examples to decode json and extract the value.
* `output_payload` - The output HCL object containing the properties specified in `response_export_values`. Here are some examples to use the values.


## Timeouts
Expand Down
19 changes: 9 additions & 10 deletions docs/resources/azapi_data_plane_resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ resource "azapi_data_plane_resource" "dataset" {
type = "Microsoft.Synapse/workspaces/datasets@2020-12-01"
parent_id = trimprefix(data.azurerm_synapse_workspace.example.connectivity_endpoints.dev, "https://")
name = "example-dataset"
body = jsonencode({
payload = {
properties = {
type = "AzureBlob",
typeProperties = {
Expand All @@ -62,7 +62,7 @@ resource "azapi_data_plane_resource" "dataset" {
}
}
}
})
}
}

```
Expand All @@ -79,13 +79,13 @@ The following arguments are supported:

-> **Note** For the available resource types and parent IDs, please refer to the `Available Resources` section below.

* `body` - (Required) A JSON object that contains the request body used to create and update data plane resource.
* `payload` - (Required) A dynamic attribute that contains the request body used to create and update data plane resource.

---

* `response_export_values` - (Optional) A list of path that needs to be exported from response body.
Setting it to `["*"]` will export the full response body.
Here's an example. If it sets to `["properties.loginServer", "properties.policies.quarantinePolicy.status"]`, it will set the following json to computed property `output`.
Here's an example. If it sets to `["properties.loginServer", "properties.policies.quarantinePolicy.status"]`, it will set the following HCL object to computed property `output_payload`.
```
{
"properties" : {
Expand All @@ -101,26 +101,25 @@ The following arguments are supported:

* `locks` - (Optional) A list of ARM resource IDs which are used to avoid create/modify/delete azapi resources at the same time.

* `ignore_casing` - (Optional) Whether ignore incorrect casing returned in `body` to suppress plan-diff. Defaults to `false`.

* `ignore_missing_property` - (Optional) Whether ignore not returned properties like credentials in `body` to suppress plan-diff. Defaults to `true`.
* `ignore_missing_property` - (Optional) Whether ignore not returned properties like credentials in `payload` to suppress plan-diff. Defaults to `true`.
It's recommend to enable this option when some sensitive properties are not returned in response body, instead of setting them in `lifecycle.ignore_changes` because it will make the sensitive fields unable to update.

## Attributes Reference

In addition to the Arguments listed above - the following Attributes are exported:

* `id` - The ID of the azure resource.

* `output` - The output json containing the properties specified in `response_export_values`. Here're some examples to decode json and extract the value.
* `output_payload` - The output HCL object containing the properties specified in `response_export_values`. Here are some examples to use the values.
```
// it will output "registry1.azurecr.io"
output "login_server" {
value = jsondecode(azapi_data_plane_resource.example.output).properties.loginServer
value = azapi_data_plane_resource.example.output_payload.properties.loginServer
}

// it will output "disabled"
output "quarantine_policy" {
value = jsondecode(azapi_data_plane_resource.example.output).properties.policies.quarantinePolicy.status
value = azapi_data_plane_resource.example.output_payload.properties.policies.quarantinePolicy.status
}
```

Expand Down
37 changes: 17 additions & 20 deletions docs/resources/azapi_resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ resource "azapi_resource" "example" {
identity_ids = [azurerm_user_assigned_identity.example.id]
}

body = jsonencode({
payload = {
sku = {
name = "Standard"
}
properties = {
adminUserEnabled = true
}
})
}

tags = {
"Key" = "Value"
Expand All @@ -69,12 +69,12 @@ resource "azapi_resource" "example" {

// it will output "registry1.azurecr.io"
output "login_server" {
value = jsondecode(azapi_resource.example.output).properties.loginServer
value = azapi_resource.example.output_payload.properties.loginServer
}

// it will output "disabled"
output "quarantine_policy" {
value = jsondecode(azapi_resource.example.output).properties.policies.quarantinePolicy.status
value = azapi_resource.example.output_payload.properties.policies.quarantinePolicy.status
}
```

Expand All @@ -96,7 +96,7 @@ The following arguments are supported:
* `type` - (Required) It is in a format like `<resource-type>@<api-version>`. `<resource-type>` is the Azure resource type, for example, `Microsoft.Storage/storageAccounts`.
`<api-version>` is version of the API used to manage this azure resource.

* `body` - (Required) A JSON object that contains the request body used to create and update azure resource.
* `payload` - (Required) A dynamic attribute that contains the request body used to create and update azure resource.

* `removing_special_chars` - (Optional) Whether to remove special characters in resource name. Defaults to `false`.

Expand All @@ -110,14 +110,14 @@ The following arguments are supported:

* `response_export_values` - (Optional) A list of path that needs to be exported from response body.
Setting it to `["*"]` will export the full response body.
Here's an example. If it sets to `["properties.loginServer", "properties.policies.quarantinePolicy.status"]`, it will set the following json to computed property `output`.
Here's an example. If it sets to `["properties.loginServer", "properties.policies.quarantinePolicy.status"]`, it will set the following HCL object to computed property `output_payload`.
```
{
"properties" : {
"loginServer" : "registry1.azurecr.io"
"policies" : {
"quarantinePolicy" = {
"status" = "disabled"
properties = {
loginServer = "registry1.azurecr.io"
policies = {
quarantinePolicy = {
status = "disabled"
}
}
}
Expand All @@ -126,13 +126,10 @@ The following arguments are supported:

* `locks` - (Optional) A list of ARM resource IDs which are used to avoid create/modify/delete azapi resources at the same time.

* `ignore_casing` - (Optional) Whether ignore incorrect casing returned in `body` to suppress plan-diff. Defaults to `false`.

* `ignore_body_changes` - (Optional) A list of properties that should be ignored when comparing the `body` with its current state.

* `ignore_missing_property` - (Optional) Whether ignore not returned properties like credentials in `body` to suppress plan-diff. Defaults to `true`.
* `ignore_missing_property` - (Optional) Whether ignore not returned properties like credentials in `payload` to suppress plan-diff. Defaults to `true`.
It's recommend to enable this option when some sensitive properties are not returned in response body, instead of setting them in `lifecycle.ignore_changes` because it will make the sensitive fields unable to update.

* `schema_validation_enabled` - (Optional) Whether enabled the validation on `type` and `body` with embedded schema. Defaults to `true`.
* `schema_validation_enabled` - (Optional) Whether enabled the validation on `type` and `payload` with embedded schema. Defaults to `true`.

---

Expand All @@ -151,16 +148,16 @@ In addition to the Arguments listed above - the following Attributes are exporte

* `identity` - An `identity` block as defined below, which contains the Managed Service Identity information for this azure resource.

* `output` - The output json containing the properties specified in `response_export_values`. Here're some examples to decode json and extract the value.
* `output_payload` - The output HCL object containing the properties specified in `response_export_values`. Here are some examples use the values.
```
// it will output "registry1.azurecr.io"
output "login_server" {
value = jsondecode(azapi_resource.example.output).properties.loginServer
value = azapi_resource.example.output_payload.properties.loginServer
}

// it will output "disabled"
output "quarantine_policy" {
value = jsondecode(azapi_resource.example.output).properties.policies.quarantinePolicy.status
value = azapi_resource.example.output_payload.properties.policies.quarantinePolicy.status
}
```

Expand Down
28 changes: 14 additions & 14 deletions docs/resources/azapi_resource_action.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ data "azapi_resource_action" "test" {
type = "Microsoft.ResourceGraph@2020-04-01-preview"
resource_id = "/providers/Microsoft.ResourceGraph"
action = "resources"
body = jsonencode({
payload = {
query = "resources| where name contains \"test\""
})
}
response_export_values = ["*"]
}
```
Expand All @@ -121,28 +121,28 @@ The following arguments are supported:

---

* `body` - (Optional) A JSON object that contains the request body.
* `payload` - (Optional) A dynamic attribute that contains the request body.

* `locks` - (Optional) A list of ARM resource IDs which are used to avoid modify azapi resources at the same time.

* `method` - (Optional) Specifies the Http method of the azure resource action. Allowed values are `POST`, `PATCH`, `PUT` and `DELETE`. Defaults to `POST`.

* `response_export_values` - (Optional) A list of path that needs to be exported from response body.
Setting it to `["*"]` will export the full response body.
Here's an example. If it sets to `["keys"]`, it will set the following json to computed property `output`.
Here's an example. If it sets to `["keys"]`, it will set the following HCL object to computed property `output_payload`.

```
{
"keys": [
keys = [
{
"KeyName": "Primary",
"Permissions": "Full",
"Value": "nHGYNd******i4wdug=="
KeyName = "Primary"
Permissions = "Full"
Value = "nHGYNd******i4wdug=="
},
{
"KeyName": "Secondary",
"Permissions": "Full",
"Value": "6yoCad******SLzKzg=="
KeyName = "Secondary"
Permissions = "Full"
Value = "6yoCad******SLzKzg=="
}
]
}
Expand All @@ -156,17 +156,17 @@ In addition to the Arguments listed above - the following Attributes are exporte

* `id` - The ID of the azure resource action.

* `output` - The output json containing the properties specified in `response_export_values`. Here are some examples to decode json and extract the value.
* `output_payload` - The HCL object containing the properties specified in `response_export_values`. Here are some examples to use the values.

```hcl
// it will output "nHGYNd******i4wdug=="
output "primary_key" {
value = jsondecode(azapi_resource_action.test.output).keys.0.Value
value = azapi_resource_action.test.output_payload.keys.0.Value
}

// it will output "6yoCad******SLzKzg=="
output "secondary_key" {
value = jsondecode(azapi_resource_action.test.output).keys.1.Value
value = azapi_resource_action.test.output_payload.keys.1.Value
}
```

Expand Down
Loading
Loading