-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
azurerm_api_management_api - deprecate
sku
in favour of the `sku_na…
…me` property (#3154) * Flatten arm_api_management sku * Updates for backwards compatibility * Updated test cases * Addressing some PR comments * Fix for test pass * Rmoved comments and fixed docs * Fixed ImportStateVerify * Added SKU back into datasource * Updated code per PR comments * Removed newline * Remove unused function
- Loading branch information
Showing
22 changed files
with
360 additions
and
164 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package azure | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func SplitSku(sku string) (string, int32, error) { | ||
skuParts := strings.Split(sku, "_") | ||
|
||
if len(skuParts) != 2 { | ||
return "", -1, fmt.Errorf("sku_name(%s) is not formatted properly.", sku) | ||
} | ||
|
||
capacity, err := strconv.Atoi(skuParts[1]) | ||
|
||
if err != nil { | ||
return "", -1, fmt.Errorf("%s in sku_name is not a valid value.", skuParts[1]) | ||
} | ||
|
||
return skuParts[0], int32(capacity), nil | ||
} | ||
|
||
// MinCapacitySkuNameInSlice returns a SchemaValidateFunc which tests if the provided value | ||
// is of type string and matches the value of an element in the valid slice | ||
// will test with in lower case if ignoreCase is true will also validate if the | ||
// capacity if above passed minCapacity value | ||
func MinCapacitySkuNameInSlice(valid []string, minCapacity int32, ignoreCase bool) schema.SchemaValidateFunc { | ||
return func(i interface{}, k string) (s []string, es []error) { | ||
v, ok := i.(string) | ||
if !ok { | ||
es = append(es, fmt.Errorf("expected type of %s to be string", k)) | ||
return | ||
} | ||
|
||
name, capacity, err := SplitSku(v) | ||
|
||
if err != nil { | ||
es = append(es, err) | ||
return | ||
} | ||
|
||
for _, str := range valid { | ||
if name == str || (ignoreCase && strings.ToLower(name) == strings.ToLower(str)) { | ||
if capacity < minCapacity { | ||
es = append(es, fmt.Errorf("expected %s capacity value to be greater that %d, got %d", k, minCapacity, capacity)) | ||
} | ||
return | ||
} | ||
} | ||
|
||
es = append(es, fmt.Errorf("expected %s to be one of %v, got %s", k, valid, name)) | ||
return | ||
} | ||
} |
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.