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

New Resource azurerm_static_site #7150

Merged
merged 9 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from 8 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
5 changes: 5 additions & 0 deletions azurerm/internal/services/web/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Client struct {
BaseClient *web.BaseClient
CertificatesClient *web.CertificatesClient
CertificatesOrderClient *web.AppServiceCertificateOrdersClient
StaticSitesClient *web.StaticSitesClient
}

func NewClient(o *common.ClientOptions) *Client {
Expand All @@ -33,12 +34,16 @@ func NewClient(o *common.ClientOptions) *Client {
certificatesOrderClient := web.NewAppServiceCertificateOrdersClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&certificatesOrderClient.Client, o.ResourceManagerAuthorizer)

staticSitesClient := web.NewStaticSitesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&staticSitesClient.Client, o.ResourceManagerAuthorizer)

return &Client{
AppServiceEnvironmentsClient: &appServiceEnvironmentsClient,
AppServicePlansClient: &appServicePlansClient,
AppServicesClient: &appServicesClient,
BaseClient: &baseClient,
CertificatesClient: &certificatesClient,
CertificatesOrderClient: &certificatesOrderClient,
StaticSitesClient: &staticSitesClient,
}
}
69 changes: 69 additions & 0 deletions azurerm/internal/services/web/parse/static_site.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package parse

// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten

import (
"fmt"
"strings"

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
)

type StaticSiteId struct {
SubscriptionId string
ResourceGroup string
Name string
}

func NewStaticSiteID(subscriptionId, resourceGroup, name string) StaticSiteId {
return StaticSiteId{
SubscriptionId: subscriptionId,
ResourceGroup: resourceGroup,
Name: name,
}
}

func (id StaticSiteId) String() string {
segments := []string{
fmt.Sprintf("Name %q", id.Name),
fmt.Sprintf("Resource Group %q", id.ResourceGroup),
}
segmentsStr := strings.Join(segments, " / ")
return fmt.Sprintf("%s: (%s)", "Static Site", segmentsStr)
}

func (id StaticSiteId) ID() string {
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Web/staticSites/%s"
return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.Name)
}

// StaticSiteID parses a StaticSite ID into an StaticSiteId struct
func StaticSiteID(input string) (*StaticSiteId, error) {
id, err := azure.ParseAzureResourceID(input)
if err != nil {
return nil, err
}

resourceId := StaticSiteId{
SubscriptionId: id.SubscriptionID,
ResourceGroup: id.ResourceGroup,
}

if resourceId.SubscriptionId == "" {
return nil, fmt.Errorf("ID was missing the 'subscriptions' element")
}

if resourceId.ResourceGroup == "" {
return nil, fmt.Errorf("ID was missing the 'resourceGroups' element")
}

if resourceId.Name, err = id.PopSegment("staticSites"); err != nil {
return nil, err
}

if err := id.ValidateNoEmptySegments(input); err != nil {
return nil, err
}

return &resourceId, nil
}
112 changes: 112 additions & 0 deletions azurerm/internal/services/web/parse/static_site_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package parse

// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten

import (
"testing"

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/resourceid"
)

var _ resourceid.Formatter = StaticSiteId{}

func TestStaticSiteIDFormatter(t *testing.T) {
actual := NewStaticSiteID("12345678-1234-9876-4563-123456789012", "group1", "my-static-site1").ID()
expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Web/staticSites/my-static-site1"
if actual != expected {
t.Fatalf("Expected %q but got %q", expected, actual)
}
}

func TestStaticSiteID(t *testing.T) {
testData := []struct {
Input string
Error bool
Expected *StaticSiteId
}{

{
// empty
Input: "",
Error: true,
},

{
// missing SubscriptionId
Input: "/",
Error: true,
},

{
// missing value for SubscriptionId
Input: "/subscriptions/",
Error: true,
},

{
// missing ResourceGroup
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/",
Error: true,
},

{
// missing value for ResourceGroup
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/",
Error: true,
},

{
// missing Name
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Web/",
Error: true,
},

{
// missing value for Name
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Web/staticSites/",
Error: true,
},

{
// valid
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Web/staticSites/my-static-site1",
Expected: &StaticSiteId{
SubscriptionId: "12345678-1234-9876-4563-123456789012",
ResourceGroup: "group1",
Name: "my-static-site1",
},
},

{
// upper-cased
Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/GROUP1/PROVIDERS/MICROSOFT.WEB/STATICSITES/MY-STATIC-SITE1",
Error: true,
},
}

for _, v := range testData {
t.Logf("[DEBUG] Testing %q", v.Input)

actual, err := StaticSiteID(v.Input)
if err != nil {
if v.Error {
continue
}

t.Fatalf("Expect a value but got an error: %s", err)
}
if v.Error {
t.Fatal("Expect an error but didn't get one")
}

if actual.SubscriptionId != v.Expected.SubscriptionId {
t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId)
}
if actual.ResourceGroup != v.Expected.ResourceGroup {
t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup)
}
if actual.Name != v.Expected.Name {
t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name)
}
}
}
1 change: 1 addition & 0 deletions azurerm/internal/services/web/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ func (r Registration) SupportedResources() map[string]*schema.Resource {
"azurerm_app_service": resourceAppService(),
"azurerm_function_app": resourceFunctionApp(),
"azurerm_function_app_slot": resourceFunctionAppSlot(),
"azurerm_static_site": resourceStaticSite(),
}
}
1 change: 1 addition & 0 deletions azurerm/internal/services/web/resourceids.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ package web
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=HybridConnection -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Web/sites/site1/hybridConnectionNamespaces/hybridConnectionNamespace1/relays/relay1
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=ManagedCertificate -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Web/certificates/customhost.contoso.com
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SlotVirtualNetworkSwiftConnection -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Web/sites/site1/slots/slot1/config/virtualNetwork
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=StaticSite -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Web/staticSites/my-static-site1
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=VirtualNetworkSwiftConnection -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Web/sites/site1/config/virtualNetwork
Loading