diff --git a/azurerm/internal/provider/services.go b/azurerm/internal/provider/services.go index a74a4f7983dd..cf8732f360af 100644 --- a/azurerm/internal/provider/services.go +++ b/azurerm/internal/provider/services.go @@ -103,6 +103,7 @@ func SupportedTypedServices() []sdk.TypedServiceRegistration { return []sdk.TypedServiceRegistration{ eventhub.Registration{}, loadbalancer.Registration{}, + policy.Registration{}, resource.Registration{}, web.Registration{}, } diff --git a/azurerm/internal/sdk/service_registration.go b/azurerm/internal/sdk/service_registration.go index 94a283b4e725..269c24a0a32e 100644 --- a/azurerm/internal/sdk/service_registration.go +++ b/azurerm/internal/sdk/service_registration.go @@ -11,9 +11,6 @@ type TypedServiceRegistration interface { // Name is the name of this Service Name() string - // PackagePath is the relative path to this package - PackagePath() string - // DataSources returns a list of Data Sources supported by this Service DataSources() []DataSource diff --git a/azurerm/internal/sdk/wrapper_data_source.go b/azurerm/internal/sdk/wrapper_data_source.go index 16fee73ad135..9f8e79bbaff7 100644 --- a/azurerm/internal/sdk/wrapper_data_source.go +++ b/azurerm/internal/sdk/wrapper_data_source.go @@ -31,8 +31,10 @@ func (dw *DataSourceWrapper) DataSource() (*schema.Resource, error) { } modelObj := dw.dataSource.ModelObject() - if err := ValidateModelObject(&modelObj); err != nil { - return nil, fmt.Errorf("validating model for %q: %+v", dw.dataSource.ResourceType(), err) + if modelObj != nil { + if err := ValidateModelObject(&modelObj); err != nil { + return nil, fmt.Errorf("validating model for %q: %+v", dw.dataSource.ResourceType(), err) + } } d := func(duration time.Duration) *time.Duration { diff --git a/azurerm/internal/sdk/wrapper_resource.go b/azurerm/internal/sdk/wrapper_resource.go index 48509a3b9c53..206515256077 100644 --- a/azurerm/internal/sdk/wrapper_resource.go +++ b/azurerm/internal/sdk/wrapper_resource.go @@ -34,8 +34,10 @@ func (rw *ResourceWrapper) Resource() (*schema.Resource, error) { } modelObj := rw.resource.ModelObject() - if err := ValidateModelObject(&modelObj); err != nil { - return nil, fmt.Errorf("validating model for %q: %+v", rw.resource.ResourceType(), err) + if modelObj != nil { + if err := ValidateModelObject(&modelObj); err != nil { + return nil, fmt.Errorf("validating model for %q: %+v", rw.resource.ResourceType(), err) + } } d := func(duration time.Duration) *time.Duration { diff --git a/azurerm/internal/services/eventhub/registration.go b/azurerm/internal/services/eventhub/registration.go index 925ae6354c15..c3b6b53f5ce6 100644 --- a/azurerm/internal/services/eventhub/registration.go +++ b/azurerm/internal/services/eventhub/registration.go @@ -44,11 +44,6 @@ func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { } } -// PackagePath is the relative path to this package -func (r Registration) PackagePath() string { - return "TODO" -} - // DataSources returns a list of Data Sources supported by this Service func (r Registration) DataSources() []sdk.DataSource { return []sdk.DataSource{} diff --git a/azurerm/internal/services/loadbalancer/registration.go b/azurerm/internal/services/loadbalancer/registration.go index 98862829f576..51b7a883879a 100644 --- a/azurerm/internal/services/loadbalancer/registration.go +++ b/azurerm/internal/services/loadbalancer/registration.go @@ -49,11 +49,6 @@ func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { } } -// PackagePath is the relative path to this package -func (r Registration) PackagePath() string { - return "TODO: do we need this?" -} - // Resources returns a list of Resources supported by this Service func (r Registration) Resources() []sdk.Resource { return []sdk.Resource{ diff --git a/azurerm/internal/services/logic/logic_app_workflow_resource.go b/azurerm/internal/services/logic/logic_app_workflow_resource.go index 314cc9a17a5a..8b5e53e08c7a 100644 --- a/azurerm/internal/services/logic/logic_app_workflow_resource.go +++ b/azurerm/internal/services/logic/logic_app_workflow_resource.go @@ -81,7 +81,7 @@ func resourceLogicAppWorkflow() *pluginsdk.Resource { Type: pluginsdk.TypeString, Optional: true, ForceNew: true, - Default: "https://pluginsdk.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#", + Default: "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#", }, "workflow_version": { diff --git a/azurerm/internal/services/managedapplications/managed_application_definition_resource_test.go b/azurerm/internal/services/managedapplications/managed_application_definition_resource_test.go index 33b371b415f8..b5219f53f9bd 100644 --- a/azurerm/internal/services/managedapplications/managed_application_definition_resource_test.go +++ b/azurerm/internal/services/managedapplications/managed_application_definition_resource_test.go @@ -167,7 +167,7 @@ resource "azurerm_managed_application_definition" "test" { create_ui_definition = < **Note:** The `location` field must also be specified when `identity` is specified. + +* `location` - (Optional) The Azure Region where the Policy Assignment should exist. Changing this forces a new Policy Assignment to be created. + +* `metadata` - (Optional) A JSON mapping of any Metadata for this Policy. + +* `not_scopes` - (Optional) Specifies a list of Resource Scopes (for example a Subscription, or a Resource Group) within this Management Group which are excluded from this Policy. + +* `parameters` - (Optional) A JSON mapping of any Parameters for this Policy. Changing this forces a new Management Group Policy Assignment to be created. + +--- + +A `identity` block supports the following: + +* `type` - (Optional) The Type of Managed Identity which should be added to this Policy Definition. The only possible value is `SystemAssigned`. + +## Attributes Reference + +In addition to the Arguments listed above - the following Attributes are exported: + +* `id` - The ID of the Management Group Policy Assignment. + +--- + +The `identity` block exports the following: + +* `principal_id` - The Principal ID of the Policy Assignment for this Management Group. + +* `tenant_id` - The Tenant ID of the Policy Assignment for this Management Group. + +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: + +* `create` - (Defaults to 30 minutes) Used when creating the Policy Assignment for this Management Group. +* `read` - (Defaults to 5 minutes) Used when retrieving the Policy Assignment for this Management Group. +* `update` - (Defaults to 30 minutes) Used when updating the Policy Assignment for this Management Group. +* `delete` - (Defaults to 30 minutes) Used when deleting the Policy Assignment for this Management Group. + +## Import + +Management Group Policy Assignments can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_management_group_policy_assignment.example /providers/Microsoft.Management/managementGroups/group1/providers/Microsoft.Authorization/policyAssignments/assignment1 +``` diff --git a/website/docs/r/policy_assignment.html.markdown b/website/docs/r/policy_assignment.html.markdown index dc7d13d36c05..46f6a3b2b2d8 100644 --- a/website/docs/r/policy_assignment.html.markdown +++ b/website/docs/r/policy_assignment.html.markdown @@ -10,6 +10,8 @@ description: |- Configures the specified Policy Definition at the specified Scope. Also, Policy Set Definitions are supported. +!> **Note:** The `azurerm_policy_assignment` resource has been deprecated in favour of the `azurerm_management_group_policy_assignment`, `azurerm_resource_policy_assignment`, `azurerm_resource_group_policy_assignment` and `azurerm_subscription_policy_assignment` resources and will be removed in v3.0 of the Azure Provider. + ## Example Usage ```hcl @@ -88,14 +90,20 @@ The following arguments are supported: * `policy_definition_id` - (Required) The ID of the Policy Definition to be applied at the specified Scope. -* `identity` - (Optional) An `identity` block. - -* `location` - (Optional) The Azure location where this policy assignment should exist. This is required when an Identity is assigned. Changing this forces a new resource to be created. +--- * `description` - (Optional) A description to use for this Policy Assignment. Changing this forces a new resource to be created. * `display_name` - (Optional) A friendly display name to use for this Policy Assignment. Changing this forces a new resource to be created. +* `enforcement_mode`- (Optional) Can be set to 'true' or 'false' to control whether the assignment is enforced (true) or not (false). Default is 'true'. + +* `location` - (Optional) The Azure location where this policy assignment should exist. This is required when an Identity is assigned. Changing this forces a new resource to be created. + +* `identity` - (Optional) An `identity` block. + +-> **Note:** When `identity` is set the `location` field must also be set. + * `metadata` - (Optional) The metadata for the policy assignment. This is a JSON string representing additional metadata that should be stored with the policy assignment. * `parameters` - (Optional) Parameters for the policy definition. This field is a JSON string that maps to the Parameters field from the Policy Definition. Changing this forces a new resource to be created. @@ -104,13 +112,11 @@ The following arguments are supported: * `not_scopes` - (Optional) A list of the Policy Assignment's excluded scopes. The list must contain Resource IDs (such as Subscriptions e.g. `/subscriptions/00000000-0000-0000-000000000000` or Resource Groups e.g.`/subscriptions/00000000-0000-0000-000000000000/resourceGroups/myResourceGroup`). -* `enforcement_mode`- (Optional) Can be set to 'true' or 'false' to control whether the assignment is enforced (true) or not (false). Default is 'true'. - --- An `identity` block supports the following: -* `type` - (Required) The Managed Service Identity Type of this Policy Assignment. Possible values are `SystemAssigned` (where Azure will generate a Service Principal for you), or `None` (no use of a Managed Service Identity). +* `type` - (Required) The type of Managed Identity for this Policy Assignment. Possible values are `SystemAssigned` (where Azure will generate a Service Principal for you). ~> **NOTE:** When `type` is set to `SystemAssigned`, identity the Principal ID can be retrieved after the policy has been assigned. diff --git a/website/docs/r/resource_group_policy_assignment.html.markdown b/website/docs/r/resource_group_policy_assignment.html.markdown new file mode 100644 index 000000000000..a7e10a0e3505 --- /dev/null +++ b/website/docs/r/resource_group_policy_assignment.html.markdown @@ -0,0 +1,113 @@ +--- +subcategory: "Policy" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_resource_group_policy_assignment" +description: |- + Manages a Resource Group Policy Assignment. +--- + +# azurerm_resource_group_policy_assignment + +Manages a Resource Group Policy Assignment. + +## Example Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "example-resources" + location = "West Europe" +} + +resource "azurerm_policy_definition" "example" { + name = "only-deploy-in-westeurope" + policy_type = "Custom" + mode = "All" + + policy_rule = < **Note:** The `location` field must also be specified when `identity` is specified. + +* `location` - (Optional) The Azure Region where the Policy Assignment should exist. Changing this forces a new Policy Assignment to be created. + +* `metadata` - (Optional) A JSON mapping of any Metadata for this Policy. + +* `not_scopes` - (Optional) Specifies a list of Resource Scopes (for example a Subscription, or a Resource Group) within this Management Group which are excluded from this Policy. + +* `parameters` - (Optional) A JSON mapping of any Parameters for this Policy. Changing this forces a new Management Group Policy Assignment to be created. + +--- + +A `identity` block supports the following: + +* `type` - (Optional) The Type of Managed Identity which should be added to this Policy Definition. The only possible value is `SystemAssigned`. + +## Attributes Reference + +In addition to the Arguments listed above - the following Attributes are exported: + +* `id` - The ID of the Resource Group Policy Assignment. + +--- + +The `identity` block exports the following: + +* `principal_id` - The Principal ID of the Policy Assignment for this Resource Group. + +* `tenant_id` - The Tenant ID of the Policy Assignment for this Resource Group. + +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: + +* `create` - (Defaults to 30 minutes) Used when creating the Policy Assignment for this Resource Group. +* `read` - (Defaults to 5 minutes) Used when retrieving the Policy Assignment for this Resource Group. +* `update` - (Defaults to 30 minutes) Used when updating the Policy Assignment for this Resource Group. +* `delete` - (Defaults to 30 minutes) Used when deleting the Policy Assignment for this Resource Group. + +## Import + +Resource Group Policy Assignments can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_resource_group_policy_assignment.example /subscriptions/00000000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Authorization/policyAssignments/assignment1 +``` diff --git a/website/docs/r/resource_policy_assignment.html.markdown b/website/docs/r/resource_policy_assignment.html.markdown new file mode 100644 index 000000000000..1cc6a4a3bc05 --- /dev/null +++ b/website/docs/r/resource_policy_assignment.html.markdown @@ -0,0 +1,117 @@ +--- +subcategory: "Policy" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_resource_policy_assignment" +description: |- + Manages a Policy Assignment to a Resource. +--- + +# azurerm_resource_policy_assignment + +Manages a Policy Assignment to a Resource. + +## Example Usage + +```hcl +data "azurerm_virtual_network" "example" { + name = "production" + resource_group_name = "networking" +} + +resource "azurerm_policy_definition" "example" { + name = "only-deploy-in-westeurope" + policy_type = "Custom" + mode = "All" + + policy_rule = < To create a Policy Assignment at a Management Group use the `azurerm_management_group_policy_assignment` resource, for a Resource Group use the `azurerm_resource_group_policy_assignment` and for a Subscription use the `azurerm_subscription_policy_assignment` resource. + +--- + +* `description` - (Optional) A description which should be used for this Policy Assignment. + +* `display_name` - (Optional) The Display Name for this Policy Assignment. + +* `enforce` - (Optional) Specifies if this Policy should be enforced or not? + +* `identity` - (Optional) A `identity` block as defined below. + +-> **Note:** The `location` field must also be specified when `identity` is specified. + +* `location` - (Optional) The Azure Region where the Policy Assignment should exist. Changing this forces a new Policy Assignment to be created. + +* `metadata` - (Optional) A JSON mapping of any Metadata for this Policy. + +* `not_scopes` - (Optional) Specifies a list of Resource Scopes (for example a Subscription, or a Resource Group) within this Management Group which are excluded from this Policy. + +* `parameters` - (Optional) A JSON mapping of any Parameters for this Policy. Changing this forces a new Management Group Policy Assignment to be created. + +--- + +A `identity` block supports the following: + +* `type` - (Optional) The Type of Managed Identity which should be added to this Policy Definition. The only possible value is `SystemAssigned`. + +## Attributes Reference + +In addition to the Arguments listed above - the following Attributes are exported: + +* `id` - The ID of the Resource Policy Assignment. + +--- + +The `identity` block exports the following: + +* `principal_id` - The Principal ID of the Policy Assignment for this Resource. + +* `tenant_id` - The Tenant ID of the Policy Assignment for this Resource. + +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: + +* `create` - (Defaults to 30 minutes) Used when creating the Policy Assignment for this Resource. +* `read` - (Defaults to 5 minutes) Used when retrieving the Policy Assignment for this Resource. +* `update` - (Defaults to 30 minutes) Used when updating the Policy Assignment for this Resource. +* `delete` - (Defaults to 30 minutes) Used when deleting the Policy Assignment for this Resource. + +## Import + +Resource Policy Assignments can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_resource_policy_assignment.example "{resource}/providers/Microsoft.Authorization/policyAssignments/assignment1" +``` + +where `{resource}` is a Resource ID in the form `/subscriptions/00000000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Network/virtualNetworks/network1`. diff --git a/website/docs/r/subscription_policy_assignment.html.markdown b/website/docs/r/subscription_policy_assignment.html.markdown new file mode 100644 index 000000000000..69e56e956936 --- /dev/null +++ b/website/docs/r/subscription_policy_assignment.html.markdown @@ -0,0 +1,110 @@ +--- +subcategory: "Policy" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_subscription_policy_assignment" +description: |- + Manages a Subscription Policy Assignment. +--- + +# azurerm_subscription_policy_assignment + +Manages a Subscription Policy Assignment. + +## Example Usage + +```hcl +data "azurerm_subscription" "current" {} + +resource "azurerm_policy_definition" "example" { + name = "only-deploy-in-westeurope" + policy_type = "Custom" + mode = "All" + + policy_rule = < **Note:** The `location` field must also be specified when `identity` is specified. + +* `location` - (Optional) The Azure Region where the Policy Assignment should exist. Changing this forces a new Policy Assignment to be created. + +* `metadata` - (Optional) A JSON mapping of any Metadata for this Policy. + +* `not_scopes` - (Optional) Specifies a list of Resource Scopes (for example a Subscription, or a Resource Group) within this Management Group which are excluded from this Policy. + +* `parameters` - (Optional) A JSON mapping of any Parameters for this Policy. Changing this forces a new Management Group Policy Assignment to be created. + +--- + +A `identity` block supports the following: + +* `type` - (Optional) The Type of Managed Identity which should be added to this Policy Definition. The only possible value is `SystemAssigned`. + +## Attributes Reference + +In addition to the Arguments listed above - the following Attributes are exported: + +* `id` - The ID of the Subscription Policy Assignment. + +--- + +The `identity` block exports the following: + +* `principal_id` - The Principal ID of the Policy Assignment for this Subscription. + +* `tenant_id` - The Tenant ID of the Policy Assignment for this Subscription. + +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: + +* `create` - (Defaults to 30 minutes) Used when creating the Policy Assignment for this Subscription. +* `read` - (Defaults to 5 minutes) Used when retrieving the Policy Assignment for this Subscription. +* `update` - (Defaults to 30 minutes) Used when updating the Policy Assignment for this Subscription. +* `delete` - (Defaults to 30 minutes) Used when deleting the Policy Assignment for this Subscription. + +## Import + +Subscription Policy Assignments can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_subscription_policy_assignment.example /subscriptions/00000000-0000-0000-000000000000/providers/Microsoft.Authorization/policyAssignments/assignment1 +```