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

remove FourPointOh: s services + apim #27992

Merged
merged 4 commits into from
Nov 12, 2024
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
21 changes: 0 additions & 21 deletions internal/services/apimanagement/api_management_api_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2022-08-01/api"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/apimanagement/migration"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/apimanagement/schemaz"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/apimanagement/validate"
Expand Down Expand Up @@ -337,18 +336,6 @@ func resourceApiManagementApi() *pluginsdk.Resource {
},
}

if !features.FourPointOhBeta() {
resource.Schema["api_type"].ConflictsWith = []string{"soap_pass_through"}

resource.Schema["soap_pass_through"] = &pluginsdk.Schema{
Type: pluginsdk.TypeBool,
Optional: true,
Computed: true,
Deprecated: "`soap_pass_through` will be removed in favour of the property `api_type` in version 4.0 of the AzureRM Provider",
ConflictsWith: []string{"api_type"},
}
}

return resource
}

Expand Down Expand Up @@ -395,11 +382,6 @@ func resourceApiManagementApiCreateUpdate(d *pluginsdk.ResourceData, meta interf
if v, ok := d.GetOk("api_type"); ok {
apiType = api.ApiType(v.(string))
}
if !features.FourPointOhBeta() {
if d.Get("soap_pass_through").(bool) {
apiType = api.ApiTypeSoap
}
}

soapApiType := map[api.ApiType]api.SoapApiType{
api.ApiTypeGraphql: api.SoapApiTypeGraphql,
Expand Down Expand Up @@ -563,9 +545,6 @@ func resourceApiManagementApiRead(d *pluginsdk.ResourceData, meta interface{}) e
d.Set("path", props.Path)
d.Set("service_url", pointer.From(props.ServiceURL))
d.Set("revision", pointer.From(props.ApiRevision))
if !features.FourPointOhBeta() {
d.Set("soap_pass_through", apiType == string(api.ApiTypeSoap))
}
d.Set("subscription_required", pointer.From(props.SubscriptionRequired))
d.Set("version", pointer.From(props.ApiVersion))
d.Set("version_set_id", pointer.From(props.ApiVersionSetId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
)

Expand Down Expand Up @@ -187,25 +186,6 @@ func TestAccApiManagementApi_websocket(t *testing.T) {
})
}

func TestAccApiManagementApi_soapPassthrough(t *testing.T) {
if features.FourPointOhBeta() {
t.Skipf("Test does not apply on 4.0")
}
data := acceptance.BuildTestData(t, "azurerm_api_management_api", "test")
r := ApiManagementApiResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.soapPassthrough(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("api_type").HasValue("soap"),
),
},
data.ImportStep(),
})
}

func TestAccApiManagementApi_subscriptionRequired(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_api_management_api", "test")
r := ApiManagementApiResource{}
Expand Down Expand Up @@ -594,23 +574,6 @@ resource "azurerm_api_management_api" "test" {
`, r.template(data, SkuNameDeveloper), data.RandomInteger)
}

func (r ApiManagementApiResource) soapPassthrough(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

resource "azurerm_api_management_api" "test" {
name = "acctestapi-%d"
resource_group_name = azurerm_resource_group.test.name
api_management_name = azurerm_api_management.test.name
display_name = "api1"
path = "api1"
protocols = ["https"]
revision = "1"
api_type = "soap"
}
`, r.template(data, SkuNameConsumption), data.RandomInteger)
}

func (r ApiManagementApiResource) subscriptionRequired(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
Expand Down
149 changes: 0 additions & 149 deletions internal/services/apimanagement/api_management_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/helpers/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/apimanagement/schemaz"
apimValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/apimanagement/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
Expand Down Expand Up @@ -640,34 +639,6 @@ func resourceApiManagementSchema() map[string]*pluginsdk.Schema {
"tags": commonschema.Tags(),
}

if !features.FourPointOhBeta() {
schema["policy"] = &pluginsdk.Schema{
Type: pluginsdk.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
ConfigMode: pluginsdk.SchemaConfigModeAttr,
Deprecated: "The `policy` block has been superseded by the resource `azurerm_api_management_policy` and will be removed in v4.0 of the AzureRM Provider",
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"xml_content": {
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
ConflictsWith: []string{"policy.0.xml_link"},
DiffSuppressFunc: XmlWithDotNetInterpolationsDiffSuppress,
},

"xml_link": {
Type: pluginsdk.TypeString,
Optional: true,
ConflictsWith: []string{"policy.0.xml_content"},
},
},
},
}
}

return schema
}

Expand Down Expand Up @@ -943,32 +914,6 @@ func resourceApiManagementServiceCreate(d *pluginsdk.ResourceData, meta interfac
}
}

if !features.FourPointOhBeta() {
policyClient := meta.(*clients.Client).ApiManagement.PolicyClient
policiesRaw := d.Get("policy").([]interface{})
policyContract, err := expandApiManagementPolicies(policiesRaw)
if err != nil {
return err
}

if _, ok := d.GetOk("policy"); ok {
policyServiceId := policy.NewServiceID(subscriptionId, id.ResourceGroupName, id.ServiceName)
// remove the existing policy
if delResp, err := policyClient.Delete(ctx, policyServiceId, policy.DeleteOperationOptions{}); err != nil {
if !response.WasNotFound(delResp.HttpResponse) {
return fmt.Errorf("removing Policies from %s: %+v", id, err)
}
}

// then add the new one, if it exists
if policyContract != nil {
if _, err := policyClient.CreateOrUpdate(ctx, policyServiceId, *policyContract, policy.CreateOrUpdateOperationOptions{}); err != nil {
return fmt.Errorf(" setting Policies for %s: %+v", id, err)
}
}
}
}

tenantAccessRaw := d.Get("tenant_access").([]interface{})
if sku.Name == apimanagementservice.SkuTypeConsumption && len(tenantAccessRaw) > 0 {
return fmt.Errorf("`tenant_access` is not supported for sku tier `Consumption`")
Expand Down Expand Up @@ -1194,32 +1139,6 @@ func resourceApiManagementServiceUpdate(d *pluginsdk.ResourceData, meta interfac
}
}

if !features.FourPointOhBeta() {
if d.HasChange("policy") {
policyClient := meta.(*clients.Client).ApiManagement.PolicyClient
policiesRaw := d.Get("policy").([]interface{})
policyContract, err := expandApiManagementPolicies(policiesRaw)
if err != nil {
return err
}

policyServiceId := policy.NewServiceID(subscriptionId, id.ResourceGroupName, id.ServiceName)
// remove the existing policy
if delResp, err := policyClient.Delete(ctx, policyServiceId, policy.DeleteOperationOptions{}); err != nil {
if !response.WasNotFound(delResp.HttpResponse) {
return fmt.Errorf("removing Policies from %s: %+v", id, err)
}
}

// then add the new one, if it exists
if policyContract != nil {
if _, err := policyClient.CreateOrUpdate(ctx, policyServiceId, *policyContract, policy.CreateOrUpdateOperationOptions{}); err != nil {
return fmt.Errorf(" setting Policies for %s: %+v", id, err)
}
}
}
}

if d.HasChange("tenant_access") {
tenantAccessRaw := d.Get("tenant_access").([]interface{})
if sku.Name == apimanagementservice.SkuTypeConsumption && len(tenantAccessRaw) > 0 {
Expand Down Expand Up @@ -1343,13 +1262,6 @@ func resourceApiManagementServiceRead(d *pluginsdk.ResourceData, meta interface{
if err := d.Set("sku_name", flattenApiManagementServiceSkuName(&model.Sku)); err != nil {
return fmt.Errorf("setting `sku_name`: %+v", err)
}

if !features.FourPointOhBeta() {
if err := d.Set("policy", flattenApiManagementPolicies(d, policy.Model)); err != nil {
return fmt.Errorf("setting `policy`: %+v", err)
}
}

d.Set("zones", zones.FlattenUntyped(model.Zones))

if model.Sku.Name != apimanagementservice.SkuTypeConsumption {
Expand Down Expand Up @@ -2133,67 +2045,6 @@ func flattenApiManagementSignUpSettings(input signupsettings.PortalSignupSetting
}
}

func expandApiManagementPolicies(input []interface{}) (*policy.PolicyContract, error) {
if len(input) == 0 || input[0] == nil {
return nil, nil
}

vs := input[0].(map[string]interface{})
xmlContent := vs["xml_content"].(string)
xmlLink := vs["xml_link"].(string)

if xmlContent != "" {
return &policy.PolicyContract{
Properties: &policy.PolicyContractProperties{
Format: pointer.To(policy.PolicyContentFormatRawxml),
Value: xmlContent,
},
}, nil
}

if xmlLink != "" {
return &policy.PolicyContract{
Properties: &policy.PolicyContractProperties{
Format: pointer.To(policy.PolicyContentFormatXmlNegativelink),
Value: xmlLink,
},
}, nil
}

return nil, errors.New("Either `xml_content` or `xml_link` should be set if the `policy` block is defined.")
}

func flattenApiManagementPolicies(d *pluginsdk.ResourceData, input *policy.PolicyContract) []interface{} {
xmlContent := ""
if input != nil && input.Properties != nil {
if input.Properties.Value != "" {
xmlContent = input.Properties.Value
}
}

// if there's no policy assigned, we set this to an empty list
if xmlContent == "" {
return []interface{}{}
}

output := map[string]interface{}{
"xml_content": xmlContent,
"xml_link": "",
}

// when you submit an `xml_link` to the API, the API downloads this link and stores it as `xml_content`
// as such we need to retrieve this value from the state if it's present
if existing, ok := d.GetOk("policy"); ok {
existingVs := existing.([]interface{})
if len(existingVs) > 0 && existingVs[0] != nil {
existingV := existingVs[0].(map[string]interface{})
output["xml_link"] = existingV["xml_link"].(string)
}
}

return []interface{}{output}
}

func expandApiManagementTenantAccessSettings(input []interface{}) tenantaccess.AccessInformationUpdateParameters {
enabled := false

Expand Down
Loading
Loading