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

policy: fixing and superseding azurerm_policy_assignment #12349

Merged
merged 30 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d7c6ed3
r/policy_assignment: matching the behaviour of the identity block wit…
tombuildsstuff Jun 22, 2021
ed3c08b
r/policy_assignment: refactoring
tombuildsstuff Jun 22, 2021
0a990e3
policy: refactoring out the common metadata
tombuildsstuff Jun 22, 2021
f9fe945
r/policy_assignment: refactoring to use the identity block
tombuildsstuff Jun 22, 2021
0c5fa19
r/policy_assignment: waiting consistently until the policy assignment…
tombuildsstuff Jun 22, 2021
16b13b3
r/policy_assignment: support for delta updates
tombuildsstuff Jun 22, 2021
529f1b5
r/policy_assignment: fixing an issue when parsing the ID
tombuildsstuff Jun 22, 2021
1d392bb
r/policy_assignment: removing the unnecessary `PolicyScopeId` from th…
tombuildsstuff Jun 22, 2021
ea6aed8
r/policy_assignment: updating the log messages for create/update
tombuildsstuff Jun 22, 2021
fd653d1
r/policy_assignment: updating the tests
tombuildsstuff Jun 22, 2021
dd9faf3
fixing the azure schema uri
tombuildsstuff Jun 23, 2021
5b13787
sdk: support for Typed Resources without models
tombuildsstuff Jun 23, 2021
2090e32
policy: supporting typed resources
tombuildsstuff Jun 23, 2021
e05980f
New Resource: `azurerm_resource_group_policy_assignment`
tombuildsstuff Jun 23, 2021
6b2c1e0
New Resource: `azurerm_subscription_policy_assignment`
tombuildsstuff Jun 23, 2021
a84de8a
policy: assignment name can vary per resource
tombuildsstuff Jun 23, 2021
618501a
New Resource: `azurerm_management_group_policy_assignment`
tombuildsstuff Jun 23, 2021
30500bf
New Resource: `azurerm_resource_policy_assignment`
tombuildsstuff Jun 23, 2021
a9ed9b4
r/policy_assignment: reverting the changes to the identity block
tombuildsstuff Jun 23, 2021
d1df2d8
r/policy_assignment: refactoring
tombuildsstuff Jun 23, 2021
e1a465c
r/management_group_policy_assignment: adding a complex policy definition
tombuildsstuff Jun 24, 2021
58dbac8
sdk: removing the unused PackagePath method
tombuildsstuff Jun 24, 2021
1c1214d
r/policy_assignment: deprecating in favour of the new resources
tombuildsstuff Jun 24, 2021
3cc35eb
r/policy_assignment: removing support in 3.0 mode
tombuildsstuff Jun 24, 2021
a3ed1db
r/management_group_policy_assignment: adding documentation
tombuildsstuff Jun 24, 2021
0df62ef
r/resource_policy_assignment: adding docs
tombuildsstuff Jun 24, 2021
55f0a5b
r/resource_group_policy_assignment: adding docs
tombuildsstuff Jun 24, 2021
5b0dd7e
r/subscription_policy_assignment: adding docs
tombuildsstuff Jun 24, 2021
ab50b68
linting
tombuildsstuff Jun 30, 2021
c7f884c
lint
mbfrahry Jun 30, 2021
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
1 change: 1 addition & 0 deletions azurerm/internal/provider/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func SupportedTypedServices() []sdk.TypedServiceRegistration {
return []sdk.TypedServiceRegistration{
eventhub.Registration{},
loadbalancer.Registration{},
policy.Registration{},
resource.Registration{},
web.Registration{},
}
Expand Down
3 changes: 0 additions & 3 deletions azurerm/internal/sdk/service_registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions azurerm/internal/sdk/wrapper_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions azurerm/internal/sdk/wrapper_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 0 additions & 5 deletions azurerm/internal/services/eventhub/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
5 changes: 0 additions & 5 deletions azurerm/internal/services/loadbalancer/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ resource "azurerm_managed_application_definition" "test" {

create_ui_definition = <<CREATE_UI_DEFINITION
{
"$schema": "https://pluginsdk.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview",
"parameters": {
Expand Down Expand Up @@ -216,7 +216,7 @@ resource "azurerm_managed_application_definition" "test" {

main_template = <<MAIN_TEMPLATE
{
"$schema": "https://pluginsdk.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageAccountNamePrefix": {
Expand Down
58 changes: 58 additions & 0 deletions azurerm/internal/services/policy/assignment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package policy

import (
"context"
"fmt"
"strconv"
"time"

"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2019-09-01/policy"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/policy/parse"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/pluginsdk"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func convertEnforcementMode(mode bool) policy.EnforcementMode {
if mode {
return policy.Default
} else {
return policy.DoNotEnforce
}
}

func waitForPolicyAssignmentToStabilize(ctx context.Context, client *policy.AssignmentsClient, id parse.PolicyAssignmentId, shouldExist bool) error {
deadline, ok := ctx.Deadline()
if !ok {
return fmt.Errorf("context was missing a deadline")
}
stateConf := &pluginsdk.StateChangeConf{
Pending: []string{"404"},
Target: []string{"200"},
Refresh: func() (interface{}, string, error) {
resp, err := client.Get(ctx, id.Scope, id.Name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return resp, strconv.Itoa(resp.StatusCode), nil
}

return nil, strconv.Itoa(resp.StatusCode), fmt.Errorf("polling for %s: %+v", id, err)
}

return resp, strconv.Itoa(resp.StatusCode), nil
},
MinTimeout: 10 * time.Second,
ContinuousTargetOccurence: 20,
PollInterval: 5 * time.Second,
Timeout: time.Until(deadline),
}
if !shouldExist {
stateConf.Pending = []string{"200"}
stateConf.Target = []string{"404"}
}

if _, err := stateConf.WaitForStateContext(ctx); err != nil {
return err
}

return nil
}
Loading