-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create oic storage account in dev (#3404)
* create oic storage account in dev * split oic resources into new template for reuse * add roleassignment, dev script * parameterize, add documentation * create new cmd for full env, doc change
- Loading branch information
1 parent
af311a2
commit 42f3708
Showing
9 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
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
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
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
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,41 @@ | ||
{ | ||
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", | ||
"contentVersion": "1.0.0.0", | ||
"parameters": { | ||
"rpServicePrincipalId": { | ||
"type": "string" | ||
} | ||
}, | ||
"resources": [ | ||
{ | ||
"sku": { | ||
"name": "Standard_LRS" | ||
}, | ||
"kind": "StorageV2", | ||
"properties": { | ||
"accessTier": "Hot", | ||
"supportsHttpsTrafficOnly": true, | ||
"allowBlobPublicAccess": true, | ||
"minimumTlsVersion": "TLS1_2" | ||
}, | ||
"location": "[resourceGroup().location]", | ||
"name": "[concat(take(replace(resourceGroup().name, '-', ''), 21), 'oic')]", | ||
"type": "Microsoft.Storage/storageAccounts", | ||
"apiVersion": "2019-06-01" | ||
}, | ||
{ | ||
"name": "[concat(concat(take(replace(resourceGroup().name, '-', ''), 21), 'oic'), '/Microsoft.Authorization/', guid(resourceId('Microsoft.Storage/storageAccounts', concat(take(replace(resourceGroup().name, '-', ''), 21), 'oic'))))]", | ||
"type": "Microsoft.Storage/storageAccounts/providers/roleAssignments", | ||
"properties": { | ||
"scope": "[resourceId('Microsoft.Storage/storageAccounts', concat(take(replace(resourceGroup().name, '-', ''), 21), 'oic'))]", | ||
"roleDefinitionId": "[subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'ba92f5b4-2d11-453d-a403-e96b0029c9fe')]", | ||
"principalId": "[parameters('rpServicePrincipalId')]", | ||
"principalType": "ServicePrincipal" | ||
}, | ||
"apiVersion": "2018-09-01-preview", | ||
"dependsOn": [ | ||
"[resourceId('Microsoft.Storage/storageAccounts', concat(take(replace(resourceGroup().name, '-', ''), 21), 'oic'))]" | ||
] | ||
} | ||
] | ||
} |
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
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
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,55 @@ | ||
package generator | ||
|
||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the Apache License 2.0. | ||
|
||
import ( | ||
"fmt" | ||
|
||
mgmtstorage "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage" | ||
"github.com/Azure/go-autorest/autorest/to" | ||
|
||
"github.com/Azure/ARO-RP/pkg/util/arm" | ||
"github.com/Azure/ARO-RP/pkg/util/azureclient" | ||
"github.com/Azure/ARO-RP/pkg/util/rbac" | ||
) | ||
|
||
var ( | ||
// Storage accounts must not contain dashes or be more than 24 characters | ||
// Name it after the resource group + 'oic' | ||
storageAccountName string = "concat(take(replace(resourceGroup().name, '-', ''), 21), 'oic')" | ||
resourceTypeStorageAccount string = "Microsoft.Storage/storageAccounts" | ||
) | ||
|
||
func (g *generator) oicStorageAccount() *arm.Resource { | ||
storageAccount := &mgmtstorage.Account{ | ||
Kind: mgmtstorage.StorageV2, | ||
Sku: &mgmtstorage.Sku{ | ||
Name: "Standard_LRS", | ||
}, | ||
AccountProperties: &mgmtstorage.AccountProperties{ | ||
AllowBlobPublicAccess: to.BoolPtr(true), | ||
EnableHTTPSTrafficOnly: to.BoolPtr(true), | ||
MinimumTLSVersion: mgmtstorage.TLS12, | ||
AccessTier: mgmtstorage.Hot, | ||
}, | ||
Name: to.StringPtr(fmt.Sprintf("[%s]", storageAccountName)), | ||
Location: to.StringPtr("[resourceGroup().location]"), | ||
Type: to.StringPtr(resourceTypeStorageAccount), | ||
} | ||
|
||
return &arm.Resource{ | ||
Resource: storageAccount, | ||
APIVersion: azureclient.APIVersion("Microsoft.Storage"), | ||
} | ||
} | ||
|
||
func (g *generator) oicRoleAssignment() *arm.Resource { | ||
return rbac.ResourceRoleAssignmentWithName( | ||
rbac.RoleStorageBlobDataContributor, | ||
"parameters('rpServicePrincipalId')", // RP MSI | ||
resourceTypeStorageAccount, | ||
storageAccountName, | ||
fmt.Sprintf("concat(%s, '/Microsoft.Authorization/', guid(resourceId('%s', %s)))", storageAccountName, resourceTypeStorageAccount, storageAccountName), | ||
) | ||
} |
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,24 @@ | ||
package generator | ||
|
||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the Apache License 2.0. | ||
|
||
import ( | ||
"github.com/Azure/ARO-RP/pkg/util/arm" | ||
) | ||
|
||
func (g *generator) oicTemplate() *arm.Template { | ||
t := templateStanza() | ||
|
||
t.Resources = append(t.Resources, | ||
g.oicStorageAccount(), | ||
g.oicRoleAssignment()) | ||
|
||
t.Parameters = map[string]*arm.TemplateParameter{ | ||
"rpServicePrincipalId": { | ||
Type: "string", | ||
}, | ||
} | ||
|
||
return t | ||
} |
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