-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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_profile
#23478
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
94c1f72
temp env apex
jiaweitao001 1d852b1
containerapps: Add support for workload_profile
jiaweitao001 55d92a9
fix go fmt
jiaweitao001 225d57c
Add doc
jiaweitao001 549f695
fix tflint
jiaweitao001 77c8260
Fix test
jiaweitao001 16b6acf
rename workload profile attributes
jiaweitao001 aab804e
Modify workload_profile structure
jiaweitao001 2408bb4
Fix docs of workload profile attributes
jiaweitao001 7309795
Update tests
jiaweitao001 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
internal/services/containerapps/helpers/container_app_environment.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package helpers | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/hashicorp/go-azure-helpers/lang/pointer" | ||
"github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2023-05-01/managedenvironments" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" | ||
) | ||
|
||
const consumption = "Consumption" | ||
|
||
type WorkloadProfileModel struct { | ||
MaximumCount int `tfschema:"maximum_count"` | ||
MinimumCount int `tfschema:"minimum_count"` | ||
Name string `tfschema:"name"` | ||
WorkloadProfileType string `tfschema:"workload_profile_type"` | ||
} | ||
|
||
func WorkloadProfileSchema() *pluginsdk.Schema { | ||
return &pluginsdk.Schema{ | ||
Type: pluginsdk.TypeSet, | ||
Optional: true, | ||
Elem: &pluginsdk.Resource{ | ||
Schema: map[string]*pluginsdk.Schema{ | ||
"name": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringIsNotEmpty, | ||
}, | ||
|
||
"workload_profile_type": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
"D4", | ||
"D8", | ||
"D16", | ||
"D32", | ||
"E4", | ||
"E8", | ||
"E16", | ||
"E32", | ||
}, false), | ||
}, | ||
|
||
"maximum_count": { | ||
Type: pluginsdk.TypeInt, | ||
Required: true, | ||
}, | ||
|
||
"minimum_count": { | ||
Type: pluginsdk.TypeInt, | ||
Required: true, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func ExpandWorkloadProfiles(input []WorkloadProfileModel) *[]managedenvironments.WorkloadProfile { | ||
if len(input) == 0 { | ||
return nil | ||
} | ||
|
||
result := make([]managedenvironments.WorkloadProfile, 0) | ||
|
||
for _, v := range input { | ||
r := managedenvironments.WorkloadProfile{ | ||
Name: v.Name, | ||
WorkloadProfileType: v.WorkloadProfileType, | ||
} | ||
|
||
if v.Name != consumption { | ||
r.MaximumCount = pointer.To(int64(v.MaximumCount)) | ||
r.MinimumCount = pointer.To(int64(v.MinimumCount)) | ||
} | ||
|
||
result = append(result, r) | ||
} | ||
|
||
result = append(result, managedenvironments.WorkloadProfile{ | ||
Name: consumption, | ||
WorkloadProfileType: consumption, | ||
}) | ||
|
||
return &result | ||
} | ||
|
||
func FlattenWorkloadProfiles(input *[]managedenvironments.WorkloadProfile) []WorkloadProfileModel { | ||
if input == nil || len(*input) == 0 { | ||
return []WorkloadProfileModel{} | ||
} | ||
result := make([]WorkloadProfileModel, 0) | ||
|
||
for _, v := range *input { | ||
if strings.EqualFold(v.WorkloadProfileType, consumption) { | ||
continue | ||
} | ||
result = append(result, WorkloadProfileModel{ | ||
Name: v.Name, | ||
MaximumCount: int(pointer.From(v.MaximumCount)), | ||
MinimumCount: int(pointer.From(v.MinimumCount)), | ||
WorkloadProfileType: v.WorkloadProfileType, | ||
}) | ||
} | ||
|
||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add some update testing?
We'll want coverage on adding and removing a profile to an environment, as well as removing all user specified profiles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will update the test.