From f37f28bca41cdffaf97a6409bf2e58ad88563562 Mon Sep 17 00:00:00 2001 From: ccushing Date: Tue, 26 Sep 2017 18:09:38 -0700 Subject: [PATCH] Support compartment renaming * 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 --- docs/datasources/identity/compartment.md | 4 +- docs/datasources/identity/policy.md | 2 +- docs/datasources/identity/user.md | 2 +- docs/resources/identity/compartment.md | 4 +- helpers_identity.go | 93 +------------------ resource_obmcs_identity_compartment.go | 43 ++++++++- resource_obmcs_identity_compartment_test.go | 4 +- resource_obmcs_identity_group.go | 2 +- resource_obmcs_identity_policy.go | 62 +++++++++---- resource_obmcs_identity_user.go | 2 +- .../bmcs-go-sdk/identity_compartment.go | 2 +- .../oracle/bmcs-go-sdk/request_options.go | 21 +++-- vendor/vendor.json | 6 +- 13 files changed, 114 insertions(+), 133 deletions(-) diff --git a/docs/datasources/identity/compartment.md b/docs/datasources/identity/compartment.md index f5e140dba37..4f185daccdf 100644 --- a/docs/datasources/identity/compartment.md +++ b/docs/datasources/identity/compartment.md @@ -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] diff --git a/docs/datasources/identity/policy.md b/docs/datasources/identity/policy.md index 1d829b65b49..2e6f1c21f16 100644 --- a/docs/datasources/identity/policy.md +++ b/docs/datasources/identity/policy.md @@ -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. diff --git a/docs/datasources/identity/user.md b/docs/datasources/identity/user.md index a77359e478e..9c4b905b96a 100644 --- a/docs/datasources/identity/user.md +++ b/docs/datasources/identity/user.md @@ -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. diff --git a/docs/resources/identity/compartment.md b/docs/resources/identity/compartment.md index eeae61f49dc..a93378d6866 100644 --- a/docs/resources/identity/compartment.md +++ b/docs/resources/identity/compartment.md @@ -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] diff --git a/helpers_identity.go b/helpers_identity.go index 420c2655c0b..2e5f1697a12 100644 --- a/helpers_identity.go +++ b/helpers_identity.go @@ -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, @@ -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, - }, -} diff --git a/resource_obmcs_identity_compartment.go b/resource_obmcs_identity_compartment.go index 0c77b276f4d..c0e9edefcf9 100644 --- a/resource_obmcs_identity_compartment.go +++ b/resource_obmcs_identity_compartment.go @@ -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, @@ -24,7 +60,7 @@ func CompartmentResource() *schema.Resource { Read: readCompartment, Update: updateCompartment, Delete: deleteCompartment, - Schema: baseIdentitySchemaWithID, + Schema: compartmentSchema, } } @@ -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) } diff --git a/resource_obmcs_identity_compartment_test.go b/resource_obmcs_identity_compartment_test.go index ae18230f2da..e3007210b6c 100644 --- a/resource_obmcs_identity_compartment_test.go +++ b/resource_obmcs_identity_compartment_test.go @@ -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"), ), }, diff --git a/resource_obmcs_identity_group.go b/resource_obmcs_identity_group.go index 300e102ff4e..5d5cd110963 100644 --- a/resource_obmcs_identity_group.go +++ b/resource_obmcs_identity_group.go @@ -22,7 +22,7 @@ func GroupResource() *schema.Resource { Read: readGroup, Update: updateGroup, Delete: deleteGroup, - Schema: baseIdentitySchemaWithID, + Schema: baseIdentitySchema, } } diff --git a/resource_obmcs_identity_policy.go b/resource_obmcs_identity_policy.go index 3220576870e..b06a0bc1d67 100644 --- a/resource_obmcs_identity_policy.go +++ b/resource_obmcs_identity_policy.go @@ -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{ diff --git a/resource_obmcs_identity_user.go b/resource_obmcs_identity_user.go index 01851af3cb9..3e4084ae7e4 100644 --- a/resource_obmcs_identity_user.go +++ b/resource_obmcs_identity_user.go @@ -20,7 +20,7 @@ func UserResource() *schema.Resource { Read: readUser, Update: updateUser, Delete: deleteUser, - Schema: baseIdentitySchemaWithID, + Schema: baseIdentitySchema, } } diff --git a/vendor/github.com/oracle/bmcs-go-sdk/identity_compartment.go b/vendor/github.com/oracle/bmcs-go-sdk/identity_compartment.go index 838483f9107..0423b3d2f39 100644 --- a/vendor/github.com/oracle/bmcs-go-sdk/identity_compartment.go +++ b/vendor/github.com/oracle/bmcs-go-sdk/identity_compartment.go @@ -77,7 +77,7 @@ func (c *Client) GetCompartment(id string) (res *Compartment, e error) { // UpdateCompartment updates the description of a compartment. // // See https://docs.us-phoenix-1.oraclecloud.com/api/#/en/identity/20160918/Compartment/UpdateCompartment -func (c *Client) UpdateCompartment(id string, opts *UpdateIdentityOptions) (res *Compartment, e error) { +func (c *Client) UpdateCompartment(id string, opts *UpdateCompartmentOptions) (res *Compartment, e error) { details := &requestDetails{ ids: urlParts{id}, name: resourceCompartments, diff --git a/vendor/github.com/oracle/bmcs-go-sdk/request_options.go b/vendor/github.com/oracle/bmcs-go-sdk/request_options.go index fd9841210ab..1fb60275408 100644 --- a/vendor/github.com/oracle/bmcs-go-sdk/request_options.go +++ b/vendor/github.com/oracle/bmcs-go-sdk/request_options.go @@ -155,8 +155,8 @@ type UpdatePrivateIPOptions struct { type UpdateVnicOptions struct { UpdateOptions - HostnameLabel string `header:"-" json:"hostnameLabel,omitempty" url:"-"` - SkipSourceDestCheck *bool `header:"-" json:"skipSourceDestCheck,omitempty" url:"-"` + HostnameLabel string `header:"-" json:"hostnameLabel,omitempty" url:"-"` + SkipSourceDestCheck *bool `header:"-" json:"skipSourceDestCheck,omitempty" url:"-"` } type CreateVolumeOptions struct { @@ -171,12 +171,12 @@ type CreatePolicyOptions struct { } type CreateVnicOptions struct { - AssignPublicIp *bool `header:"-" json:"assignPublicIp,omitempty" url:"-"` - DisplayName string `header:"-" json:"displayName,omitempty" url:"-"` - HostnameLabel string `header:"-" json:"hostnameLabel,omitempty" url:"-"` - PrivateIp string `header:"-" json:"privateIp,omitempty" url:"-"` - SkipSourceDestCheck *bool `header:"-" json:"skipSourceDestCheck,omitempty" url:"-"` - SubnetID string `header:"-" json:"subnetId,omitempty" url:"-"` + AssignPublicIp *bool `header:"-" json:"assignPublicIp,omitempty" url:"-"` + DisplayName string `header:"-" json:"displayName,omitempty" url:"-"` + HostnameLabel string `header:"-" json:"hostnameLabel,omitempty" url:"-"` + PrivateIp string `header:"-" json:"privateIp,omitempty" url:"-"` + SkipSourceDestCheck *bool `header:"-" json:"skipSourceDestCheck,omitempty" url:"-"` + SubnetID string `header:"-" json:"subnetId,omitempty" url:"-"` } type LaunchInstanceOptions struct { @@ -242,6 +242,11 @@ type UpdateIdentityOptions struct { Description string `header:"-" json:"description,omitempty" url:"-"` } +type UpdateCompartmentOptions struct { + UpdateIdentityOptions + Name string `header:"-" json:"name,omitempty" url:"-"` +} + type UpdateUserStateOptions struct { IfMatchOptions Blocked *bool `header:"-" json:"blocked,omitempty" url:"-"` diff --git a/vendor/vendor.json b/vendor/vendor.json index 4561800332d..4b72d2a76e5 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -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=",