-
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
New Resource: azurerm_static_web_app_link_backend
#26507
base: main
Are you sure you want to change the base?
Conversation
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.
Thanks @nnstt1 - I've added some comments below to take a look at. However, I think that this resource should actually be split into multiple resources for the specific backend types to avoid the somewhat messy code around checking for IDs and to assist users in being explicit about their configuration? WDYT?
} | ||
|
||
func (r StaticWebAppLinkBackendResource) ResourceType() string { | ||
return "azurerm_static_web_app_link_backend" |
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 call this
return "azurerm_static_web_app_link_backend" | |
return "azurerm_static_web_app_linked_backend" |
as the resource names the "thing" created, not the action.
} | ||
|
||
func (r StaticWebAppLinkBackendResource) ModelObject() interface{} { | ||
return &StaticWebAppLinkBackendModel{} |
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.
return &StaticWebAppLinkBackendModel{} | |
return &StaticWebAppLinkedBackendModel{} |
return map[string]*pluginsdk.Schema{ | ||
"id": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
} |
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.
id is handled implicitly by the SDK package and cannot be specified here
return map[string]*pluginsdk.Schema{ | |
"id": { | |
Type: pluginsdk.TypeString, | |
Computed: true, | |
}, | |
} | |
return map[string]*pluginsdk.Schema{} |
if apiManagementId, err := apimanagementservice.ParseServiceID(model.BackendResourceId); err == nil { | ||
linkedBackend.id = apiManagementId.ID() | ||
linkedBackend.name = apiManagementId.ServiceName | ||
|
||
backendClient := metadata.Client.ApiManagement.ServiceClient | ||
|
||
apiManagement, err := backendClient.Get(ctx, *apiManagementId) | ||
if err != nil { | ||
return fmt.Errorf("reading specified %s: %+v", *apiManagementId, err) | ||
} | ||
|
||
if appModel := apiManagement.Model; appModel != nil { | ||
loc = location.Normalize(appModel.Location) | ||
} | ||
|
||
} else if appServiceId, err := commonids.ParseAppServiceID(model.BackendResourceId); err == nil { | ||
linkedBackend.id = appServiceId.ID() | ||
linkedBackend.name = appServiceId.SiteName | ||
|
||
backendClient := metadata.Client.AppService.WebAppsClient | ||
|
||
appService, err := backendClient.Get(ctx, *appServiceId) | ||
if err != nil { | ||
return fmt.Errorf("reading specified %s: %+v", *appServiceId, err) | ||
} | ||
|
||
if appModel := appService.Model; appModel != nil { | ||
loc = location.Normalize(appModel.Location) | ||
} | ||
|
||
} else if containerAppId, err := containerapps.ParseContainerAppID(model.BackendResourceId); err == nil { | ||
linkedBackend.id = containerAppId.ID() | ||
linkedBackend.name = containerAppId.ContainerAppName | ||
|
||
backendClient := metadata.Client.ContainerApps.ContainerAppClient | ||
|
||
containerApp, err := backendClient.Get(ctx, *containerAppId) | ||
if err != nil { | ||
return fmt.Errorf("reading specified %s: %+v", *containerAppId, err) | ||
} | ||
|
||
if appModel := containerApp.Model; appModel != nil { | ||
loc = location.Normalize(appModel.Location) | ||
} | ||
|
||
} else { | ||
return fmt.Errorf("unsupported backend resource type") | ||
} |
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 update this to a switch
using the validate functions? Since the Schema validation gates the values here before we get here, we shouldn't need the error/defaul case.
|
||
if model := result.Model; model != nil { | ||
if props := model.Properties; props != nil { | ||
state.BackendResourceId = pointer.From(props.BackendResourceId) |
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.
We'll need to check the ID type here and parse it with the appropriate parser to ensure the ID is correctly cased and formatted for the state.
--- | ||
subcategory: "App Service (Web Apps)" | ||
layout: "azurerm" | ||
page_title: "Azure Resource Manager: azurerm_static_web_app_link_backend" |
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.
page_title: "Azure Resource Manager: azurerm_static_web_app_link_backend" | |
page_title: "Azure Resource Manager: azurerm_static_web_app_linked_backend" |
Manages a Static Web App Link Backend. | ||
--- | ||
|
||
# azurerm_static_web_app_link_backend |
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.
# azurerm_static_web_app_link_backend | |
# azurerm_static_web_app_linked_backend |
sku_name = "Consumption_0" | ||
} | ||
|
||
resource "azurerm_static_web_app_link_backend" "example" { |
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.
resource "azurerm_static_web_app_link_backend" "example" { | |
resource "azurerm_static_web_app_linked_backend" "example" { |
This PR is being labeled as "stale" because it has not been updated for 30 or more days. If this PR is still valid, please remove the "stale" label. If this PR is blocked, please add it to the "Blocked" milestone. If you need some help completing this PR, please leave a comment letting us know. Thank you! |
This PR is being labeled as "stale" because it has not been updated for 30 or more days. If this PR is still valid, please remove the "stale" label. If this PR is blocked, please add it to the "Blocked" milestone. If you need some help completing this PR, please leave a comment letting us know. Thank you! |
Community Note
Description
Support for linking Static Web App to API Management, App Service, or Container App.
Only API Management ID, App Service ID, or Container App ID can be specified in the
backend_resource_id
argument as backend resources to be linked with Static Web Apps.PR Checklist
For example: “
resource_name_here
- description of change e.g. adding propertynew_property_name_here
”Changes to existing Resource / Data Source
Testing
Change Log
Below please provide what should go into the changelog (if anything) conforming to the Changelog Format documented here.
azurerm_static_web_app_link_backend
[GH-00000]This is a (please select all that apply):
Related Issue(s)
Fixes #26350
Note
If this PR changes meaningfully during the course of review please update the title and description as required.