-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new data source for built-in policy definition
- Loading branch information
Showing
7 changed files
with
187 additions
and
123 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
20 changes: 20 additions & 0 deletions
20
internal/services/policy/policy_definition_built_in_data_source.go
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,20 @@ | ||
package policy | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" | ||
) | ||
|
||
// dataSourceArmPolicyDefinitionBuiltIn read built-in policy definition only | ||
func dataSourceArmPolicyDefinitionBuiltIn() *pluginsdk.Resource { | ||
return &pluginsdk.Resource{ | ||
Read: policyDefinitionReadFunc(true), | ||
|
||
Timeouts: &pluginsdk.ResourceTimeout{ | ||
Read: pluginsdk.DefaultTimeout(5 * time.Minute), | ||
}, | ||
|
||
Schema: policyDefinitionDataSourceSchema(), | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
internal/services/policy/policy_definition_built_in_data_source_test.go
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,42 @@ | ||
package policy_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" | ||
) | ||
|
||
type PolicyDefinitionBuiltInDataSource struct{} | ||
|
||
func TestAccDataSourceAzureRMPolicyDefinitionBuiltIn_basic(t *testing.T) { | ||
data := acceptance.BuildTestData(t, "data.azurerm_policy_definition_built_in", "test") | ||
d := PolicyDefinitionBuiltInDataSource{} | ||
|
||
data.DataSourceTest(t, []acceptance.TestStep{ | ||
{ | ||
Config: d.basic("Allowed resource types"), | ||
Check: acceptance.ComposeTestCheckFunc( | ||
check.That(data.ResourceName).Key("id").HasValue("/providers/Microsoft.Authorization/policyDefinitions/a08ec900-254a-4555-9bf5-e42af04b5c5c"), | ||
check.That(data.ResourceName).Key("name").HasValue("a08ec900-254a-4555-9bf5-e42af04b5c5c"), | ||
check.That(data.ResourceName).Key("display_name").HasValue("Allowed resource types"), | ||
check.That(data.ResourceName).Key("type").HasValue("Microsoft.Authorization/policyDefinitions"), | ||
check.That(data.ResourceName).Key("description").HasValue("This policy enables you to specify the resource types that your organization can deploy. Only resource types that support 'tags' and 'location' will be affected by this policy. To restrict all resources please duplicate this policy and change the 'mode' to 'All'."), | ||
check.That(data.ResourceName).Key("mode").HasValue("Indexed"), | ||
), | ||
}, | ||
}) | ||
} | ||
|
||
func (d PolicyDefinitionBuiltInDataSource) basic(name string) string { | ||
return fmt.Sprintf(` | ||
provider "azurerm" { | ||
features {} | ||
} | ||
data "azurerm_policy_definition_built_in" "test" { | ||
display_name = "%s" | ||
} | ||
`, name) | ||
} |
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
Oops, something went wrong.