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

fix error when adding revisions to existing APIs #22380

Closed
wants to merge 8 commits into from
18 changes: 13 additions & 5 deletions internal/services/apimanagement/api_management_api_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,18 +348,18 @@ func resourceApiManagementApiCreateUpdate(d *pluginsdk.ResourceData, meta interf
ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d)
defer cancel()

id := parse.NewApiID(subscriptionId, d.Get("resource_group_name").(string), d.Get("api_management_name").(string), d.Get("name").(string))

revision := d.Get("revision").(string)
path := d.Get("path").(string)
apiId := fmt.Sprintf("%s;rev=%s", id.Name, revision)
apiId := fmt.Sprintf("%s;rev=%s", d.Get("name").(string), revision)
version := d.Get("version").(string)
versionSetId := d.Get("version_set_id").(string)
displayName := d.Get("display_name").(string)
protocolsRaw := d.Get("protocols").(*pluginsdk.Set).List()
protocols := expandApiManagementApiProtocols(protocolsRaw)
sourceApiId := d.Get("source_api_id").(string)

id := parse.NewApiID(subscriptionId, d.Get("resource_group_name").(string), d.Get("api_management_name").(string), apiId)
kevjallen marked this conversation as resolved.
Show resolved Hide resolved

if version != "" && versionSetId == "" {
return fmt.Errorf("setting `version` without the required `version_set_id`")
}
Expand Down Expand Up @@ -414,7 +414,7 @@ func resourceApiManagementApiCreateUpdate(d *pluginsdk.ResourceData, meta interf
Format: apimanagement.ContentFormat(contentFormat),
Value: utils.String(contentValue),
Path: utils.String(path),
APIVersion: utils.String(version),
APIRevision: utils.String(revision),
},
}
wsdlSelectorVs := importV["wsdl_selector"].([]interface{})
Expand All @@ -435,6 +435,10 @@ func resourceApiManagementApiCreateUpdate(d *pluginsdk.ResourceData, meta interf
}
}

if version != "" {
apiParams.APICreateOrUpdateProperties.APIVersion = utils.String(version)
}

if versionSetId != "" {
apiParams.APICreateOrUpdateProperties.APIVersionSetID = utils.String(versionSetId)
}
Expand Down Expand Up @@ -481,7 +485,7 @@ func resourceApiManagementApiCreateUpdate(d *pluginsdk.ResourceData, meta interf
Protocols: protocols,
ServiceURL: utils.String(serviceUrl),
SubscriptionKeyParameterNames: subscriptionKeyParameterNames,
APIVersion: utils.String(version),
APIRevision: utils.String(revision),
SubscriptionRequired: &subscriptionRequired,
AuthenticationSettings: authenticationSettings,
APIRevisionDescription: utils.String(d.Get("revision_description").(string)),
Expand All @@ -499,6 +503,10 @@ func resourceApiManagementApiCreateUpdate(d *pluginsdk.ResourceData, meta interf
params.APICreateOrUpdateProperties.DisplayName = &displayName
}

if version != "" {
params.APICreateOrUpdateProperties.APIVersion = utils.String(version)
}

if versionSetId != "" {
params.APICreateOrUpdateProperties.APIVersionSetID = utils.String(versionSetId)
}
Expand Down