Skip to content

Commit

Permalink
Code review changes (fixes #1239)
Browse files Browse the repository at this point in the history
  • Loading branch information
josemanuelt committed May 30, 2018
1 parent deeaac5 commit b9f3b97
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion google/resource_google_folder_organization_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ resource "google_folder" "orgpolicy" {
}
resource "google_folder_organization_policy" "bool" {
# Test numeric folder ID.
# Test numeric folder ID.
folder = "${replace(google_folder.orgpolicy.name, "folders/", "")}"
constraint = "constraints/compute.disableSerialPortAccess"
Expand Down
25 changes: 13 additions & 12 deletions google/resource_google_organization_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ var schemaOrganizationPolicy = map[string]*schema.Schema{
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"default": {
Type: schema.TypeBool,
Required: true,
Type: schema.TypeBool,
Required: true,
ValidateFunc: validateDefaultPolicyValue,
},
},
},
Expand Down Expand Up @@ -248,10 +249,10 @@ func flattenBooleanOrganizationPolicy(policy *cloudresourcemanager.BooleanPolicy
return bPolicies
}

func flattenRestoreOrganizationPolicy(restore_policy *cloudresourcemanager.RestoreDefault) []map[string]interface{} {
func flattenRestoreOrganizationPolicy(restorePolicy *cloudresourcemanager.RestoreDefault) []map[string]interface{} {
rp := make([]map[string]interface{}, 0, 1)

if restore_policy == nil {
if restorePolicy == nil {
return rp
}

Expand All @@ -278,14 +279,7 @@ func expandRestoreOrganizationPolicy(configured []interface{}) (*cloudresourcema
return nil, nil
}

restoreDefaultMap := configured[0].(map[string]interface{})
default_value := restoreDefaultMap["default"].(bool)

if default_value {
return &cloudresourcemanager.RestoreDefault{}, nil
}

return nil, fmt.Errorf("Invalid value for restore_policy. Expecting default = true")
return &cloudresourcemanager.RestoreDefault{}, nil
}

func flattenListOrganizationPolicy(policy *cloudresourcemanager.ListPolicy) []map[string]interface{} {
Expand Down Expand Up @@ -372,3 +366,10 @@ func canonicalOrgPolicyConstraint(constraint string) string {
}
return "constraints/" + constraint
}

func validateDefaultPolicyValue(v interface{}, k string) (warnings []string, errors []error) {
if v != true {
errors = append(errors, fmt.Errorf("Invalid value for restore_policy. Expecting default = true"))
}
return
}
4 changes: 2 additions & 2 deletions google/resource_google_project_organization_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func setProjectOrganizationPolicy(d *schema.ResourceData, meta interface{}) erro
return err
}

restore_default, err := expandRestoreOrganizationPolicy(d.Get("restore_policy").([]interface{}))
restoreDefault, err := expandRestoreOrganizationPolicy(d.Get("restore_policy").([]interface{}))
if err != nil {
return err
}
Expand All @@ -102,7 +102,7 @@ func setProjectOrganizationPolicy(d *schema.ResourceData, meta interface{}) erro
Constraint: canonicalOrgPolicyConstraint(d.Get("constraint").(string)),
BooleanPolicy: expandBooleanOrganizationPolicy(d.Get("boolean_policy").([]interface{})),
ListPolicy: listPolicy,
RestoreDefault: restore_default,
RestoreDefault: restoreDefault,
Version: int64(d.Get("version").(int)),
Etag: d.Get("etag").(string),
},
Expand Down
6 changes: 3 additions & 3 deletions google/resource_google_project_organization_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,9 @@ resource "google_project_organization_policy" "restore" {
project = "%s"
constraint = "constraints/serviceuser.services"
restore_policy {
default = true
}
restore_policy {
default = true
}
}
`, pid)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ The following arguments are supported:

* `boolean_policy` - (Optional) A boolean policy is a constraint that is either enforced or not. Structure is documented below.

* `list_policy` - (Optional) A policy that can define specific values that are allowed or denied for the given constraint. It
can also be used to allow or deny all values. Structure is documented below.
* `list_policy` - (Optional) A policy that can define specific values that are allowed or denied for the given constraint. It can also be used to allow or deny all values. Structure is documented below.

* `restore_policy` - (Optional) A restore policy is a constraint to restore the default policy. Structure is documented below.

Expand All @@ -114,7 +113,7 @@ The `allow` or `deny` blocks support:

The `restore_policy` block supports:

* `default` - (Required) If true, then the default Policy is restored. If false, then any configuration is acceptable.
* `default` - (Required) Only can use true, then the default Policy is restored.

## Attributes Reference

Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/google_organization_policy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ The `allow` or `deny` blocks support:

The `restore_policy` block supports:

* `default` - (Required) If true, then the default Policy is restored. If false, then any configuration is acceptable.
* `default` - (Required) Only can use true, then the default Policy is restored.

## Attributes Reference

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ The `allow` or `deny` blocks support:

The `restore_policy` block supports:

* `default` - (Required) If true, then the default Policy is restored. If false, then any configuration is acceptable.
* `default` - (Required) Only can use true, then the default Policy is restored.

## Attributes Reference

Expand Down

0 comments on commit b9f3b97

Please sign in to comment.