Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_container_app - adding property max_inactive_revisions #27598

Merged
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
Expand Up @@ -30,6 +30,7 @@ type ContainerAppDataSourceModel struct {
ManagedEnvironmentId string `tfschema:"container_app_environment_id"`
Location string `tfschema:"location"`
RevisionMode string `tfschema:"revision_mode"`
MaxInactiveRevisions int64 `tfschema:"max_inactive_revisions"`
Ingress []helpers.Ingress `tfschema:"ingress"`
Registries []helpers.Registry `tfschema:"registry"`
Secrets []helpers.Secret `tfschema:"secret"`
Expand Down Expand Up @@ -117,6 +118,11 @@ func (r ContainerAppDataSource) Attributes() map[string]*pluginsdk.Schema {
Type: pluginsdk.TypeString,
Computed: true,
},

"max_inactive_revisions": {
Type: pluginsdk.TypeInt,
Computed: true,
},
}
}

Expand Down Expand Up @@ -172,6 +178,7 @@ func (r ContainerAppDataSource) Read() sdk.ResourceFunc {
containerApp.Ingress = helpers.FlattenContainerAppIngress(config.Ingress, id.ContainerAppName)
containerApp.Registries = helpers.FlattenContainerAppRegistries(config.Registries)
containerApp.Dapr = helpers.FlattenContainerAppDapr(config.Dapr)
containerApp.MaxInactiveRevisions = pointer.ToInt64(config.MaxInactiveRevisions)
}
}
containerApp.LatestRevisionName = pointer.From(props.LatestRevisionName)
Expand Down
27 changes: 20 additions & 7 deletions internal/services/containerapps/container_app_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ type ContainerAppModel struct {
Dapr []helpers.Dapr `tfschema:"dapr"`
Template []helpers.ContainerTemplate `tfschema:"template"`

Identity []identity.ModelSystemAssignedUserAssigned `tfschema:"identity"`
WorkloadProfileName string `tfschema:"workload_profile_name"`
Tags map[string]interface{} `tfschema:"tags"`
Identity []identity.ModelSystemAssignedUserAssigned `tfschema:"identity"`
WorkloadProfileName string `tfschema:"workload_profile_name"`
MaxInactiveRevisions int64 `tfschema:"max_inactive_revisions"`
Tags map[string]interface{} `tfschema:"tags"`

OutboundIpAddresses []string `tfschema:"outbound_ip_addresses"`
LatestRevisionName string `tfschema:"latest_revision_name"`
Expand Down Expand Up @@ -112,6 +113,12 @@ func (r ContainerAppResource) Arguments() map[string]*pluginsdk.Schema {
ValidateFunc: validation.StringIsNotEmpty,
},

"max_inactive_revisions": {
Type: pluginsdk.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(0, 100),
},

"tags": commonschema.Tags(),
}
}
Expand Down Expand Up @@ -199,10 +206,11 @@ func (r ContainerAppResource) Create() sdk.ResourceFunc {
Location: location.Normalize(env.Model.Location),
Properties: &containerapps.ContainerAppProperties{
Configuration: &containerapps.Configuration{
Ingress: helpers.ExpandContainerAppIngress(app.Ingress, id.ContainerAppName),
Dapr: helpers.ExpandContainerAppDapr(app.Dapr),
Secrets: secrets,
Registries: registries,
Ingress: helpers.ExpandContainerAppIngress(app.Ingress, id.ContainerAppName),
Dapr: helpers.ExpandContainerAppDapr(app.Dapr),
Secrets: secrets,
Registries: registries,
MaxInactiveRevisions: pointer.FromInt64(app.MaxInactiveRevisions),
},
ManagedEnvironmentId: pointer.To(app.ManagedEnvironmentId),
Template: helpers.ExpandContainerAppTemplate(app.Template, metadata),
Expand Down Expand Up @@ -279,6 +287,7 @@ func (r ContainerAppResource) Read() sdk.ResourceFunc {
state.Ingress = helpers.FlattenContainerAppIngress(config.Ingress, id.ContainerAppName)
state.Registries = helpers.FlattenContainerAppRegistries(config.Registries)
state.Dapr = helpers.FlattenContainerAppDapr(config.Dapr)
state.MaxInactiveRevisions = pointer.ToInt64(config.MaxInactiveRevisions)
}
state.LatestRevisionName = pointer.From(props.LatestRevisionName)
state.LatestRevisionFqdn = pointer.From(props.LatestRevisionFqdn)
Expand Down Expand Up @@ -375,6 +384,10 @@ func (r ContainerAppResource) Update() sdk.ResourceFunc {
}
}

if metadata.ResourceData.HasChange("max_inactive_revisions") {
model.Properties.Configuration.MaxInactiveRevisions = pointer.FromInt64(state.MaxInactiveRevisions)
}

if metadata.ResourceData.HasChange("dapr") {
model.Properties.Configuration.Dapr = helpers.ExpandContainerAppDapr(state.Dapr)

Expand Down
46 changes: 46 additions & 0 deletions internal/services/containerapps/container_app_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,28 @@ func TestAccContainerAppResource_ingressTrafficValidation(t *testing.T) {
})
}

func TestAccContainerAppResource_maxInactiveRevisionsUpdate(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(),
{
Config: r.maxInactiveRevisionsChange(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func (r ContainerAppResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := containerapps.ParseContainerAppID(state.ID)
if err != nil {
Expand Down Expand Up @@ -1304,6 +1326,7 @@ resource "azurerm_container_app" "test" {
resource_group_name = azurerm_resource_group.test.name
container_app_environment_id = azurerm_container_app_environment.test.id
revision_mode = "Single"
max_inactive_revisions = 25

template {
container {
Expand Down Expand Up @@ -2832,3 +2855,26 @@ traffic_weight {
}
`
}

func (r ContainerAppResource) maxInactiveRevisionsChange(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"
max_inactive_revisions = 50

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)
}
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 @@ -49,6 +49,8 @@ In addition to the Arguments listed above - the following Attributes are exporte

* `workload_profile_name` - The name of the Workload Profile in the Container App Environment in which this Container App is running.

* `max_inactive_revisions` - The max inactive revisions for this Container App.

* `tags` - A mapping of tags to assign to the Container App.

---
Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/container_app.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ resource "azurerm_container_app_environment" "example" {
resource_group_name = azurerm_resource_group.example.name
log_analytics_workspace_id = azurerm_log_analytics_workspace.example.id
}

resource "azurerm_container_app" "example" {
name = "example-app"
container_app_environment_id = azurerm_container_app_environment.example.id
Expand Down Expand Up @@ -79,6 +80,8 @@ The following arguments are supported:

~> **Note:** Omit this value to use the default `Consumption` Workload Profile.

* `max_inactive_revisions` - (Optional) The maximum of inactive revisions allowed for this Container App.

* `tags` - (Optional) A mapping of tags to assign to the Container App.

---
Expand Down
Loading