Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add support for policy at ManagementGroup level #1754

Merged
merged 3 commits into from
Oct 2, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,116 @@
}
}
},
"/providers/Microsoft.Management/managementgroups/{managementGroupId}/providers/Microsoft.Authorization/policydefinitions/{policyDefinitionName}": {
"put": {
"tags": [
"PolicyDefinitions"
],
"operationId": "PolicyDefinitions_CreateOrUpdateAtManagementGroup",
"description": "Creates or updates a policy definition at management group level.",
"parameters": [
{
"name": "policyDefinitionName",
"in": "path",
"required": true,
"type": "string",
"description": "The name of the policy definition to create."
},
{
"name": "parameters",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/PolicyDefinition"
},
"description": "The policy definition properties."
},
{
"$ref": "#/parameters/ApiVersionParameter"
},
{
"$ref": "#/parameters/SubscriptionIdParameter"
},
{
"$ref": "#/parameters/ManagementGroupIdParameter"
}
],
"responses": {
"201": {
"description": "Created - Returns information about the policy definition.",
"schema": {
"$ref": "#/definitions/PolicyDefinition"
}
}
}
},
"delete": {
"tags": [
"PolicyDefinitions"
],
"operationId": "PolicyDefinitions_DeleteAtManagementGroup",
"description": "Deletes a policy definition at management group level.",
"parameters": [
{
"name": "policyDefinitionName",
"in": "path",
"required": true,
"type": "string",
"description": "The name of the policy definition to delete."
},
{
"$ref": "#/parameters/ApiVersionParameter"
},
{
"$ref": "#/parameters/SubscriptionIdParameter"
},
{
"$ref": "#/parameters/ManagementGroupIdParameter"
}
],
"responses": {
"204": {
"description": "No Content"
},
"200": {
"description": "OK"
}
}
},
"get": {
"tags": [
"PolicyDefinitions"
],
"operationId": "PolicyDefinitions_GetAtManagementGroup",
"description": "Gets the policy definition at management group level.",
"parameters": [
{
"name": "policyDefinitionName",
"in": "path",
"required": true,
"type": "string",
"description": "The name of the policy definition to get."
},
{
"$ref": "#/parameters/ApiVersionParameter"
},
{
"$ref": "#/parameters/SubscriptionIdParameter"
},
{
"$ref": "#/parameters/ManagementGroupIdParameter"
}
],
"responses": {
"200": {
"description": "OK - Returns information about the policy definition.",
"schema": {
"$ref": "#/definitions/PolicyDefinition"
}
}
}
}
},
"/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policydefinitions": {
"get": {
"tags": [
Expand Down Expand Up @@ -172,6 +282,45 @@
},
"x-ms-odata": "#/definitions/PolicyDefinition"
}
},
"/providers/Microsoft.Management/managementgroups/{managementGroupId}/providers/Microsoft.Authorization/policydefinitions": {
"get": {
"tags": [
"PolicyDefinitions"
],
"operationId": "PolicyDefinitions_ListByManagementGroup",
"description": "Gets all the policy definitions for a subscription at management group level.",
"parameters": [
{
"name": "$filter",
"in": "query",
"required": false,
"type": "string",
"description": "The filter to apply on the operation."
},
{
"$ref": "#/parameters/ApiVersionParameter"
},
{
"$ref": "#/parameters/SubscriptionIdParameter"
},
{
"$ref": "#/parameters/ManagementGroupIdParameter"
}
],
"responses": {
"200": {
"description": "OK - Returns ana array of policy definitions.",
"schema": {
"$ref": "#/definitions/PolicyDefinitionListResult"
}
}
},
"x-ms-pageable": {
"nextLinkName": "nextLink"
},
"x-ms-odata": "#/definitions/PolicyDefinition"
}
}
},
"definitions": {
Expand Down Expand Up @@ -272,6 +421,13 @@
"type": "string",
"description": "The ID of the target subscription."
},
"ManagementGroupIdParameter": {
"name": "managementGroupId",
"in": "path",
"required": true,
"type": "string",
"description": "The ID of the management group."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: @sarangan12 is still the assigned reviewer. He will be finally reviewing the spec.
@vivsriaus - I noted an anomaly that I wanted to point out. Whenever you define a parameter in the global "prameters" section, Autorest treats it as a client property. This will end up as a required parameter in the constructor. I am sure this is not motive over here. It is ok to define parameters in the global parameters section so that you can reference it at multiple places in the swagger spec. However, if the parameter should not be a client property then please add the following extension: "x-ms-parameter-location": "method".
There is an issue filed in the linter repo for checking this Azure/azure-openapi-validator#84

Azure/azure-openapi-validator#84

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @amarzavery thanks for the comment. I'm not sure what a client property is. What do you mean when you say"required parameter in the constructor"? You mean of the policy client?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @vivsriaus - That is correct. The constructor of the policy client will have a required parameter named managementGroupId. An example TypeScript client:

class PolicyClient {
 . . .
  constructor(subscriptionId: string, managementGroupId: string, baseUri: string?, options: OptionalParams) {
   . . .
  }
}

This would be the case in C# and other languages as well. I am sure this is not the desired behavior. If so then please add the extension "x-ms-parameter-location": "method" to the parameter in this and the other swagger spec below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @amarzavery. Yes, we definitely don't want managementGroupId to be a required parameter in the constructor. I'll make the changes.

},
"ApiVersionParameter": {
"name": "api-version",
"in": "query",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"parameters": {
"subscriptionId": "subid",
"managementGroupId": "mgid",
"policySetDefinitionName": "costManagement",
"api-version": "2017-06-01-preview",
"parameters": {
"properties": {
"displayName": "VM and Storage Cost Management",
"description": "Policies required to minimize the risk of accidental cost overruns",
"metadata": {
"category": "Cost Management"
},
"policyDefinitions": [
{
"policyDefinitionId": "/subscriptions/subId/providers/Microsoft.Authorization/policyDefinitions/storageSkus",
"parameters": {
"listOfAllowedSKUs": {
"value": [
"Standard_GRS",
"Standard_LRS"
]
}
}
}
]
}
}
},
"responses": {
"201": {
"headers": {},
"body": {
"id": "/providers/Microsoft.Management/managementgroups/mgid/providers/Microsoft.Authorization/policySetDefinitions/costManagement",
"type": "Microsoft.Authorization/policySetDefinitions",
"name": "costManagement",
"properties": {
"displayName": "VM and Storage Cost Management",
"description": "Policies required to minimize the risk of accidental cost overruns",
"metadata": {
"category": "Cost Management"
},
"policyDefinitions": [
{
"policyDefinitionId": "/subscriptions/subid/providers/Microsoft.Authorization/policyDefinitions/storageSkus",
"parameters": {
"listOfAllowedSKUs": {
"value": [
"Standard_GRS",
"Standard_LRS"
]
}
}
}
],
"policyType": "Custom"
}
}
},
"200": {
"headers": {},
"body": {
"id": "/providers/Microsoft.Management/managementgroups/mgid/providers/Microsoft.Authorization/policySetDefinitions/costManagement",
"type": "Microsoft.Authorization/policySetDefinitions",
"name": "costManagement",
"properties": {
"displayName": "VM and Storage Cost Management",
"description": "Policies required to minimize the risk of accidental cost overruns",
"metadata": {
"category": "Cost Management"
},
"policyDefinitions": [
{
"policyDefinitionId": "/subscriptions/subid/providers/Microsoft.Authorization/policyDefinitions/storageSkus",
"parameters": {
"listOfAllowedSKUs": {
"value": [
"Standard_GRS",
"Standard_LRS"
]
}
}
}
],
"policyType": "Custom"
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"parameters": {
"subscriptionId": "subid",
"managementGroupId": "mgid",
"policySetDefinitionName": "costManagement",
"api-version": "2017-06-01-preview"
},
"responses": {
"200": {
"headers": {},
"body": {
"id": "/providers/Microsoft.Management/managementgroups/mgid/providers/Microsoft.Authorization/policySetDefinitions/costManagement",
"type": "Microsoft.Authorization/policySetDefinitions",
"name": "costManagement",
"properties": {
"displayName": "VM and Storage Cost Management",
"description": "Policies required to minimize the risk of accidental cost overruns",
"metadata": {
"category": "Cost Management"
},
"parameters": {
"allowedLocations": {
"type": "array",
"metadata": {
"description": "Regions that resources can be deployed to",
"displayName": "Valid Regions"
}
}
},
"policyDefinitions": [
{
"policyDefinitionId": "/subscriptions/subid/providers/Microsoft.Authorization/policyDefinitions/storageSkus",
"parameters": {
"listOfAllowedSKUs": {
"value": [
"Standard_GRS",
"Standard_LRS"
]
}
}
},
{
"policyDefinitionId": "/subscriptions/subid/providers/Microsoft.Authorization/policyDefinitions/vmSkus"
},
{
"policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/policyDefinitionId",
"parameters": {
"listOfAllowedLocations": {
"value": "[parameters('allowedLocations')]"
}
}
}
],
"policyType": "Custom"
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"parameters": {
"subscriptionId": "subid",
"managementGroupId": "mgid",
"api-version": "2017-06-01-preview"
},
"responses": {
"200": {
"headers": {},
"body": {
"value": [
{
"id": "/providers/Microsoft.Management/managementgroups/mgid/providers/Microsoft.Authorization/policySetDefinitions/costManagement",
"type": "Microsoft.Authorization/policySetDefinitions",
"name": "costManagement",
"properties": {
"displayName": "VM and Storage Cost Management",
"description": "Policies required to minimize the risk of accidental cost overruns",
"metadata": {
"category": "Cost Management"
},
"parameters": {
"allowedLocations": {
"type": "array",
"metadata": {
"description": "Regions that resources can be deployed to",
"displayName": "Valid Regions"
}
}
},
"policyDefinitions": [
{
"policyDefinitionId": "/subscriptions/subid/providers/Microsoft.Authorization/policyDefinitions/storageSkus",
"parameters": {
"locations": {
"value": "[parameters('allowedLocations')]"
}
}
}
],
"policyType": "Custom"
}
},
{
"id": "/providers/Microsoft.Management/managementgroups/mgid/providers/Microsoft.Authorization/policySetDefinitions/skuManagement",
"type": "Microsoft.Authorization/policySetDefinitions",
"name": "skuManagement",
"properties": {
"displayName": "VM Sku Management",
"description": "Policies required to minimize the risk of accidental cost overruns",
"metadata": {
"category": "Sku Management"
},
"policyDefinitions": [
{
"policyDefinitionId": "/subscriptions/subid/providers/Microsoft.Authorization/policyDefinitions/vmSkus"
}
],
"policyType": "Custom"
}
}
]
}
}
}
}
Loading