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: fix infrastructure_resource_group_name behavior with workload_profile set to Consumption #27502

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -103,13 +103,9 @@ func (r ContainerAppEnvironmentResource) Arguments() map[string]*pluginsdk.Schem
RequiredWith: []string{"workload_profile"},
ValidateFunc: resourcegroups.ValidateName,
DiffSuppressOnRefresh: true,
DiffSuppressFunc: func(k, oldValue, newValue string, d *pluginsdk.ResourceData) bool { // If this is omitted, and there is a non-consumption profile, then the service generates a value for the required manage resource group.
DiffSuppressFunc: func(k, oldValue, newValue string, d *pluginsdk.ResourceData) bool { // If this is omitted, then the service generates a value for the required manage resource group.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DiffSuppressFunc: func(k, oldValue, newValue string, d *pluginsdk.ResourceData) bool { // If this is omitted, then the service generates a value for the required manage resource group.
DiffSuppressFunc: func(k, oldValue, newValue string, d *pluginsdk.ResourceData) bool { // If this is omitted and workload_profile is set, then the service generates a value for the required manage resource group.

Maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense, will add this line.

if profiles := d.Get("workload_profile").(*pluginsdk.Set).List(); len(profiles) > 0 && newValue == "" {
for _, profile := range profiles {
if profile.(map[string]interface{})["workload_profile_type"].(string) != string(helpers.WorkloadProfileSkuConsumption) {
return true
}
}
return true
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍🏻

}
return false
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,21 @@ func TestAccContainerAppEnvironment_infraResourceGroupWithoutName(t *testing.T)
})
}

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

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

func (r ContainerAppEnvironmentResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := managedenvironments.ParseManagedEnvironmentID(state.ID)
if err != nil {
Expand Down Expand Up @@ -581,3 +596,32 @@ resource "azurerm_container_app_environment" "test" {
}
`, r.templateVNet(data), data.RandomInteger)
}

func (r ContainerAppEnvironmentResource) infraResourceGroupWithConsumptionWorkloadProfile(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_profile {
name = "Consumption"
workload_profile_type = "Consumption"
}

zone_redundancy_enabled = true
Copy link

@J0F3 J0F3 Sep 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When here the intention is to test the configuration with infrastructure_subnet_id and workload_profile only I think zone_redundancy_enabled should be not be part of this test resource as it may have other implications.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.


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