Skip to content
Closed
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
11 changes: 11 additions & 0 deletions internal/services/containerapps/container_app_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type ContainerAppDataSourceModel struct {
ResourceGroup string `tfschema:"resource_group_name"`
ManagedEnvironmentId string `tfschema:"container_app_environment_id"`
Location string `tfschema:"location"`
Kind string `tfschema:"kind"`
RevisionMode string `tfschema:"revision_mode"`
MaxInactiveRevisions int64 `tfschema:"max_inactive_revisions"`
Ingress []helpers.Ingress `tfschema:"ingress"`
Expand Down Expand Up @@ -73,6 +74,12 @@ func (r ContainerAppDataSource) Attributes() map[string]*pluginsdk.Schema {
Computed: true,
},

"kind": {
Type: pluginsdk.TypeString,
Computed: true,
Description: "The kind of container app.",
},

"ingress": helpers.ContainerAppIngressSchemaComputed(),

"registry": helpers.ContainerAppRegistrySchemaComputed(),
Expand Down Expand Up @@ -163,6 +170,10 @@ func (r ContainerAppDataSource) Read() sdk.ResourceFunc {
containerApp.Location = location.Normalize(model.Location)
containerApp.Tags = tags.Flatten(model.Tags)

if model.Kind != nil {
containerApp.Kind = string(pointer.From(model.Kind))
}

if props := model.Properties; props != nil {
envId, err := managedenvironments.ParseManagedEnvironmentIDInsensitively(pointer.From(props.ManagedEnvironmentId))
if err != nil {
Expand Down
25 changes: 24 additions & 1 deletion internal/services/containerapps/container_app_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type ContainerAppModel struct {
ManagedEnvironmentId string `tfschema:"container_app_environment_id"`
Location string `tfschema:"location"`

Kind string `tfschema:"kind"`
RevisionMode string `tfschema:"revision_mode"`
Ingress []helpers.Ingress `tfschema:"ingress"`
Registries []helpers.Registry `tfschema:"registry"`
Expand Down Expand Up @@ -97,7 +98,15 @@ func (r ContainerAppResource) Arguments() map[string]*pluginsdk.Schema {
}, false),
},

"ingress": helpers.ContainerAppIngressSchema(),
"kind": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
string(containerapps.KindFunctionapp),
string(containerapps.KindWorkflowapp),
}, false),
Description: "The kind of container app. Possible values include: `functionapp`, `workflowapp`. This value is not returned by the API and will be stored in the Terraform state only.",
}, "ingress": helpers.ContainerAppIngressSchema(),

"registry": helpers.ContainerAppRegistrySchema(),

Expand Down Expand Up @@ -219,6 +228,10 @@ func (r ContainerAppResource) Create() sdk.ResourceFunc {
Tags: tags.Expand(app.Tags),
}

if app.Kind != "" {
containerApp.Kind = pointer.To(containerapps.Kind(app.Kind))
}

ident, err := identity.ExpandSystemAndUserAssignedMapFromModel(app.Identity)
if err != nil {
return err
Expand Down Expand Up @@ -262,6 +275,8 @@ func (r ContainerAppResource) Read() sdk.ResourceFunc {
state.Name = id.ContainerAppName
state.ResourceGroup = id.ResourceGroupName

state.Kind = metadata.ResourceData.Get("kind").(string)

if model := existing.Model; model != nil {
state.Location = location.Normalize(model.Location)
state.Tags = tags.Flatten(model.Tags)
Expand Down Expand Up @@ -427,6 +442,14 @@ func (r ContainerAppResource) Update() sdk.ResourceFunc {
model.Tags = tags.Expand(state.Tags)
}

if metadata.ResourceData.HasChange("kind") {
if state.Kind != "" {
model.Kind = pointer.To(containerapps.Kind(state.Kind))
} else {
model.Kind = nil
}
}

model.Properties.Template = helpers.ExpandContainerAppTemplate(state.Template, metadata)

if err := client.CreateOrUpdateThenPoll(ctx, *id, *model); err != nil {
Expand Down
112 changes: 112 additions & 0 deletions internal/services/containerapps/container_app_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,72 @@ func TestAccContainerAppResource_basic(t *testing.T) {
})
}

func TestAccContainerAppResource_kindFunctionApp(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_container_app", "test")
r := ContainerAppResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.withKindFunctionApp(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("kind"),
})
}

func TestAccContainerAppResource_kindWorkflowApp(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_container_app", "test")
r := ContainerAppResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.withKindWorkflowApp(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("kind"),
})
}

func TestAccContainerAppResource_kindUpdate(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_container_app", "test")
r := ContainerAppResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("kind"),
{
Config: r.withKindFunctionApp(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("kind"),
{
Config: r.withKindWorkflowApp(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("kind"),
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("kind"),
})
}

func TestAccContainerAppResource_workloadProfile(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_container_app", "test")
r := ContainerAppResource{}
Expand Down Expand Up @@ -663,6 +729,52 @@ resource "azurerm_container_app" "test" {
`, r.template(data), data.RandomInteger)
}

func (r ContainerAppResource) withKindFunctionApp(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

resource "azurerm_container_app" "test" {
name = "acctest-capp-%[2]d"
resource_group_name = azurerm_resource_group.test.name
container_app_environment_id = azurerm_container_app_environment.test.id
revision_mode = "Single"
kind = "functionapp"

template {
container {
name = "acctest-cont-%[2]d"
image = "jackofallops/azure-containerapps-python-acctest:v0.0.1"
cpu = 0.25
memory = "0.5Gi"
}
}
}
`, r.template(data), data.RandomInteger)
}

func (r ContainerAppResource) withKindWorkflowApp(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

resource "azurerm_container_app" "test" {
name = "acctest-capp-%[2]d"
resource_group_name = azurerm_resource_group.test.name
container_app_environment_id = azurerm_container_app_environment.test.id
revision_mode = "Single"
kind = "workflowapp"

template {
container {
name = "acctest-cont-%[2]d"
image = "jackofallops/azure-containerapps-python-acctest:v0.0.1"
cpu = 0.25
memory = "0.5Gi"
}
}
}
`, r.template(data), data.RandomInteger)
}

func (r ContainerAppResource) withSystemIdentity(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions website/docs/d/container_app.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ In addition to the Arguments listed above - the following Attributes are exporte

* `revision_mode` - The revision mode of the Container App.

* `kind` - The kind of container app.

* `template` - A `template` block as detailed below.

* `dapr` - A `dapr` block as detailed below.
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/container_app.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ The following arguments are supported:

* `ingress` - (Optional) An `ingress` block as detailed below.

* `kind` - (Optional) The kind of container app. Possible values include `functionapp` and `workflowapp`.

* `registry` - (Optional) A `registry` block as detailed below.

* `secret` - (Optional) One or more `secret` block as detailed below.
Expand Down
Loading