Skip to content

Commit

Permalink
Feature ephemeral resource (#703)
Browse files Browse the repository at this point in the history
* go mod vendor

* new ephemeral resource: `azapi_resource_action`

* use go 1.22

* use go 1.22.7
  • Loading branch information
ms-henglu authored Jan 2, 2025
1 parent ccc7d9c commit 6ec10c8
Show file tree
Hide file tree
Showing 256 changed files with 17,037 additions and 8,479 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v2.3.0 (unreleased)
FEATURES:
- **New Ephemeral Resource**: azapi_resource_action

## v2.2.0

ENHANCEMENTS:
Expand Down
1 change: 0 additions & 1 deletion docs/data-sources/resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ terraform {
}
provider "azapi" {
enable_hcl_output_for_data_source = true
}
provider "azurerm" {
Expand Down
1 change: 0 additions & 1 deletion docs/data-sources/resource_action.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ terraform {
}
provider "azapi" {
enable_hcl_output_for_data_source = true
}
provider "azurerm" {
Expand Down
1 change: 0 additions & 1 deletion docs/data-sources/resource_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ terraform {
}
provider "azapi" {
enable_hcl_output_for_data_source = true
}
data "azapi_resource_list" "listBySubscription" {
Expand Down
141 changes: 141 additions & 0 deletions docs/ephemeral-resources/resource_action.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "azapi_resource_action Ephemeral Resource - terraform-provider-azapi"
subcategory: ""
description: |-
Performs an action on an existing Azure resource.
---

# azapi_resource_action (Ephemeral Resource)

Performs an action on an existing Azure resource.

## Example Usage

```terraform
terraform {
required_providers {
azapi = {
source = "Azure/azapi"
}
}
}
provider "azapi" {
}
resource "azapi_resource" "resourceGroup" {
type = "Microsoft.Resources/resourceGroups@2021-04-01"
name = "example-rg"
location = "westus"
body = {}
}
resource "azapi_resource" "storageAccount" {
type = "Microsoft.Storage/storageAccounts@2021-02-01"
parent_id = azapi_resource.resourceGroup.id
name = "exampleaccount"
location = "westus"
body = {
kind = "StorageV2"
sku = {
name = "Premium_LRS"
}
}
}
ephemeral "azapi_resource_action" "listKeys" {
type = "Microsoft.Storage/storageAccounts@2023-05-01"
resource_id = azapi_resource.storageAccount.id
action = "listKeys"
method = "POST"
response_export_values = {
all = "@"
}
}
```

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

### Required

- `resource_id` (String) The ID of an existing Azure source.
- `type` (String) 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.

### Optional

- `action` (String) The name of the resource action. It's also possible to make HTTP requests towards the resource ID if leave this field empty.
- `body` (Dynamic) A dynamic attribute that contains the request body.
- `headers` (Map of String) A map of headers to include in the request
- `locks` (List of String) A list of ARM resource IDs which are used to avoid create/modify/delete azapi resources at the same time.
- `method` (String) Specifies the HTTP method of the azure resource action. Allowed values are `POST`, `PATCH`, `PUT` and `DELETE`. Defaults to `POST`.
- `query_parameters` (Map of List of String) A map of query parameters to include in the request
- `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 block supports the following arguments: (see [below for nested schema](#nestedatt--retry))
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))

### 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 = ephemeral.azapi_resource_action.example.output.properties.loginServer
}

// it will output "disabled"
output "quarantine_policy" {
value = ephemeral.azapi_resource_action.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 error is considered retryable.

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:

- `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.
1 change: 0 additions & 1 deletion examples/data-sources/azapi_resource/data-source.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ terraform {
}

provider "azapi" {
enable_hcl_output_for_data_source = true
}

provider "azurerm" {
Expand Down
1 change: 0 additions & 1 deletion examples/data-sources/azapi_resource_action/data-source.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ terraform {
}

provider "azapi" {
enable_hcl_output_for_data_source = true
}

provider "azurerm" {
Expand Down
1 change: 0 additions & 1 deletion examples/data-sources/azapi_resource_list/data-source.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ terraform {
}

provider "azapi" {
enable_hcl_output_for_data_source = true
}

data "azapi_resource_list" "listBySubscription" {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
terraform {
required_providers {
azapi = {
source = "Azure/azapi"
}
}
}

provider "azapi" {
}

resource "azapi_resource" "resourceGroup" {
type = "Microsoft.Resources/resourceGroups@2021-04-01"
name = "example-rg"
location = "westus"
body = {}
}

resource "azapi_resource" "storageAccount" {
type = "Microsoft.Storage/storageAccounts@2021-02-01"
parent_id = azapi_resource.resourceGroup.id
name = "exampleaccount"
location = "westus"
body = {
kind = "StorageV2"
sku = {
name = "Premium_LRS"
}
}
}

ephemeral "azapi_resource_action" "listKeys" {
type = "Microsoft.Storage/storageAccounts@2023-05-01"
resource_id = azapi_resource.storageAccount.id
action = "listKeys"
method = "POST"
response_export_values = {
all = "@"
}
}
34 changes: 17 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ require (
github.com/google/go-cmp v0.6.0
github.com/hashicorp/go-azure-helpers v0.70.1
github.com/hashicorp/go-uuid v1.0.3
github.com/hashicorp/terraform-plugin-docs v0.19.2
github.com/hashicorp/terraform-plugin-framework v1.12.0
github.com/hashicorp/terraform-plugin-docs v0.20.1
github.com/hashicorp/terraform-plugin-framework v1.13.0
github.com/hashicorp/terraform-plugin-framework-timeouts v0.4.1
github.com/hashicorp/terraform-plugin-framework-validators v0.13.0
github.com/hashicorp/terraform-plugin-go v0.24.0
github.com/hashicorp/terraform-plugin-go v0.25.0
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0
github.com/jmespath/go-jmespath v0.4.0
Expand All @@ -31,7 +31,7 @@ require (
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/bmatcuk/doublestar/v4 v4.6.1 // indirect
github.com/bmatcuk/doublestar/v4 v4.7.1 // indirect
github.com/cloudflare/circl v1.3.9 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.17.0 // indirect
Expand All @@ -45,14 +45,14 @@ require (
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 // indirect
github.com/hashicorp/go-hclog v1.6.3 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.6.1 // indirect
github.com/hashicorp/go-plugin v1.6.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/hashicorp/hc-install v0.8.0 // indirect
github.com/hashicorp/hc-install v0.9.0 // indirect
github.com/hashicorp/hcl/v2 v2.21.0 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hashicorp/terraform-exec v0.21.0 // indirect
github.com/hashicorp/terraform-json v0.22.1 // indirect
github.com/hashicorp/terraform-json v0.23.0 // indirect
github.com/hashicorp/terraform-registry-address v0.2.3 // indirect
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
Expand All @@ -76,24 +76,24 @@ require (
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/yuin/goldmark v1.7.1 // indirect
github.com/yuin/goldmark v1.7.7 // indirect
github.com/yuin/goldmark-meta v1.1.0 // indirect
github.com/zclconf/go-cty v1.15.0 // indirect
go.abhg.dev/goldmark/frontmatter v0.2.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect
golang.org/x/mod v0.20.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.20.0 // indirect
golang.org/x/tools v0.23.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 // indirect
google.golang.org/grpc v1.66.2 // indirect
google.golang.org/protobuf v1.34.2 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

go 1.22.0
go 1.22.7
Loading

0 comments on commit 6ec10c8

Please sign in to comment.