Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new resource
azurerm_spring_cloud_app
, `azurerm_spring_cloud_deploy…
…ment` and `azurerm_spring_cloud_active_deployment`
- Loading branch information
Showing
43 changed files
with
4,033 additions
and
5 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
azurerm/internal/authorizers/authorizer_shared_access_signature.go
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,47 @@ | ||
package authorizers | ||
|
||
import ( | ||
"net/http" | ||
"net/url" | ||
|
||
"github.com/Azure/go-autorest/autorest" | ||
) | ||
|
||
// SharedAccessSignatureAuthorizer implements an authorization for Shared Access Signature | ||
// this can be used for interaction with Blob, File and Queue Storage Endpoints | ||
type SharedAccessSignatureAuthorizer struct { | ||
sasQuery map[string]interface{} | ||
} | ||
|
||
// NewSharedAccessSignatureAuthorizer creates a SharedAccessSignatureAuthorizer using sasToken | ||
func NewSharedAccessSignatureAuthorizer(sasToken string) *SharedAccessSignatureAuthorizer { | ||
m, _ := url.ParseQuery(sasToken) | ||
query := make(map[string]interface{}, len(m)) | ||
for key, value := range m { | ||
for i, v := range value { | ||
value[i] = url.QueryEscape(v) | ||
} | ||
query[key] = value | ||
} | ||
return &SharedAccessSignatureAuthorizer{ | ||
sasQuery: query, | ||
} | ||
} | ||
|
||
// WithAuthorization returns a PrepareDecorator that adds an HTTP Authorization header whose | ||
// value is "SharedKey " followed by the computed key. | ||
// This can be used for the Blob, Queue, and File Services | ||
// | ||
// from: https://docs.microsoft.com/en-us/rest/api/storageservices/delegate-access-with-shared-access-signature | ||
func (skl *SharedAccessSignatureAuthorizer) WithAuthorization() autorest.PrepareDecorator { | ||
return func(p autorest.Preparer) autorest.Preparer { | ||
return autorest.PreparerFunc(func(r *http.Request) (*http.Request, error) { | ||
r, err := p.Prepare(r) | ||
if err != nil { | ||
return r, err | ||
} | ||
|
||
return autorest.Prepare(r, autorest.WithQueryParameters(skl.sasQuery)) | ||
}) | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
azurerm/internal/services/appplatform/parse/spring_cloud_app.go
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,38 @@ | ||
package parse | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
) | ||
|
||
type SpringCloudAppId struct { | ||
ResourceGroup string | ||
ServiceName string | ||
Name string | ||
} | ||
|
||
func SpringCloudAppID(input string) (*SpringCloudAppId, error) { | ||
id, err := azure.ParseAzureResourceID(input) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to parse Spring Cloud App ID %q: %+v", input, err) | ||
} | ||
|
||
app := SpringCloudAppId{ | ||
ResourceGroup: id.ResourceGroup, | ||
} | ||
|
||
if app.ServiceName, err = id.PopSegment("Spring"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if app.Name, err = id.PopSegment("apps"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := id.ValidateNoEmptySegments(input); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &app, nil | ||
} |
88 changes: 88 additions & 0 deletions
88
azurerm/internal/services/appplatform/parse/spring_cloud_app_test.go
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,88 @@ | ||
package parse | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestSpringCloudAppID(t *testing.T) { | ||
testData := []struct { | ||
Name string | ||
Input string | ||
Expected *SpringCloudAppId | ||
}{ | ||
{ | ||
Name: "Empty", | ||
Input: "", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "No Resource Groups Segment", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "No Resource Groups Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Resource Group ID", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "No Spring Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Missing Apps Segment", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Missing Apps Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Spring Cloud App ID", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1", | ||
Expected: &SpringCloudAppId{ | ||
ResourceGroup: "resGroup1", | ||
ServiceName: "spring1", | ||
Name: "app1", | ||
}, | ||
}, | ||
{ | ||
Name: "Wrong Casing", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/Apps/app1", | ||
Expected: nil, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q", v.Name) | ||
|
||
actual, err := SpringCloudAppID(v.Input) | ||
if err != nil { | ||
if v.Expected == nil { | ||
continue | ||
} | ||
|
||
t.Fatalf("Expected a value but got an error: %s", err) | ||
} | ||
|
||
if actual.ResourceGroup != v.Expected.ResourceGroup { | ||
t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup) | ||
} | ||
|
||
if actual.ServiceName != v.Expected.ServiceName { | ||
t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) | ||
} | ||
|
||
if actual.Name != v.Expected.Name { | ||
t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
azurerm/internal/services/appplatform/parse/spring_cloud_deployment.go
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,43 @@ | ||
package parse | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
) | ||
|
||
type SpringCloudDeploymentId struct { | ||
ResourceGroup string | ||
ServiceName string | ||
AppName string | ||
Name string | ||
} | ||
|
||
func SpringCloudDeploymentID(input string) (*SpringCloudDeploymentId, error) { | ||
id, err := azure.ParseAzureResourceID(input) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to parse Spring Cloud Deployment ID %q: %+v", input, err) | ||
} | ||
|
||
deployment := SpringCloudDeploymentId{ | ||
ResourceGroup: id.ResourceGroup, | ||
} | ||
|
||
if deployment.ServiceName, err = id.PopSegment("Spring"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if deployment.AppName, err = id.PopSegment("apps"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if deployment.Name, err = id.PopSegment("deployments"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := id.ValidateNoEmptySegments(input); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &deployment, nil | ||
} |
103 changes: 103 additions & 0 deletions
103
azurerm/internal/services/appplatform/parse/spring_cloud_deployment_test.go
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,103 @@ | ||
package parse | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestSpringCloudDeploymentID(t *testing.T) { | ||
testData := []struct { | ||
Name string | ||
Input string | ||
Expected *SpringCloudDeploymentId | ||
}{ | ||
{ | ||
Name: "Empty", | ||
Input: "", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "No Resource Groups Segment", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "No Resource Groups Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Resource Group ID", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "No Spring Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Missing Apps Segment", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Missing Apps Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Missing Deployment Segment", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Missing Deployment Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/deployments", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Spring Cloud Deployment ID", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/deployments/deployment1", | ||
Expected: &SpringCloudDeploymentId{ | ||
ResourceGroup: "resGroup1", | ||
ServiceName: "spring1", | ||
AppName: "app1", | ||
Name: "deployment1", | ||
}, | ||
}, | ||
{ | ||
Name: "Wrong Casing", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/Deployments/deployment1", | ||
Expected: nil, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q", v.Name) | ||
|
||
actual, err := SpringCloudDeploymentID(v.Input) | ||
if err != nil { | ||
if v.Expected == nil { | ||
continue | ||
} | ||
|
||
t.Fatalf("Expected a value but got an error: %s", err) | ||
} | ||
|
||
if actual.ResourceGroup != v.Expected.ResourceGroup { | ||
t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup) | ||
} | ||
|
||
if actual.ServiceName != v.Expected.ServiceName { | ||
t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) | ||
} | ||
|
||
if actual.AppName != v.Expected.AppName { | ||
t.Fatalf("Expected %q but got %q for AppName", v.Expected.AppName, actual.AppName) | ||
} | ||
|
||
if actual.Name != v.Expected.Name { | ||
t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) | ||
} | ||
} | ||
} |
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.