Skip to content

Commit 6b75d24

Browse files
chrisstmodular-magician
authored andcommitted
Add import support for organization_policies
Signed-off-by: Modular Magician <[email protected]>
1 parent 6aabf31 commit 6b75d24

7 files changed

+102
-7
lines changed

google/resource_google_folder_organization_policy.go

+16
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package google
22

33
import (
44
"fmt"
5+
"strings"
56

67
"github.com/hashicorp/terraform/helper/schema"
78
"google.golang.org/api/cloudresourcemanager/v1"
@@ -14,6 +15,10 @@ func resourceGoogleFolderOrganizationPolicy() *schema.Resource {
1415
Update: resourceGoogleFolderOrganizationPolicyUpdate,
1516
Delete: resourceGoogleFolderOrganizationPolicyDelete,
1617

18+
Importer: &schema.ResourceImporter{
19+
State: resourceFolderOrgPolicyImporter,
20+
},
21+
1722
Schema: mergeSchemas(
1823
schemaOrganizationPolicy,
1924
map[string]*schema.Schema{
@@ -27,6 +32,17 @@ func resourceGoogleFolderOrganizationPolicy() *schema.Resource {
2732
}
2833
}
2934

35+
func resourceFolderOrgPolicyImporter(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
36+
parts := strings.Split(d.Id(), ":")
37+
if len(parts) != 2 {
38+
return nil, fmt.Errorf("ID must be in the format folders/<folderId>:constraints/<constraint>")
39+
}
40+
d.Set("folder", parts[0])
41+
d.Set("constraint", parts[1])
42+
43+
return []*schema.ResourceData{d}, nil
44+
}
45+
3046
func resourceGoogleFolderOrganizationPolicyCreate(d *schema.ResourceData, meta interface{}) error {
3147
if err := setFolderOrganizationPolicy(d, meta); err != nil {
3248
return err

google/resource_google_folder_organization_policy_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ func TestAccFolderOrganizationPolicy_list_allowAll(t *testing.T) {
6666
Config: testAccFolderOrganizationPolicy_list_allowAll(org, folder),
6767
Check: testAccCheckGoogleFolderOrganizationListPolicyAll("list", "ALLOW"),
6868
},
69+
{
70+
ResourceName: "google_folder_organization_policy.list",
71+
ImportState: true,
72+
ImportStateVerify: true,
73+
},
6974
},
7075
})
7176
}
@@ -85,6 +90,11 @@ func TestAccFolderOrganizationPolicy_list_allowSome(t *testing.T) {
8590
Config: testAccFolderOrganizationPolicy_list_allowSome(org, folder, project),
8691
Check: testAccCheckGoogleFolderOrganizationListPolicyAllowedValues("list", []string{"projects/" + project}),
8792
},
93+
{
94+
ResourceName: "google_folder_organization_policy.list",
95+
ImportState: true,
96+
ImportStateVerify: true,
97+
},
8898
},
8999
})
90100
}
@@ -103,6 +113,11 @@ func TestAccFolderOrganizationPolicy_list_denySome(t *testing.T) {
103113
Config: testAccFolderOrganizationPolicy_list_denySome(org, folder),
104114
Check: testAccCheckGoogleFolderOrganizationListPolicyDeniedValues("list", DENIED_ORG_POLICIES),
105115
},
116+
{
117+
ResourceName: "google_folder_organization_policy.list",
118+
ImportState: true,
119+
ImportStateVerify: true,
120+
},
106121
},
107122
})
108123
}
@@ -125,6 +140,11 @@ func TestAccFolderOrganizationPolicy_list_update(t *testing.T) {
125140
Config: testAccFolderOrganizationPolicy_list_denySome(org, folder),
126141
Check: testAccCheckGoogleFolderOrganizationListPolicyDeniedValues("list", DENIED_ORG_POLICIES),
127142
},
143+
{
144+
ResourceName: "google_folder_organization_policy.list",
145+
ImportState: true,
146+
ImportStateVerify: true,
147+
},
128148
},
129149
})
130150
}
@@ -143,6 +163,11 @@ func TestAccFolderOrganizationPolicy_restore_defaultTrue(t *testing.T) {
143163
Config: testAccFolderOrganizationPolicy_restore_defaultTrue(org, folder),
144164
Check: getGoogleFolderOrganizationRestoreDefaultTrue("restore", &cloudresourcemanager.RestoreDefault{}),
145165
},
166+
{
167+
ResourceName: "google_folder_organization_policy.restore",
168+
ImportState: true,
169+
ImportStateVerify: true,
170+
},
146171
},
147172
})
148173
}

google/resource_google_project_organization_policy.go

+16
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package google
22

33
import (
44
"fmt"
5+
"strings"
56

67
"github.com/hashicorp/terraform/helper/schema"
78
"google.golang.org/api/cloudresourcemanager/v1"
@@ -14,6 +15,10 @@ func resourceGoogleProjectOrganizationPolicy() *schema.Resource {
1415
Update: resourceGoogleProjectOrganizationPolicyUpdate,
1516
Delete: resourceGoogleProjectOrganizationPolicyDelete,
1617

18+
Importer: &schema.ResourceImporter{
19+
State: resourceProjectOrgPolicyImporter,
20+
},
21+
1722
Schema: mergeSchemas(
1823
schemaOrganizationPolicy,
1924
map[string]*schema.Schema{
@@ -27,6 +32,17 @@ func resourceGoogleProjectOrganizationPolicy() *schema.Resource {
2732
}
2833
}
2934

35+
func resourceProjectOrgPolicyImporter(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
36+
parts := strings.Split(d.Id(), ":")
37+
if len(parts) != 2 {
38+
return nil, fmt.Errorf("ID must be in the format <projectId>:constraints/<constraint>")
39+
}
40+
d.Set("project", parts[0])
41+
d.Set("constraint", parts[1])
42+
43+
return []*schema.ResourceData{d}, nil
44+
}
45+
3046
func resourceGoogleProjectOrganizationPolicyCreate(d *schema.ResourceData, meta interface{}) error {
3147
if err := setProjectOrganizationPolicy(d, meta); err != nil {
3248
return err

google/resource_google_project_organization_policy_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ func testAccProjectOrganizationPolicy_list_allowAll(t *testing.T) {
8484
Config: testAccProjectOrganizationPolicyConfig_list_allowAll(projectId),
8585
Check: testAccCheckGoogleProjectOrganizationListPolicyAll("list", "ALLOW"),
8686
},
87+
{
88+
ResourceName: "google_project_organization_policy.list",
89+
ImportState: true,
90+
ImportStateVerify: true,
91+
},
8792
},
8893
})
8994
}
@@ -100,6 +105,11 @@ func testAccProjectOrganizationPolicy_list_allowSome(t *testing.T) {
100105
Config: testAccProjectOrganizationPolicyConfig_list_allowSome(project),
101106
Check: testAccCheckGoogleProjectOrganizationListPolicyAllowedValues("list", []string{canonicalProject}),
102107
},
108+
{
109+
ResourceName: "google_project_organization_policy.list",
110+
ImportState: true,
111+
ImportStateVerify: true,
112+
},
103113
},
104114
})
105115
}
@@ -115,6 +125,11 @@ func testAccProjectOrganizationPolicy_list_denySome(t *testing.T) {
115125
Config: testAccProjectOrganizationPolicyConfig_list_denySome(projectId),
116126
Check: testAccCheckGoogleProjectOrganizationListPolicyDeniedValues("list", DENIED_ORG_POLICIES),
117127
},
128+
{
129+
ResourceName: "google_project_organization_policy.list",
130+
ImportState: true,
131+
ImportStateVerify: true,
132+
},
118133
},
119134
})
120135
}
@@ -134,6 +149,11 @@ func testAccProjectOrganizationPolicy_list_update(t *testing.T) {
134149
Config: testAccProjectOrganizationPolicyConfig_list_denySome(projectId),
135150
Check: testAccCheckGoogleProjectOrganizationListPolicyDeniedValues("list", DENIED_ORG_POLICIES),
136151
},
152+
{
153+
ResourceName: "google_project_organization_policy.list",
154+
ImportState: true,
155+
ImportStateVerify: true,
156+
},
137157
},
138158
})
139159
}
@@ -150,6 +170,11 @@ func testAccProjectOrganizationPolicy_restore_defaultTrue(t *testing.T) {
150170
Config: testAccProjectOrganizationPolicyConfig_restore_defaultTrue(projectId),
151171
Check: getGoogleProjectOrganizationRestoreDefaultTrue("restore", &cloudresourcemanager.RestoreDefault{}),
152172
},
173+
{
174+
ResourceName: "google_project_organization_policy.restore",
175+
ImportState: true,
176+
ImportStateVerify: true,
177+
},
153178
},
154179
})
155180
}

website/docs/r/google_folder_organization_policy.html.markdown

+8
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,11 @@ exported:
127127
* `etag` - (Computed) The etag of the organization policy. `etag` is used for optimistic concurrency control as a way to help prevent simultaneous updates of a policy from overwriting each other.
128128

129129
* `update_time` - (Computed) The timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds, representing when the variable was last updated. Example: "2016-10-09T12:33:37.578138407Z".
130+
131+
## Import
132+
133+
Folder organization policies can be imported with the format `folders/<folderId>:constraints/<constraint>`. eg
134+
135+
```
136+
$ terraform import google_folder_organization_policy.policy folders/folder-1234:constraints/serviceuser.services
137+
```

website/docs/r/google_project_organization_policy.html.markdown

+9-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ The following arguments are supported:
9191

9292
* `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.
9393

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

9696
- - -
9797

@@ -126,3 +126,11 @@ exported:
126126
* `etag` - (Computed) The etag of the organization policy. `etag` is used for optimistic concurrency control as a way to help prevent simultaneous updates of a policy from overwriting each other.
127127

128128
* `update_time` - (Computed) The timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds, representing when the variable was last updated. Example: "2016-10-09T12:33:37.578138407Z".
129+
130+
## Import
131+
132+
Project organization policies can be imported with the format `<projectId>:constraints/<constraint>`. eg
133+
134+
```
135+
$ terraform import google_project_organization_policy.policy test-project:constraints/serviceuser.services
136+
```

website/docs/r/sql_ssl_cert.html.markdown

+3-6
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,9 @@ The following arguments are supported:
3939
* `instance` - (Required) The name of the Cloud SQL instance. Changing this
4040
forces a new resource to be created.
4141

42-
* `common_name` - (Required) The common name to be used in the certificate to identify the
42+
* `common_name` - (Required) The common name to be used in the certificate to identify the
4343
client. Constrained to [a-zA-Z.-_ ]+. Changing this forces a new resource to be created.
4444

45-
* `project` - (Optional) The ID of the project in which the resource belongs. If it
46-
is not provided, the provider project is used.
47-
4845

4946
## Attributes Reference
5047

@@ -56,9 +53,9 @@ exported:
5653
* `server_ca_cert` - The CA cert of the server this client cert was generated from.
5754
* `cert` - The actual certificate data for this client certificate.
5855
* `cert_serial_number` - The serial number extracted from the certificate data.
59-
* `create_time` - The time when the certificate was created in RFC 3339 format,
56+
* `create_time` - The time when the certificate was created in RFC 3339 format,
6057
for example 2012-11-15T16:19:00.094Z.
61-
* `expiration_time` - The time when the certificate expires in RFC 3339 format,
58+
* `expiration_time` - The time when the certificate expires in RFC 3339 format,
6259
for example 2012-11-15T16:19:00.094Z.
6360

6461
## Import

0 commit comments

Comments
 (0)