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_environment: add support for workload_profiles_consumption_only_enabled #24277

Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type ContainerAppEnvironmentModel struct {
InternalLoadBalancerEnabled bool `tfschema:"internal_load_balancer_enabled"`
ZoneRedundant bool `tfschema:"zone_redundancy_enabled"`
Tags map[string]interface{} `tfschema:"tags"`
WorkloadProfilesConsumptionOnlyEnabled bool `tfschema:"workload_profiles_consumption_only_enabled"`
WorkloadProfiles []helpers.WorkloadProfileModel `tfschema:"workload_profile"`
InfrastructureResourceGroup string `tfschema:"infrastructure_resource_group_name"`

Expand Down Expand Up @@ -118,6 +119,13 @@ func (r ContainerAppEnvironmentResource) Arguments() map[string]*pluginsdk.Schem
Description: "Should the Container Environment operate in Internal Load Balancing Mode? Defaults to `false`. **Note:** can only be set to `true` if `infrastructure_subnet_id` is specified.",
},

"workload_profiles_consumption_only_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
Description: "Should the Container Environment only allow Consumption Workload Profiles? Defaults to `false`.",
},

"workload_profile": helpers.WorkloadProfileSchema(),

"zone_redundancy_enabled": {
Expand Down Expand Up @@ -251,6 +259,15 @@ func (r ContainerAppEnvironmentResource) Create() sdk.ResourceFunc {
managedEnvironment.Properties.VnetConfiguration.Internal = pointer.To(containerAppEnvironment.InternalLoadBalancerEnabled)
}

if containerAppEnvironment.WorkloadProfilesConsumptionOnlyEnabled {
managedEnvironment.Properties.WorkloadProfiles = &[]managedenvironments.WorkloadProfile{
{
Name: helpers.Consumption,
WorkloadProfileType: helpers.Consumption,
},
}
}

managedEnvironment.Properties.WorkloadProfiles = helpers.ExpandWorkloadProfiles(containerAppEnvironment.WorkloadProfiles)

if err := client.CreateOrUpdateThenPoll(ctx, id, managedEnvironment); err != nil {
Expand Down Expand Up @@ -301,8 +318,13 @@ func (r ContainerAppEnvironmentResource) Read() sdk.ResourceFunc {
state.ZoneRedundant = pointer.From(props.ZoneRedundant)
state.StaticIP = pointer.From(props.StaticIP)
state.DefaultDomain = pointer.From(props.DefaultDomain)
state.WorkloadProfiles = helpers.FlattenWorkloadProfiles(props.WorkloadProfiles)
state.InfrastructureResourceGroup = pointer.From(props.InfrastructureResourceGroup)

if workloadProfiles := helpers.FlattenWorkloadProfiles(props.WorkloadProfiles); len(workloadProfiles) > 0 {
state.WorkloadProfilesConsumptionOnlyEnabled = false
state.WorkloadProfiles = workloadProfiles
} else {
state.WorkloadProfilesConsumptionOnlyEnabled = true
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,21 @@ func TestAccContainerAppEnvironment_withWorkloadProfile(t *testing.T) {
})
}

func TestAccContainerAppEnvironment_withWorkloadProfileComsumptionOnly(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_container_app_environment", "test")
r := ContainerAppEnvironmentResource{}

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

func TestAccContainerAppEnvironment_updateWorkloadProfile(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_container_app_environment", "test")
r := ContainerAppEnvironmentResource{}
Expand Down Expand Up @@ -227,6 +242,30 @@ resource "azurerm_container_app_environment" "test" {
`, r.templateVNet(data), data.RandomInteger)
}

func (r ContainerAppEnvironmentResource) completeWithWorkloadProfileConsumptionOnly(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

%[1]s

resource "azurerm_container_app_environment" "test" {
name = "acctest-CAEnv%[2]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
infrastructure_subnet_id = azurerm_subnet.control.id
workload_profiles_consumption_only_enabled = true
zone_redundancy_enabled = true

tags = {
Foo = "Bar"
secret = "sauce"
}
}
`, r.templateVNet(data), data.RandomInteger)
}

func (r ContainerAppEnvironmentResource) completeWithWorkloadProfile(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
)

const consumption = "Consumption"
const Consumption = "Consumption"

type WorkloadProfileModel struct {
MaximumCount int `tfschema:"maximum_count"`
Expand Down Expand Up @@ -75,7 +75,7 @@ func ExpandWorkloadProfiles(input []WorkloadProfileModel) *[]managedenvironments
WorkloadProfileType: v.WorkloadProfileType,
}

if v.Name != consumption {
if v.Name != Consumption {
r.MaximumCount = pointer.To(int64(v.MaximumCount))
r.MinimumCount = pointer.To(int64(v.MinimumCount))
}
Expand All @@ -84,8 +84,8 @@ func ExpandWorkloadProfiles(input []WorkloadProfileModel) *[]managedenvironments
}

result = append(result, managedenvironments.WorkloadProfile{
Name: consumption,
WorkloadProfileType: consumption,
Name: Consumption,
WorkloadProfileType: Consumption,
})

return &result
Expand All @@ -98,7 +98,7 @@ func FlattenWorkloadProfiles(input *[]managedenvironments.WorkloadProfile) []Wor
result := make([]WorkloadProfileModel, 0)

for _, v := range *input {
if strings.EqualFold(v.WorkloadProfileType, consumption) {
if strings.EqualFold(v.WorkloadProfileType, Consumption) {
continue
}
result = append(result, WorkloadProfileModel{
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/container_app_environment.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ The following arguments are supported:

* `log_analytics_workspace_id` - (Optional) The ID for the Log Analytics Workspace to link this Container Apps Managed Environment to. Changing this forces a new resource to be created.

* `workload_profiles_consumption_only_enabled` - (Optional) Should the Container App Environment be created with Workload Profiles in Consumption Only Mode? Defaults to `false`.

* `workload_profile` - (Optional) The profile of the workload to scope the container app execution. A `workload_profile` block as defined below.

* `tags` - (Optional) A mapping of tags to assign to the resource.
Expand Down
Loading