Skip to content

Commit

Permalink
Support compartment renaming
Browse files Browse the repository at this point in the history
* Denormalize not really normal shared schemas in helpers_identity + policy + compartments
  * remove dead code/schema defs in helpers_identity
* fix some copy/paste errors in related docs/datasources
  • Loading branch information
ccushing committed Sep 27, 2017
1 parent 98ffeee commit f37f28b
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 133 deletions.
4 changes: 2 additions & 2 deletions docs/datasources/identity/compartment.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ The following arguments are supported:
## Attribute Reference
* `compartments` - A list of compartments

## Group Reference
## Compartment Reference
* `id` - The OCID of the compartment.
* `compartment_id` - The OCID of the tenancy containing the compartment.
* `name` - The name you assign to the compartment during creation. The name must be unique across all compartments in the tenancy and cannot be changed.
* `name` - The name you assign to the compartment during creation. The name must be unique across all compartments in the tenancy, and it's changeable.
* `description` - The description you assign to the compartment. Does not have to be unique, and it's changeable.
* `time_created` - Date and time the compartment was created.
* `state` - The compartment's current state. [CREATING, ACTIVE, INACTIVE, DELETING, DELETED]
Expand Down
2 changes: 1 addition & 1 deletion docs/datasources/identity/policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The following arguments are supported:
## Attribute Reference
* `policies` - A list of policies

## Group Reference
## Policy Reference
* `id` - The OCID of the policy.
* `compartment_id` - The OCID of the compartment containing the policy (either the tenancy or another compartment).
* `name` - The name you assign to the policy during creation. The name must be unique across all policies in the tenancy and cannot be changed.
Expand Down
2 changes: 1 addition & 1 deletion docs/datasources/identity/user.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The following arguments are supported:
## Attribute Reference
* `users` - A list of users

## Group Reference
## User Reference
* `id` - The OCID of the user.
* `compartment_id` - The OCID of the tenancy containing the user.
* `name` - The name you assign to the user during creation. This is the user's login for the Console. The name must be unique across all users in the tenancy and cannot be changed.
Expand Down
4 changes: 2 additions & 2 deletions docs/resources/identity/compartment.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ resource "oci_identity_compartment" "t" {

The following arguments are supported:

* `name` - (Required) The name you assign to the compartment during creation. The name must be unique across all compartments in the tenancy and cannot be changed.
* `name` - (Required) The name you assign to the compartment during creation. The name must be unique across all compartments in the tenancy, and it's changeable.
* `description` - (Required) The description you assign to the compartment during creation. Does not have to be unique, and it's changeable.

## Attributes Reference
* `id` - The OCID of the compartment.
* `compartment_id` - The OCID of the tenancy containing the compartment.
* `name` - The name you assign to the compartment during creation. The name must be unique across all compartments in the tenancy and cannot be changed.
* `name` - The name you assign to the compartment during creation. The name must be unique across all compartments in the tenancy, and it's changeable.
* `descriptions` - The description you assign to the compartment. Does not have to be unique, and it's changeable.
* `time_created` - Date and time the compartment was created.
* `state` - The compartment's current state. [CREATING, ACTIVE, INACTIVE, DELETING, DELETED]
Expand Down
93 changes: 2 additions & 91 deletions helpers_identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ package main

import "github.com/hashicorp/terraform/helper/schema"

var baseIdentitySchemaWithID = map[string]*schema.Schema{
// User and group happen to have the same schema and share this
var baseIdentitySchema = map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -40,93 +41,3 @@ var baseIdentitySchemaWithID = map[string]*schema.Schema{
Computed: true,
},
}

// Just has a computed compartment_id
var baseIdentitySchema = map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"description": {
Type: schema.TypeString,
Required: true,
},
"compartment_id": {
Type: schema.TypeString,
Computed: true,
},
"state": {
Type: schema.TypeString,
Computed: true,
},
"time_created": {
Type: schema.TypeString,
Computed: true,
},
"time_modified": {
Type: schema.TypeString,
Computed: true,
},
}

var identitySchema = map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"description": {
Type: schema.TypeString,
Required: true,
},
"compartment_id": {
Type: schema.TypeString,
Required: true,
},
"state": {
Type: schema.TypeString,
Computed: true,
},
"time_created": {
Type: schema.TypeString,
Computed: true,
},
"time_modified": {
Type: schema.TypeString,
Computed: true,
},
}

var identitySchemaWithID = map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
ForceNew: true,
},
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"description": {
Type: schema.TypeString,
Required: true,
},
"compartment_id": {
Type: schema.TypeString,
Required: true,
},
"state": {
Type: schema.TypeString,
Computed: true,
},
"time_created": {
Type: schema.TypeString,
Computed: true,
},
"time_modified": {
Type: schema.TypeString,
Computed: true,
},
}
43 changes: 41 additions & 2 deletions resource_obmcs_identity_compartment.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,42 @@ import (

// ResourceIdentityCompartment exposes an IdentityCompartment Resource
func CompartmentResource() *schema.Resource {
compartmentSchema := map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
ForceNew: true,
},
"name": {
Type: schema.TypeString,
Required: true,
},
"description": {
Type: schema.TypeString,
Required: true,
},
"compartment_id": {
Type: schema.TypeString,
Computed: true,
},
"state": {
Type: schema.TypeString,
Computed: true,
},
"inactive_state": {
Type: schema.TypeInt,
Computed: true,
},
"time_created": {
Type: schema.TypeString,
Computed: true,
},
"time_modified": {
Type: schema.TypeString,
Computed: true,
},
}

return &schema.Resource{
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
Expand All @@ -24,7 +60,7 @@ func CompartmentResource() *schema.Resource {
Read: readCompartment,
Update: updateCompartment,
Delete: deleteCompartment,
Schema: baseIdentitySchemaWithID,
Schema: compartmentSchema,
}
}

Expand Down Expand Up @@ -132,7 +168,10 @@ func (s *CompartmentResourceCrud) Get() (e error) {
}

func (s *CompartmentResourceCrud) Update() (e error) {
opts := &baremetal.UpdateIdentityOptions{}
opts := &baremetal.UpdateCompartmentOptions{}
if name, ok := s.D.GetOk("name"); ok {
opts.Name = name.(string)
}
if description, ok := s.D.GetOk("description"); ok {
opts.Description = description.(string)
}
Expand Down
4 changes: 2 additions & 2 deletions resource_obmcs_identity_compartment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ func (s *ResourceIdentityCompartmentTestSuite) TestAccResourceIdentityCompartmen
{
Config: s.Config + `
resource "oci_identity_compartment" "t" {
name = "-tf-compartment"
name = "-tf-compartment2"
description = "tf test compartment2"
}`,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(s.ResourceName, "name", "-tf-compartment"),
resource.TestCheckResourceAttr(s.ResourceName, "name", "-tf-compartment2"),
resource.TestCheckResourceAttr(s.ResourceName, "description", "tf test compartment2"),
),
},
Expand Down
2 changes: 1 addition & 1 deletion resource_obmcs_identity_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func GroupResource() *schema.Resource {
Read: readGroup,
Update: updateGroup,
Delete: deleteGroup,
Schema: baseIdentitySchemaWithID,
Schema: baseIdentitySchema,
}
}

Expand Down
62 changes: 44 additions & 18 deletions resource_obmcs_identity_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,50 @@ import (
)

func PolicyResource() *schema.Resource {
policySchema := make(map[string]*schema.Schema)

for key, value := range identitySchemaWithID {
policySchema[key] = value
}

policySchema["statements"] = &schema.Schema{
Type: schema.TypeList,
Required: true,
Elem: &schema.Schema{Type: schema.TypeString},
}
policySchema["inactive_state"] = &schema.Schema{
Type: schema.TypeInt,
Computed: true,
}
policySchema["version_date"] = &schema.Schema{
Type: schema.TypeString,
Computed: true,
policySchema := map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
ForceNew: true,
},
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"description": {
Type: schema.TypeString,
Required: true,
},
"compartment_id": {
Type: schema.TypeString,
Required: true,
},
"state": {
Type: schema.TypeString,
Computed: true,
},
"time_created": {
Type: schema.TypeString,
Computed: true,
},
"time_modified": {
Type: schema.TypeString,
Computed: true,
},
"statements": {
Type: schema.TypeList,
Required: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"inactive_state": {
Type: schema.TypeInt,
Computed: true,
},
"version_date": {
Type: schema.TypeString,
Computed: true,
},
}

return &schema.Resource{
Expand Down
2 changes: 1 addition & 1 deletion resource_obmcs_identity_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func UserResource() *schema.Resource {
Read: readUser,
Update: updateUser,
Delete: deleteUser,
Schema: baseIdentitySchemaWithID,
Schema: baseIdentitySchema,
}
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -2972,10 +2972,10 @@
"revisionTime": "2017-01-25T16:36:56Z"
},
{
"checksumSHA1": "52cecCncaYeBtPjEq5GXLnbUVAA=",
"checksumSHA1": "i5+LuvTFk7sBs5CUWo9+cjE1YcA=",
"path": "github.com/oracle/bmcs-go-sdk",
"revision": "c12b16924d0c0613c8651bda0c0156ce527ed2bd",
"revisionTime": "2017-09-25T22:50:26Z"
"revision": "c58f2bfda490d2e87610265d056aea0716d94c87",
"revisionTime": "2017-09-27T00:20:41Z"
},
{
"checksumSHA1": "ImgLNIpeXsGjZGXw4rd+rwzQxpo=",
Expand Down

0 comments on commit f37f28b

Please sign in to comment.