Skip to content

Unable to use the module #6

@alwaysharsha

Description

@alwaysharsha

I am trying to use the module with the provided examples, but each time I am getting error

Error

λ  terraform plan
│ Error: Missing required argument
│   on main.tf line 16, in module "policies":
│   16: module "policies" {
│ The argument "policy_definition_id" is required, but no definition was found.

Code

terraform {
  required_version = ">= 0.13"
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "> 2.0"
    }
  }
}

provider "azurerm" {
  features {}
}

module "policies" {
  source  = "OT-terraform-azure-modules/policies/azure"
  version = "0.0.1"
  ### insert the 7 required variables here
  policy_manner       = "Policy"
  policy_name         = "test"
  policy_type         = "Custom"
  mode                = "All"
  policy_display_name = "test policy"
  policy_rule         = {
    "if" : {
      "not" : {
        "field" : "location"
        "in" : "[parameters('allowedLocations')]"
      }
    },
    "then" : {
      "effect" : "deny"
    }
  }
  policy_parameters   = {
    "allowedLocations" : {
      "type" : "Array",
      "metadata" : {
        "description" : "The list of allowed locations for resources.",
        "displayName" : "Allowed locations",
        "strongType" : "location"
      }
    }
  }
  metadata            = {
    "category" : "General"
  }

  policy_def_scope_type  = "subscription"
  policy_assignment_name = "testassign"
  subscription_id      = "/subscriptions/XXXXXXXX-XXXX-1111-2222-XXXXXXXXXXXXXXX"
  assignment_location    = "eastus"
  assignment_parameters  = {
          "allowedLocations": {
            "value": [ "East US" ]
          }
        }
}


module "policies2" {
  source  = "OT-terraform-azure-modules/policies/azure"
  version = "0.0.1"
  ### insert the 7 required variables here

  policy_manner       = "Initiative"
  policy_name         = "HSTest"
  policy_type         = "Custom"
  mode                = "All"
  policy_display_name = "HS Test policy"
  metadata            = {
    "category" : "General"
  }

  initiative_policy_definition_reference = [{
    "policyID" = "/providers/Microsoft.Authorization/policyDefinitions/06a78e20-9358-41c9-923c-fb736d382a4d"
    "reference_id" = "Audit VMs that do not use managed disks"
  },
  {
    "policyID" = "/providers/Microsoft.Authorization/policyDefinitions/0015ea4d-51ff-4ce3-8d8c-f3f8f0179a56"
    "reference_id" = "Audit virtual machines without disaster recovery configured"
  }]

  policy_def_scope_type  = "resource-group"
  policy_assignment_name = "testassign"
  resource_group_id      = "/subscriptions/XXXXXXXX-XXXX-1111-2222-XXXXXXXXXXXXXXX/resourceGroups/HSTest"
  assignment_location    = "eastus"

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions