Skip to content

Commit 885e38c

Browse files
committed
azurerm_container_app: Add support for kind
1 parent 0a6bcd8 commit 885e38c

5 files changed

Lines changed: 151 additions & 1 deletion

File tree

internal/services/containerapps/container_app_data_source.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type ContainerAppDataSourceModel struct {
2929
ResourceGroup string `tfschema:"resource_group_name"`
3030
ManagedEnvironmentId string `tfschema:"container_app_environment_id"`
3131
Location string `tfschema:"location"`
32+
Kind string `tfschema:"kind"`
3233
RevisionMode string `tfschema:"revision_mode"`
3334
MaxInactiveRevisions int64 `tfschema:"max_inactive_revisions"`
3435
Ingress []helpers.Ingress `tfschema:"ingress"`
@@ -73,6 +74,12 @@ func (r ContainerAppDataSource) Attributes() map[string]*pluginsdk.Schema {
7374
Computed: true,
7475
},
7576

77+
"kind": {
78+
Type: pluginsdk.TypeString,
79+
Computed: true,
80+
Description: "The kind of container app.",
81+
},
82+
7683
"ingress": helpers.ContainerAppIngressSchemaComputed(),
7784

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

173+
if model.Kind != nil {
174+
containerApp.Kind = string(pointer.From(model.Kind))
175+
}
176+
166177
if props := model.Properties; props != nil {
167178
envId, err := managedenvironments.ParseManagedEnvironmentIDInsensitively(pointer.From(props.ManagedEnvironmentId))
168179
if err != nil {

internal/services/containerapps/container_app_resource.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type ContainerAppModel struct {
3232
ManagedEnvironmentId string `tfschema:"container_app_environment_id"`
3333
Location string `tfschema:"location"`
3434

35+
Kind string `tfschema:"kind"`
3536
RevisionMode string `tfschema:"revision_mode"`
3637
Ingress []helpers.Ingress `tfschema:"ingress"`
3738
Registries []helpers.Registry `tfschema:"registry"`
@@ -97,7 +98,15 @@ func (r ContainerAppResource) Arguments() map[string]*pluginsdk.Schema {
9798
}, false),
9899
},
99100

100-
"ingress": helpers.ContainerAppIngressSchema(),
101+
"kind": {
102+
Type: pluginsdk.TypeString,
103+
Optional: true,
104+
ValidateFunc: validation.StringInSlice([]string{
105+
string(containerapps.KindFunctionapp),
106+
string(containerapps.KindWorkflowapp),
107+
}, false),
108+
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.",
109+
}, "ingress": helpers.ContainerAppIngressSchema(),
101110

102111
"registry": helpers.ContainerAppRegistrySchema(),
103112

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

231+
if app.Kind != "" {
232+
containerApp.Kind = pointer.To(containerapps.Kind(app.Kind))
233+
}
234+
222235
ident, err := identity.ExpandSystemAndUserAssignedMapFromModel(app.Identity)
223236
if err != nil {
224237
return err
@@ -262,6 +275,8 @@ func (r ContainerAppResource) Read() sdk.ResourceFunc {
262275
state.Name = id.ContainerAppName
263276
state.ResourceGroup = id.ResourceGroupName
264277

278+
state.Kind = metadata.ResourceData.Get("kind").(string)
279+
265280
if model := existing.Model; model != nil {
266281
state.Location = location.Normalize(model.Location)
267282
state.Tags = tags.Flatten(model.Tags)
@@ -427,6 +442,14 @@ func (r ContainerAppResource) Update() sdk.ResourceFunc {
427442
model.Tags = tags.Expand(state.Tags)
428443
}
429444

445+
if metadata.ResourceData.HasChange("kind") {
446+
if state.Kind != "" {
447+
model.Kind = pointer.To(containerapps.Kind(state.Kind))
448+
} else {
449+
model.Kind = nil
450+
}
451+
}
452+
430453
model.Properties.Template = helpers.ExpandContainerAppTemplate(state.Template, metadata)
431454

432455
if err := client.CreateOrUpdateThenPoll(ctx, *id, *model); err != nil {

internal/services/containerapps/container_app_resource_test.go

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,72 @@ func TestAccContainerAppResource_basic(t *testing.T) {
3535
})
3636
}
3737

38+
func TestAccContainerAppResource_kindFunctionApp(t *testing.T) {
39+
data := acceptance.BuildTestData(t, "azurerm_container_app", "test")
40+
r := ContainerAppResource{}
41+
42+
data.ResourceTest(t, r, []acceptance.TestStep{
43+
{
44+
Config: r.withKindFunctionApp(data),
45+
Check: acceptance.ComposeTestCheckFunc(
46+
check.That(data.ResourceName).ExistsInAzure(r),
47+
),
48+
},
49+
data.ImportStep("kind"),
50+
})
51+
}
52+
53+
func TestAccContainerAppResource_kindWorkflowApp(t *testing.T) {
54+
data := acceptance.BuildTestData(t, "azurerm_container_app", "test")
55+
r := ContainerAppResource{}
56+
57+
data.ResourceTest(t, r, []acceptance.TestStep{
58+
{
59+
Config: r.withKindWorkflowApp(data),
60+
Check: acceptance.ComposeTestCheckFunc(
61+
check.That(data.ResourceName).ExistsInAzure(r),
62+
),
63+
},
64+
data.ImportStep("kind"),
65+
})
66+
}
67+
68+
func TestAccContainerAppResource_kindUpdate(t *testing.T) {
69+
data := acceptance.BuildTestData(t, "azurerm_container_app", "test")
70+
r := ContainerAppResource{}
71+
72+
data.ResourceTest(t, r, []acceptance.TestStep{
73+
{
74+
Config: r.basic(data),
75+
Check: acceptance.ComposeTestCheckFunc(
76+
check.That(data.ResourceName).ExistsInAzure(r),
77+
),
78+
},
79+
data.ImportStep("kind"),
80+
{
81+
Config: r.withKindFunctionApp(data),
82+
Check: acceptance.ComposeTestCheckFunc(
83+
check.That(data.ResourceName).ExistsInAzure(r),
84+
),
85+
},
86+
data.ImportStep("kind"),
87+
{
88+
Config: r.withKindWorkflowApp(data),
89+
Check: acceptance.ComposeTestCheckFunc(
90+
check.That(data.ResourceName).ExistsInAzure(r),
91+
),
92+
},
93+
data.ImportStep("kind"),
94+
{
95+
Config: r.basic(data),
96+
Check: acceptance.ComposeTestCheckFunc(
97+
check.That(data.ResourceName).ExistsInAzure(r),
98+
),
99+
},
100+
data.ImportStep("kind"),
101+
})
102+
}
103+
38104
func TestAccContainerAppResource_workloadProfile(t *testing.T) {
39105
data := acceptance.BuildTestData(t, "azurerm_container_app", "test")
40106
r := ContainerAppResource{}
@@ -663,6 +729,52 @@ resource "azurerm_container_app" "test" {
663729
`, r.template(data), data.RandomInteger)
664730
}
665731

732+
func (r ContainerAppResource) withKindFunctionApp(data acceptance.TestData) string {
733+
return fmt.Sprintf(`
734+
%s
735+
736+
resource "azurerm_container_app" "test" {
737+
name = "acctest-capp-%[2]d"
738+
resource_group_name = azurerm_resource_group.test.name
739+
container_app_environment_id = azurerm_container_app_environment.test.id
740+
revision_mode = "Single"
741+
kind = "functionapp"
742+
743+
template {
744+
container {
745+
name = "acctest-cont-%[2]d"
746+
image = "jackofallops/azure-containerapps-python-acctest:v0.0.1"
747+
cpu = 0.25
748+
memory = "0.5Gi"
749+
}
750+
}
751+
}
752+
`, r.template(data), data.RandomInteger)
753+
}
754+
755+
func (r ContainerAppResource) withKindWorkflowApp(data acceptance.TestData) string {
756+
return fmt.Sprintf(`
757+
%s
758+
759+
resource "azurerm_container_app" "test" {
760+
name = "acctest-capp-%[2]d"
761+
resource_group_name = azurerm_resource_group.test.name
762+
container_app_environment_id = azurerm_container_app_environment.test.id
763+
revision_mode = "Single"
764+
kind = "workflowapp"
765+
766+
template {
767+
container {
768+
name = "acctest-cont-%[2]d"
769+
image = "jackofallops/azure-containerapps-python-acctest:v0.0.1"
770+
cpu = 0.25
771+
memory = "0.5Gi"
772+
}
773+
}
774+
}
775+
`, r.template(data), data.RandomInteger)
776+
}
777+
666778
func (r ContainerAppResource) withSystemIdentity(data acceptance.TestData) string {
667779
return fmt.Sprintf(`
668780
%s

website/docs/d/container_app.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ In addition to the Arguments listed above - the following Attributes are exporte
3535

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

38+
* `kind` - The kind of container app.
39+
3840
* `template` - A `template` block as detailed below.
3941

4042
* `dapr` - A `dapr` block as detailed below.

website/docs/r/container_app.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ The following arguments are supported:
7272

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

75+
* `kind` - (Optional) The kind of container app. Possible values include `functionapp` and `workflowapp`.
76+
7577
* `registry` - (Optional) A `registry` block as detailed below.
7678

7779
* `secret` - (Optional) One or more `secret` block as detailed below.

0 commit comments

Comments
 (0)