Skip to content
Draft
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
138 changes: 138 additions & 0 deletions docs/resources/general_resource.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
---
page_title: "azapi_general_resource Resource - terraform-provider-azapi"
subcategory: ""
description: |-
This resource can manage general resources.
---

# azapi_general_resource (Resource)

This resource can manage general resources.



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `url` (String) The URL of the data plane resource. Must include `https://`, e.g. `https://my-keyvault.vault.azure.net/secrets/test-secret/b15f7ed819404dd0b28debe0aa711a54`.

### Optional

- `api_version` (String) The API version to use for the data plane resource. If not specified, the provider will not add the api-version to the request, which may be required.
- `auth_audience` (String) An optional authentication audience to use for the data plane resource. If not specified, the provider will use the base URL.
- `auth_endpoint` (String) An optional authentication endpoint to use for the data plane resource. If not specified, the provider will use the base URL.
- `body` (Dynamic) A dynamic attribute that contains the request body.
- `create_headers` (Map of String) A mapping of headers to be sent with the create request.
- `create_query_parameters` (Map of List of String) A mapping of query parameters to be sent with the create request.
- `delete_headers` (Map of String) A mapping of headers to be sent with the delete request.
- `delete_query_parameters` (Map of List of String) A mapping of query parameters to be sent with the delete request.
- `ignore_casing` (Boolean) A dynamic attribute that contains the request body.
- `ignore_missing_property` (Boolean) Whether ignore not returned properties like credentials in `body` 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.
- `ignore_null_property` (Boolean) When set to `true`, the provider will ignore properties whose values are `null` in the `body`.
These properties will not be included in the request body sent to the API, and the difference will not be shown in the plan output. Defaults to `false`.
- `locks` (List of String) A list of ARM resource IDs which are used to avoid create/modify/delete azapi resources at the same time.
- `read_headers` (Map of String) A mapping of headers to be sent with the read request.
- `read_query_parameters` (Map of List of String) A mapping of query parameters to be sent with the read request.
- `replace_triggers_external_values` (Dynamic) Will trigger a replace of the resource when the value changes and is not `null`. This can be used by practitioners to force a replace of the resource when certain values change, e.g. changing the SKU of a virtual machine based on the value of variables or locals. The value is a `dynamic`, so practitioners can compose the input however they wish. For a "break glass" set the value to `null` to prevent the plan modifier taking effect.
If you have `null` values that you do want to be tracked as affecting the resource replacement, include these inside an object.
Advanced use cases are possible and resource replacement can be triggered by values external to the resource, for example when a dependent resource changes.

e.g. to replace a resource when either the SKU or os_type attributes change:

```hcl
resource "azapi_data_plane_resource" "example" {
name = var.name
type = "Microsoft.AppConfiguration/configurationStores/keyValues@1.0"
body = {
properties = {
sku = var.sku
zones = var.zones
}
}

replace_triggers_external_values = [
var.sku,
var.zones,
]
}
```
- `replace_triggers_refs` (List of String) A list of paths in the current Terraform configuration. When the values at these paths change, the resource will be replaced.
- `response_export_values` (Dynamic) The attribute can accept either a list or a map.

- **List**: A list of paths that need to be exported from the 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 HCL object to the computed property output.

```text
{
properties = {
loginServer = "registry1.azurecr.io"
policies = {
quarantinePolicy = {
status = "disabled"
}
}
}
}
```

- **Map**: A map where the key is the name for the result and the value is a JMESPath query string to filter the response. Here's an example. If it sets to `{"login_server": "properties.loginServer", "quarantine_status": "properties.policies.quarantinePolicy.status"}`, it will set the following HCL object to the computed property output.

```text
{
"login_server" = "registry1.azurecr.io"
"quarantine_status" = "disabled"
}
```

To learn more about JMESPath, visit [JMESPath](https://jmespath.org/).
- `retry` (Attributes) The retry object supports the following attributes: (see [below for nested schema](#nestedatt--retry))
- `sensitive_body` (Dynamic) A dynamic attribute that contains the write-only properties of the request body. This will be merge-patched to the body to construct the actual request body.
- `sensitive_body_version` (Map of String) A map where the key is the path to the property in `sensitive_body` and the value is the version of the property. The key is a string in the format of `path.to.property[index].subproperty`, where `index` is the index of the item in an array. When the version is changed, the property will be included in the request body, otherwise it will be omitted from the request body.
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
- `update_headers` (Map of String) A mapping of headers to be sent with the update request.
- `update_query_parameters` (Map of List of String) A mapping of query parameters to be sent with the update request.

### Read-Only

- `id` (String) The ID of the Azure resource.
- `output` (Dynamic) The output HCL object containing the properties specified in `response_export_values`. Here are some examples to use the values.

```terraform
// it will output "registry1.azurecr.io"
output "login_server" {
value = azapi_data_plane_resource.example.output.properties.loginServer
}

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

<a id="nestedatt--retry"></a>
### Nested Schema for `retry`

Required:

- `error_message_regex` (List of String) A list of regular expressions to match against error messages. If any of the regular expressions match, the request will be retried.

Optional:

- `interval_seconds` (Number) The base number of seconds to wait between retries. Default is `10`.
- `max_interval_seconds` (Number) The maximum number of seconds to wait between retries. Default is `180`.
- `multiplier` (Number) The multiplier to apply to the interval between retries. Default is `1.5`.
- `randomization_factor` (Number) The randomization factor to apply to the interval between retries. The formula for the randomized interval is: `RetryInterval * (random value in range [1 - RandomizationFactor, 1 + RandomizationFactor])`. Therefore set to zero `0.0` for no randomization. Default is `0.5`.


<a id="nestedblock--timeouts"></a>
### Nested Schema for `timeouts`

Optional:

- `create` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours).
- `delete` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). Setting a timeout for a Delete operation is only applicable if changes are saved into state before the destroy operation occurs.
- `read` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). Read operations occur during any refresh or planning operation when refresh is enabled.
- `update` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours).


21 changes: 21 additions & 0 deletions internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Client struct {

ResourceClient *ResourceClient
DataPlaneClient *DataPlaneClient
GeneralClient *GeneralClient

Account ResourceManagerAccount
Option *Option
Expand Down Expand Up @@ -136,6 +137,26 @@ func (client *Client) Build(ctx context.Context, o *Option) error {
}
client.DataPlaneClient = dataPlaneClient

GeneralClient := NewGeneralClient(o.Cred, &arm.ClientOptions{
ClientOptions: policy.ClientOptions{
Cloud: o.CloudCfg,
// Disable the default telemetry policy, because it has a length limitation for user agent
Telemetry: policy.TelemetryOptions{
Disabled: true,
},
Logging: policy.LogOptions{
IncludeBody: true,
AllowedHeaders: allowedHeaders,
AllowedQueryParams: allowedQueryParams,
},
PerCallPolicies: perCallPolicies,
PerRetryPolicies: perRetryPolicies,
Retry: policy.RetryOptions{MaxRetries: o.MaxGoSdkRetries},
},
DisableRPRegistration: o.SkipProviderRegistration,
})
client.GeneralClient = GeneralClient

client.Account = NewResourceManagerAccount(o.TenantId, o.SubscriptionId, ParsedTokenClaimsObjectIDProvider(o.Cred, o.CloudCfg))

return nil
Expand Down
Loading
Loading