Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
// Copyright IBM Corp. 2014, 2025
// SPDX-License-Identifier: MPL-2.0

package containerapps

import (
"context"
"fmt"
"time"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-07-01/managedenvironmentsstorages"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/containerapps/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
)

type ContainerAppEnvironmentStorageDataSource struct{}

type ContainerAppEnvironmentStorageDataSourceModel struct {
Name string `tfschema:"name"`
ContainerAppEnvironmentId string `tfschema:"container_app_environment_id"`

AccountName string `tfschema:"account_name"`
ShareName string `tfschema:"share_name"`
AccessMode string `tfschema:"access_mode"`
NfsServerUrl string `tfschema:"nfs_server_url"`
}

var _ sdk.DataSource = ContainerAppEnvironmentStorageDataSource{}

func (r ContainerAppEnvironmentStorageDataSource) ModelObject() interface{} {
return &ContainerAppEnvironmentStorageDataSourceModel{}
}

func (r ContainerAppEnvironmentStorageDataSource) ResourceType() string {
return "azurerm_container_app_environment_storage"
}

func (r ContainerAppEnvironmentStorageDataSource) Arguments() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.ManagedEnvironmentStorageName,
Description: "The name for this Container App Environment Storage.",
},

"container_app_environment_id": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: managedenvironmentsstorages.ValidateManagedEnvironmentID,
Description: "The ID of the Container App Environment to which this storage belongs.",
},
}
}

func (r ContainerAppEnvironmentStorageDataSource) Attributes() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"account_name": {
Type: pluginsdk.TypeString,
Computed: true,
Description: "The Azure Storage Account in which the Share is located.",
},

"share_name": {
Type: pluginsdk.TypeString,
Computed: true,
Description: "The name of the Azure Storage Share.",
},

"access_mode": {
Type: pluginsdk.TypeString,
Computed: true,
Description: "The access mode to connect this storage to the Container App.",
},

"nfs_server_url": {
Type: pluginsdk.TypeString,
Computed: true,
Description: "The NFS server URL for the Azure File Share.",
},
}
}

func (r ContainerAppEnvironmentStorageDataSource) Read() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 5 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.ContainerApps.StorageClient

var state ContainerAppEnvironmentStorageDataSourceModel
if err := metadata.Decode(&state); err != nil {
return err
}

envId, err := managedenvironmentsstorages.ParseManagedEnvironmentID(state.ContainerAppEnvironmentId)
if err != nil {
return err
}

id := managedenvironmentsstorages.NewStorageID(envId.SubscriptionId, envId.ResourceGroupName, envId.ManagedEnvironmentName, state.Name)

existing, err := client.Get(ctx, id)
if err != nil {
if response.WasNotFound(existing.HttpResponse) {
return fmt.Errorf("%s was not found", id)
}
return fmt.Errorf("reading %s: %+v", id, err)
}

state.Name = id.StorageName
state.ContainerAppEnvironmentId = envId.ID()

if model := existing.Model; model != nil {
if props := model.Properties; props != nil {
if azureFile := props.AzureFile; azureFile != nil {
state.AccountName = pointer.From(azureFile.AccountName)
if azureFile.AccessMode != nil {
state.AccessMode = string(*azureFile.AccessMode)
}
state.ShareName = pointer.From(azureFile.ShareName)
} else if nfsAzureFile := props.NfsAzureFile; nfsAzureFile != nil {
state.NfsServerUrl = pointer.From(nfsAzureFile.Server)
if nfsAzureFile.AccessMode != nil {
state.AccessMode = string(*nfsAzureFile.AccessMode)
}
state.ShareName = pointer.From(nfsAzureFile.ShareName)
}
}
}

metadata.SetID(id)

return metadata.Encode(&state)
},
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright IBM Corp. 2014, 2025
// SPDX-License-Identifier: MPL-2.0

package containerapps_test

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
)

type ContainerAppEnvironmentStorageDataSource struct{}

func TestAccContainerAppEnvironmentStorageDataSource_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_container_app_environment_storage", "test")
r := ContainerAppEnvironmentStorageDataSource{}

data.DataSourceTest(t, []acceptance.TestStep{
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("account_name").IsSet(),
check.That(data.ResourceName).Key("share_name").IsSet(),
check.That(data.ResourceName).Key("access_mode").IsSet(),
),
},
})
}

func (d ContainerAppEnvironmentStorageDataSource) basic(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

data "azurerm_container_app_environment_storage" "test" {
name = azurerm_container_app_environment_storage.test.name
container_app_environment_id = azurerm_container_app_environment_storage.test.container_app_environment_id
}
`, ContainerAppEnvironmentStorageResource{}.basic(data))
}
1 change: 1 addition & 0 deletions internal/services/containerapps/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func (r Registration) DataSources() []sdk.DataSource {
ContainerAppDataSource{},
ContainerAppEnvironmentDataSource{},
ContainerAppEnvironmentCertificateDataSource{},
ContainerAppEnvironmentStorageDataSource{},
}
}

Expand Down
59 changes: 59 additions & 0 deletions website/docs/d/container_app_environment_storage.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
subcategory: "Container Apps"
layout: "azurerm"
page_title: "Azure Resource Manager: azurerm_container_app_environment_storage"
description: |-
Gets information about a Container App Environment Storage.
---

# Data Source: azurerm_container_app_environment_storage

Use this data source to access information about an existing Container App Environment Storage.

## Example Usage

```hcl
data "azurerm_container_app_environment" "example" {
name = "existing-environment"
resource_group_name = "existing-resources"
}

data "azurerm_container_app_environment_storage" "example" {
name = "existing-storage"
container_app_environment_id = data.azurerm_container_app_environment.example.id
}
```

## Arguments Reference

The following arguments are supported:

* `name` - (Required) The name of the Container App Environment Storage.

* `container_app_environment_id` - (Required) The ID of the Container App Environment to which this storage belongs.

## Attributes Reference

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

* `id` - The ID of the Container App Environment Storage.

* `access_mode` - The access mode to connect this storage to the Container App.

* `account_name` - The Azure Storage Account in which the Share is located.

* `nfs_server_url` - The NFS server URL for the Azure File Share.

* `share_name` - The name of the Azure Storage Share.

## Timeouts

The `timeouts` block allows you to specify [timeouts](https://developer.hashicorp.com/terraform/language/resources/configure#define-operation-timeouts) for certain actions:

* `read` - (Defaults to 5 minutes) Used when retrieving the Container App Environment Storage.

## API Providers
<!-- This section is generated, changes will be overwritten -->
This data source uses the following Azure API Providers:

* `Microsoft.App` - 2025-07-01
Loading