diff --git a/client/bare_metal_client.go b/client/bare_metal_client.go index 76de131c5c1..5516b0040c4 100644 --- a/client/bare_metal_client.go +++ b/client/bare_metal_client.go @@ -26,6 +26,7 @@ type BareMetalClient interface { CreateRouteTable(compartmentID, vcnID string, routeRules []baremetal.RouteRule, opts *baremetal.CreateOptions) (res *baremetal.RouteTable, e error) CreateSecurityList(compartmentID, vcnID string, egressRules []baremetal.EgressSecurityRule, ingressRules []baremetal.IngressSecurityRule, opts *baremetal.CreateOptions) (res *baremetal.SecurityList, e error) CreateSubnet(availabilityDomain, cidrBlock, compartmentID, vcnID string, opts *baremetal.CreateSubnetOptions) (sn *baremetal.Subnet, e error) + CreateSwiftPassword(userID, desc string, opts *baremetal.RetryTokenOptions) (res *baremetal.SwiftPassword, e error) CreateUser(name, desc string, opts *baremetal.RetryTokenOptions) (res *baremetal.User, e error) CreateVirtualNetwork(cidrBlock, compartmentID string, opts *baremetal.CreateOptions) (vcn *baremetal.VirtualNetwork, e error) CreateVolume(availabilityDomain, compartmentID string, opts *baremetal.CreateVolumeOptions) (res *baremetal.Volume, e error) @@ -46,6 +47,7 @@ type BareMetalClient interface { DeleteRouteTable(id string, opts *baremetal.IfMatchOptions) (e error) DeleteSecurityList(id string, opts *baremetal.IfMatchOptions) (e error) DeleteSubnet(id string, opts *baremetal.IfMatchOptions) error + DeleteSwiftPassword(id, userID string, opts *baremetal.IfMatchOptions) (e error) DeleteUser(id string, opts *baremetal.IfMatchOptions) (e error) DeleteUserGroupMembership(id string, opts *baremetal.IfMatchOptions) (e error) DeleteVirtualNetwork(id string, opts *baremetal.IfMatchOptions) (e error) @@ -114,11 +116,13 @@ type BareMetalClient interface { ListInstances(compartmentID string, opts *baremetal.ListInstancesOptions) (insts *baremetal.ListInstances, e error) ListInternetGateways(compartmentID, vcnID string, opts *baremetal.ListOptions) (list *baremetal.ListInternetGateways, e error) ListObjects(namespace baremetal.Namespace, bucket string, opts *baremetal.ListObjectsOptions) (objects *baremetal.ListObjects, e error) + ListPolicies(compartmentID string, opts *baremetal.ListOptions) (resources *baremetal.ListPolicies, e error) ListRouteTables(compartmentID, vcnID string, opts *baremetal.ListOptions) (res *baremetal.ListRouteTables, e error) ListSecurityLists(compartmentID, vcnID string, opts *baremetal.ListOptions) (res *baremetal.ListSecurityLists, e error) ListShapes(compartmentID string, opts *baremetal.ListShapesOptions) (shapes *baremetal.ListShapes, e error) ListSubnets(compartmentID, vcnID string, opts *baremetal.ListOptions) (subnets *baremetal.ListSubnets, e error) ListSupportedOperations() (*baremetal.ListSupportedOperations, error) + ListSwiftPasswords(userID string) (resources *baremetal.ListSwiftPasswords, e error) ListUserGroupMemberships(opts *baremetal.ListMembershipsOptions) (resources *baremetal.ListUserGroupMemberships, e error) ListUsers(opts *baremetal.ListOptions) (resources *baremetal.ListUsers, e error) ListVirtualNetworks(compartmentID string, opts *baremetal.ListOptions) (vcns *baremetal.ListVirtualNetworks, e error) @@ -136,15 +140,22 @@ type BareMetalClient interface { UpdateBucket(compartmentID string, name string, namespaceName baremetal.Namespace, opts *baremetal.UpdateBucketOptions) (bckt *baremetal.Bucket, e error) UpdateCompartment(id string, opts *baremetal.UpdateIdentityOptions) (res *baremetal.Compartment, e error) + UpdateCpe(id string, opts *baremetal.IfMatchDisplayNameOptions) (cpe *baremetal.Cpe, e error) UpdateDHCPOptions(id string, opts *baremetal.UpdateDHCPDNSOptions) (res *baremetal.DHCPOptions, e error) + UpdateDrg(id string, opts *baremetal.IfMatchDisplayNameOptions) (drg *baremetal.Drg, e error) + UpdateDrgAttachment(id string, opts *baremetal.IfMatchDisplayNameOptions) (drg *baremetal.DrgAttachment, e error) UpdateGroup(id string, opts *baremetal.UpdateIdentityOptions) (res *baremetal.Group, e error) UpdateImage(id string, opts *baremetal.UpdateOptions) (res *baremetal.Image, e error) UpdateInstance(id string, opts *baremetal.UpdateOptions) (inst *baremetal.Instance, e error) UpdateInternetGateway(id string, opts *baremetal.UpdateGatewayOptions) (gw *baremetal.InternetGateway, e error) + UpdateIPSecConnection(id string, opts *baremetal.IfMatchDisplayNameOptions) (conn *baremetal.IPSecConnection, e error) UpdatePolicy(id string, opts *baremetal.UpdatePolicyOptions) (res *baremetal.Policy, e error) UpdateRouteTable(id string, opts *baremetal.UpdateRouteTableOptions) (res *baremetal.RouteTable, e error) UpdateSecurityList(id string, opts *baremetal.UpdateSecurityListOptions) (res *baremetal.SecurityList, e error) + UpdateSubnet(id string, opts *baremetal.IfMatchDisplayNameOptions) (subnet *baremetal.Subnet, e error) + UpdateSwiftPassword(id, userID string, opts *baremetal.UpdateIdentityOptions) (res *baremetal.SwiftPassword, e error) UpdateUser(id string, opts *baremetal.UpdateIdentityOptions) (res *baremetal.User, e error) + UpdateVirtualNetwork(id string, opts *baremetal.IfMatchDisplayNameOptions) (vcn *baremetal.VirtualNetwork, e error) UpdateVolume(id string, opts *baremetal.UpdateOptions) (res *baremetal.Volume, e error) UpdateVolumeBackup(id string, opts *baremetal.UpdateBackupOptions) (vol *baremetal.VolumeBackup, e error) UploadAPIKey(userID, key string, opts *baremetal.RetryTokenOptions) (apiKey *baremetal.APIKey, e error) diff --git a/client/mocks/bare_metal_client.go b/client/mocks/bare_metal_client.go index 27271bf77d6..58fc4da7b9a 100644 --- a/client/mocks/bare_metal_client.go +++ b/client/mocks/bare_metal_client.go @@ -423,6 +423,29 @@ func (_m *BareMetalClient) CreateSubnet(availabilityDomain string, cidrBlock str return r0, r1 } +// CreateSwiftPassword provides a mock function with given fields: userID, desc, opts +func (_m *BareMetalClient) CreateSwiftPassword(userID string, desc string, opts *baremetal.RetryTokenOptions) (*baremetal.SwiftPassword, error) { + ret := _m.Called(userID, desc, opts) + + var r0 *baremetal.SwiftPassword + if rf, ok := ret.Get(0).(func(string, string, *baremetal.RetryTokenOptions) *baremetal.SwiftPassword); ok { + r0 = rf(userID, desc, opts) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*baremetal.SwiftPassword) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(string, string, *baremetal.RetryTokenOptions) error); ok { + r1 = rf(userID, desc, opts) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // CreateUser provides a mock function with given fields: name, desc, opts func (_m *BareMetalClient) CreateUser(name string, desc string, opts *baremetal.RetryTokenOptions) (*baremetal.User, error) { ret := _m.Called(name, desc, opts) @@ -734,6 +757,20 @@ func (_m *BareMetalClient) DeleteSubnet(id string, opts *baremetal.IfMatchOption return r0 } +// DeleteSwiftPassword provides a mock function with given fields: id, userID, opts +func (_m *BareMetalClient) DeleteSwiftPassword(id string, userID string, opts *baremetal.IfMatchOptions) error { + ret := _m.Called(id, userID, opts) + + var r0 error + if rf, ok := ret.Get(0).(func(string, string, *baremetal.IfMatchOptions) error); ok { + r0 = rf(id, userID, opts) + } else { + r0 = ret.Error(0) + } + + return r0 +} + // DeleteUser provides a mock function with given fields: id, opts func (_m *BareMetalClient) DeleteUser(id string, opts *baremetal.IfMatchOptions) error { ret := _m.Called(id, opts) @@ -2106,6 +2143,29 @@ func (_m *BareMetalClient) ListObjects(namespace baremetal.Namespace, bucket str return r0, r1 } +// ListPolicies provides a mock function with given fields: compartmentID, opts +func (_m *BareMetalClient) ListPolicies(compartmentID string, opts *baremetal.ListOptions) (*baremetal.ListPolicies, error) { + ret := _m.Called(compartmentID, opts) + + var r0 *baremetal.ListPolicies + if rf, ok := ret.Get(0).(func(string, *baremetal.ListOptions) *baremetal.ListPolicies); ok { + r0 = rf(compartmentID, opts) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*baremetal.ListPolicies) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(string, *baremetal.ListOptions) error); ok { + r1 = rf(compartmentID, opts) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // ListRouteTables provides a mock function with given fields: compartmentID, vcnID, opts func (_m *BareMetalClient) ListRouteTables(compartmentID string, vcnID string, opts *baremetal.ListOptions) (*baremetal.ListRouteTables, error) { ret := _m.Called(compartmentID, vcnID, opts) @@ -2221,6 +2281,29 @@ func (_m *BareMetalClient) ListSupportedOperations() (*baremetal.ListSupportedOp return r0, r1 } +// ListSwiftPasswords provides a mock function with given fields: userID +func (_m *BareMetalClient) ListSwiftPasswords(userID string) (*baremetal.ListSwiftPasswords, error) { + ret := _m.Called(userID) + + var r0 *baremetal.ListSwiftPasswords + if rf, ok := ret.Get(0).(func(string) *baremetal.ListSwiftPasswords); ok { + r0 = rf(userID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*baremetal.ListSwiftPasswords) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(userID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // ListUserGroupMemberships provides a mock function with given fields: opts func (_m *BareMetalClient) ListUserGroupMemberships(opts *baremetal.ListMembershipsOptions) (*baremetal.ListUserGroupMemberships, error) { ret := _m.Called(opts) @@ -2502,6 +2585,29 @@ func (_m *BareMetalClient) UpdateCompartment(id string, opts *baremetal.UpdateId return r0, r1 } +// UpdateCpe provides a mock function with given fields: id, opts +func (_m *BareMetalClient) UpdateCpe(id string, opts *baremetal.IfMatchDisplayNameOptions) (*baremetal.Cpe, error) { + ret := _m.Called(id, opts) + + var r0 *baremetal.Cpe + if rf, ok := ret.Get(0).(func(string, *baremetal.IfMatchDisplayNameOptions) *baremetal.Cpe); ok { + r0 = rf(id, opts) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*baremetal.Cpe) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(string, *baremetal.IfMatchDisplayNameOptions) error); ok { + r1 = rf(id, opts) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // UpdateDHCPOptions provides a mock function with given fields: id, opts func (_m *BareMetalClient) UpdateDHCPOptions(id string, opts *baremetal.UpdateDHCPDNSOptions) (*baremetal.DHCPOptions, error) { ret := _m.Called(id, opts) @@ -2525,6 +2631,52 @@ func (_m *BareMetalClient) UpdateDHCPOptions(id string, opts *baremetal.UpdateDH return r0, r1 } +// UpdateDrg provides a mock function with given fields: id, opts +func (_m *BareMetalClient) UpdateDrg(id string, opts *baremetal.IfMatchDisplayNameOptions) (*baremetal.Drg, error) { + ret := _m.Called(id, opts) + + var r0 *baremetal.Drg + if rf, ok := ret.Get(0).(func(string, *baremetal.IfMatchDisplayNameOptions) *baremetal.Drg); ok { + r0 = rf(id, opts) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*baremetal.Drg) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(string, *baremetal.IfMatchDisplayNameOptions) error); ok { + r1 = rf(id, opts) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// UpdateDrgAttachment provides a mock function with given fields: id, opts +func (_m *BareMetalClient) UpdateDrgAttachment(id string, opts *baremetal.IfMatchDisplayNameOptions) (*baremetal.DrgAttachment, error) { + ret := _m.Called(id, opts) + + var r0 *baremetal.DrgAttachment + if rf, ok := ret.Get(0).(func(string, *baremetal.IfMatchDisplayNameOptions) *baremetal.DrgAttachment); ok { + r0 = rf(id, opts) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*baremetal.DrgAttachment) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(string, *baremetal.IfMatchDisplayNameOptions) error); ok { + r1 = rf(id, opts) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // UpdateGroup provides a mock function with given fields: id, opts func (_m *BareMetalClient) UpdateGroup(id string, opts *baremetal.UpdateIdentityOptions) (*baremetal.Group, error) { ret := _m.Called(id, opts) @@ -2548,6 +2700,29 @@ func (_m *BareMetalClient) UpdateGroup(id string, opts *baremetal.UpdateIdentity return r0, r1 } +// UpdateIPSecConnection provides a mock function with given fields: id, opts +func (_m *BareMetalClient) UpdateIPSecConnection(id string, opts *baremetal.IfMatchDisplayNameOptions) (*baremetal.IPSecConnection, error) { + ret := _m.Called(id, opts) + + var r0 *baremetal.IPSecConnection + if rf, ok := ret.Get(0).(func(string, *baremetal.IfMatchDisplayNameOptions) *baremetal.IPSecConnection); ok { + r0 = rf(id, opts) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*baremetal.IPSecConnection) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(string, *baremetal.IfMatchDisplayNameOptions) error); ok { + r1 = rf(id, opts) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // UpdateImage provides a mock function with given fields: id, opts func (_m *BareMetalClient) UpdateImage(id string, opts *baremetal.UpdateOptions) (*baremetal.Image, error) { ret := _m.Called(id, opts) @@ -2686,6 +2861,52 @@ func (_m *BareMetalClient) UpdateSecurityList(id string, opts *baremetal.UpdateS return r0, r1 } +// UpdateSubnet provides a mock function with given fields: id, opts +func (_m *BareMetalClient) UpdateSubnet(id string, opts *baremetal.IfMatchDisplayNameOptions) (*baremetal.Subnet, error) { + ret := _m.Called(id, opts) + + var r0 *baremetal.Subnet + if rf, ok := ret.Get(0).(func(string, *baremetal.IfMatchDisplayNameOptions) *baremetal.Subnet); ok { + r0 = rf(id, opts) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*baremetal.Subnet) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(string, *baremetal.IfMatchDisplayNameOptions) error); ok { + r1 = rf(id, opts) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// UpdateSwiftPassword provides a mock function with given fields: id, userID, opts +func (_m *BareMetalClient) UpdateSwiftPassword(id string, userID string, opts *baremetal.UpdateIdentityOptions) (*baremetal.SwiftPassword, error) { + ret := _m.Called(id, userID, opts) + + var r0 *baremetal.SwiftPassword + if rf, ok := ret.Get(0).(func(string, string, *baremetal.UpdateIdentityOptions) *baremetal.SwiftPassword); ok { + r0 = rf(id, userID, opts) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*baremetal.SwiftPassword) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(string, string, *baremetal.UpdateIdentityOptions) error); ok { + r1 = rf(id, userID, opts) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // UpdateUser provides a mock function with given fields: id, opts func (_m *BareMetalClient) UpdateUser(id string, opts *baremetal.UpdateIdentityOptions) (*baremetal.User, error) { ret := _m.Called(id, opts) @@ -2709,6 +2930,29 @@ func (_m *BareMetalClient) UpdateUser(id string, opts *baremetal.UpdateIdentityO return r0, r1 } +// UpdateVirtualNetwork provides a mock function with given fields: id, opts +func (_m *BareMetalClient) UpdateVirtualNetwork(id string, opts *baremetal.IfMatchDisplayNameOptions) (*baremetal.VirtualNetwork, error) { + ret := _m.Called(id, opts) + + var r0 *baremetal.VirtualNetwork + if rf, ok := ret.Get(0).(func(string, *baremetal.IfMatchDisplayNameOptions) *baremetal.VirtualNetwork); ok { + r0 = rf(id, opts) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*baremetal.VirtualNetwork) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(string, *baremetal.IfMatchDisplayNameOptions) error); ok { + r1 = rf(id, opts) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // UpdateVolume provides a mock function with given fields: id, opts func (_m *BareMetalClient) UpdateVolume(id string, opts *baremetal.UpdateOptions) (*baremetal.Volume, error) { ret := _m.Called(id, opts) diff --git a/core/cpe_resource.go b/core/cpe_resource.go index d44da151c56..e1ed4b42125 100644 --- a/core/cpe_resource.go +++ b/core/cpe_resource.go @@ -12,6 +12,7 @@ func CpeResource() *schema.Resource { return &schema.Resource{ Create: createCpe, Read: readCpe, + Update: updateCpe, Delete: deleteCpe, Schema: map[string]*schema.Schema{ "id": { @@ -26,7 +27,6 @@ func CpeResource() *schema.Resource { "display_name": { Type: schema.TypeString, Optional: true, - ForceNew: true, Computed: true, }, "ip_address": { @@ -59,6 +59,14 @@ func readCpe(d *schema.ResourceData, m interface{}) (e error) { return crud.ReadResource(sync) } +func updateCpe(d *schema.ResourceData, m interface{}) (e error) { + client := m.(client.BareMetalClient) + crd := &CpeResourceCrud{} + crd.D = d + crd.Client = client + return crud.UpdateResource(d, crd) +} + func deleteCpe(d *schema.ResourceData, m interface{}) (e error) { client := m.(client.BareMetalClient) sync := &CpeResourceCrud{} diff --git a/core/cpe_resource_crud.go b/core/cpe_resource_crud.go index af8fce4c776..938a63a030d 100644 --- a/core/cpe_resource_crud.go +++ b/core/cpe_resource_crud.go @@ -35,6 +35,18 @@ func (s *CpeResourceCrud) Get() (e error) { return } +func (s *CpeResourceCrud) Update() (e error) { + opts := &baremetal.IfMatchDisplayNameOptions{} + compartmentID := s.D.Get("compartment_id").(string) + displayName, ok := s.D.GetOk("display_name") + if ok { + opts.DisplayName = displayName.(string) + } + + s.Resource, e = s.Client.UpdateCpe(compartmentID, opts) + return +} + func (s *CpeResourceCrud) SetData() { s.D.Set("compartment_id", s.Resource.CompartmentID) s.D.Set("display_name", s.Resource.DisplayName) diff --git a/core/drg_attachment_resource.go b/core/drg_attachment_resource.go index f3fa4a4779f..87b0277aa9f 100644 --- a/core/drg_attachment_resource.go +++ b/core/drg_attachment_resource.go @@ -12,6 +12,7 @@ func DrgAttachmentResource() *schema.Resource { return &schema.Resource{ Create: createDrgAttachment, Read: readDrgAttachment, + Update: updateDrgAttachment, Delete: deleteDrgAttachment, Schema: map[string]*schema.Schema{ "compartment_id": { @@ -66,6 +67,14 @@ func readDrgAttachment(d *schema.ResourceData, m interface{}) (e error) { return crud.ReadResource(sync) } +func updateDrgAttachment(d *schema.ResourceData, m interface{}) (e error) { + client := m.(client.BareMetalClient) + sync := &DrgAttachmentResourceCrud{} + sync.D = d + sync.Client = client + return crud.UpdateResource(sync.D, sync) +} + func deleteDrgAttachment(d *schema.ResourceData, m interface{}) (e error) { client := m.(client.BareMetalClient) sync := &DrgAttachmentResourceCrud{} diff --git a/core/drg_attachment_resource_crud.go b/core/drg_attachment_resource_crud.go index f5513dda1d3..9ed8bebc038 100644 --- a/core/drg_attachment_resource_crud.go +++ b/core/drg_attachment_resource_crud.go @@ -55,6 +55,18 @@ func (s *DrgAttachmentResourceCrud) Get() (e error) { return } +func (s *DrgAttachmentResourceCrud) Update() (e error) { + opts := &baremetal.IfMatchDisplayNameOptions{} + compartmentID := s.D.Get("compartment_id").(string) + displayName, ok := s.D.GetOk("display_name") + if ok { + opts.DisplayName = displayName.(string) + } + + s.Res, e = s.Client.UpdateDrgAttachment(compartmentID, opts) + return +} + func (s *DrgAttachmentResourceCrud) SetData() { s.D.Set("compartment_id", s.Res.CompartmentID) s.D.Set("display_name", s.Res.DisplayName) diff --git a/core/drg_resource.go b/core/drg_resource.go index 9e45931aa9d..ab67e97ea7d 100644 --- a/core/drg_resource.go +++ b/core/drg_resource.go @@ -12,6 +12,7 @@ func DrgResource() *schema.Resource { return &schema.Resource{ Create: createDrg, Read: readDrg, + Update: updateDrg, Delete: deleteDrg, Schema: map[string]*schema.Schema{ "compartment_id": { @@ -56,6 +57,14 @@ func readDrg(d *schema.ResourceData, m interface{}) (e error) { return crud.ReadResource(sync) } +func updateDrg(d *schema.ResourceData, m interface{}) (e error) { + client := m.(client.BareMetalClient) + sync := &DrgResourceCrud{} + sync.D = d + sync.Client = client + return crud.UpdateResource(sync.D, sync) +} + func deleteDrg(d *schema.ResourceData, m interface{}) (e error) { client := m.(client.BareMetalClient) sync := &DrgResourceCrud{} diff --git a/core/drg_resource_crud.go b/core/drg_resource_crud.go index adf7538dffe..ca43122e940 100644 --- a/core/drg_resource_crud.go +++ b/core/drg_resource_crud.go @@ -50,6 +50,18 @@ func (s *DrgResourceCrud) Get() (e error) { return } +func (s *DrgResourceCrud) Update() (e error) { + opts := &baremetal.IfMatchDisplayNameOptions{} + compartmentID := s.D.Get("compartment_id").(string) + displayName, ok := s.D.GetOk("display_name") + if ok { + opts.DisplayName = displayName.(string) + } + + s.Res, e = s.Client.UpdateDrg(compartmentID, opts) + return +} + func (s *DrgResourceCrud) SetData() { s.D.Set("compartment_id", s.Res.CompartmentID) s.D.Set("display_name", s.Res.DisplayName) diff --git a/core/ipsec_config_datasource.go b/core/ipsec_connection_config_datasource.go similarity index 92% rename from core/ipsec_config_datasource.go rename to core/ipsec_connection_config_datasource.go index 5ca851d7e29..83c98380b31 100644 --- a/core/ipsec_config_datasource.go +++ b/core/ipsec_connection_config_datasource.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform/helper/schema" ) -func IPSecConfigDatasource() *schema.Resource { +func IPSecConnectionConfigDatasource() *schema.Resource { return &schema.Resource{ Read: readIPSecDeviceConfig, Schema: map[string]*schema.Schema{ @@ -54,7 +54,7 @@ func IPSecConfigDatasource() *schema.Resource { func readIPSecDeviceConfig(d *schema.ResourceData, m interface{}) (e error) { client := m.(client.BareMetalClient) - reader := &IPSecConfigDatasourceCrud{} + reader := &IPSecConnectionConfigDatasourceCrud{} reader.D = d reader.Client = client diff --git a/core/ipsec_config_datasource_crud.go b/core/ipsec_connection_config_datasource_crud.go similarity index 84% rename from core/ipsec_config_datasource_crud.go rename to core/ipsec_connection_config_datasource_crud.go index 83daa503ee5..74fb478362c 100644 --- a/core/ipsec_config_datasource_crud.go +++ b/core/ipsec_connection_config_datasource_crud.go @@ -8,18 +8,18 @@ import ( "github.com/MustWin/terraform-Oracle-BareMetal-Provider/crud" ) -type IPSecConfigDatasourceCrud struct { +type IPSecConnectionConfigDatasourceCrud struct { crud.BaseCrud Resource *baremetal.IPSecConnectionDeviceConfig } -func (s *IPSecConfigDatasourceCrud) Get() (e error) { +func (s *IPSecConnectionConfigDatasourceCrud) Get() (e error) { ipsecID := s.D.Get("ipsec_id").(string) s.Resource, e = s.Client.GetIPSecConnectionDeviceConfig(ipsecID) return } -func (s *IPSecConfigDatasourceCrud) SetData() { +func (s *IPSecConnectionConfigDatasourceCrud) SetData() { if s.Resource != nil { s.D.SetId(s.Resource.ID) s.D.Set("compartment_id", s.Resource.CompartmentID) diff --git a/core/ipsec_resource.go b/core/ipsec_connection_resource.go similarity index 79% rename from core/ipsec_resource.go rename to core/ipsec_connection_resource.go index 70bcacd8aba..f464f88e7f9 100644 --- a/core/ipsec_resource.go +++ b/core/ipsec_connection_resource.go @@ -8,10 +8,11 @@ import ( "github.com/hashicorp/terraform/helper/schema" ) -func IPSecResource() *schema.Resource { +func IPSecConnectionResource() *schema.Resource { return &schema.Resource{ Create: createIPSec, Read: readIPSec, + Update: updateIPSec, Delete: deleteIPSec, Schema: map[string]*schema.Schema{ "compartment_id": { @@ -40,7 +41,6 @@ func IPSecResource() *schema.Resource { "display_name": { Type: schema.TypeString, Optional: true, - ForceNew: true, }, "state": { Type: schema.TypeString, @@ -55,21 +55,29 @@ func IPSecResource() *schema.Resource { } func createIPSec(d *schema.ResourceData, m interface{}) (e error) { - sync := &IPSecResourceCrud{} + sync := &IPSecConnectionResourceCrud{} sync.D = d sync.Client = m.(client.BareMetalClient) return crud.CreateResource(d, sync) } func readIPSec(d *schema.ResourceData, m interface{}) (e error) { - sync := &IPSecResourceCrud{} + sync := &IPSecConnectionResourceCrud{} sync.D = d sync.Client = m.(client.BareMetalClient) return crud.ReadResource(sync) } +func updateIPSec(d *schema.ResourceData, m interface{}) (e error) { + client := m.(client.BareMetalClient) + sync := &IPSecConnectionResourceCrud{} + sync.D = d + sync.Client = client + return crud.UpdateResource(sync.D, sync) +} + func deleteIPSec(d *schema.ResourceData, m interface{}) (e error) { - sync := &IPSecResourceCrud{} + sync := &IPSecConnectionResourceCrud{} sync.D = d sync.Client = m.(client.BareMetalClient) return crud.DeleteResource(sync) diff --git a/core/ipsec_resource_crud.go b/core/ipsec_connection_resource_crud.go similarity index 71% rename from core/ipsec_resource_crud.go rename to core/ipsec_connection_resource_crud.go index 3a4abf5fd87..9450dc495fa 100644 --- a/core/ipsec_resource_crud.go +++ b/core/ipsec_connection_resource_crud.go @@ -8,12 +8,12 @@ import ( "github.com/MustWin/terraform-Oracle-BareMetal-Provider/crud" ) -type IPSecResourceCrud struct { +type IPSecConnectionResourceCrud struct { crud.BaseCrud Resource *baremetal.IPSecConnection } -func (s *IPSecResourceCrud) ID() string { +func (s *IPSecConnectionResourceCrud) ID() string { return s.Resource.ID } @@ -29,7 +29,7 @@ func (s *IPSecResourceCrud) ID() string { // return []string{baremetal.ResourceDown} // } -func (s *IPSecResourceCrud) Create() (e error) { +func (s *IPSecConnectionResourceCrud) Create() (e error) { compartmentID := s.D.Get("compartment_id").(string) cpeID := s.D.Get("cpe_id").(string) drgID := s.D.Get("drg_id").(string) @@ -55,12 +55,24 @@ func (s *IPSecResourceCrud) Create() (e error) { return } -func (s *IPSecResourceCrud) Get() (e error) { +func (s *IPSecConnectionResourceCrud) Get() (e error) { s.Resource, e = s.Client.GetIPSecConnection(s.D.Id()) return } -func (s *IPSecResourceCrud) SetData() { +func (s *IPSecConnectionResourceCrud) Update() (e error) { + opts := &baremetal.IfMatchDisplayNameOptions{} + compartmentID := s.D.Get("compartment_id").(string) + displayName, ok := s.D.GetOk("display_name") + if ok { + opts.DisplayName = displayName.(string) + } + + s.Resource, e = s.Client.UpdateIPSecConnection(compartmentID, opts) + return +} + +func (s *IPSecConnectionResourceCrud) SetData() { s.D.Set("compartment_id", s.Resource.CompartmentID) s.D.Set("cpe_id", s.Resource.CpeID) s.D.Set("drg_id", s.Resource.DrgID) @@ -71,6 +83,6 @@ func (s *IPSecResourceCrud) SetData() { } -func (s *IPSecResourceCrud) Delete() (e error) { +func (s *IPSecConnectionResourceCrud) Delete() (e error) { return s.Client.DeleteIPSecConnection(s.D.Id(), nil) } diff --git a/core/ipsec_status_datasource.go b/core/ipsec_connection_status_datasource.go similarity index 92% rename from core/ipsec_status_datasource.go rename to core/ipsec_connection_status_datasource.go index 8b351fcf18f..5bbb142405c 100644 --- a/core/ipsec_status_datasource.go +++ b/core/ipsec_connection_status_datasource.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform/helper/schema" ) -func IPSecStatusDatasource() *schema.Resource { +func IPSecConnectionStatusDatasource() *schema.Resource { return &schema.Resource{ Read: readIPSecDeviceStatus, Schema: map[string]*schema.Schema{ @@ -58,7 +58,7 @@ func IPSecStatusDatasource() *schema.Resource { func readIPSecDeviceStatus(d *schema.ResourceData, m interface{}) (e error) { client := m.(client.BareMetalClient) - reader := &IPSecStatusDatasourceCrud{} + reader := &IPSecConnectionStatusDatasourceCrud{} reader.D = d reader.Client = client diff --git a/core/ipsec_status_datasource_crud.go b/core/ipsec_connection_status_datasource_crud.go similarity index 84% rename from core/ipsec_status_datasource_crud.go rename to core/ipsec_connection_status_datasource_crud.go index 3ffe6d64266..d990a0ad0d7 100644 --- a/core/ipsec_status_datasource_crud.go +++ b/core/ipsec_connection_status_datasource_crud.go @@ -8,18 +8,18 @@ import ( "github.com/MustWin/terraform-Oracle-BareMetal-Provider/crud" ) -type IPSecStatusDatasourceCrud struct { +type IPSecConnectionStatusDatasourceCrud struct { crud.BaseCrud Resource *baremetal.IPSecConnectionDeviceStatus } -func (s *IPSecStatusDatasourceCrud) Get() (e error) { +func (s *IPSecConnectionStatusDatasourceCrud) Get() (e error) { ipsecID := s.D.Get("ipsec_id").(string) s.Resource, e = s.Client.GetIPSecConnectionDeviceStatus(ipsecID) return } -func (s *IPSecStatusDatasourceCrud) SetData() { +func (s *IPSecConnectionStatusDatasourceCrud) SetData() { if s.Resource != nil { s.D.SetId(s.Resource.ID) s.D.Set("compartment_id", s.Resource.CompartmentID) diff --git a/core/subnet_resource.go b/core/subnet_resource.go index 4a5beb8ab20..9b8acbb7ba7 100644 --- a/core/subnet_resource.go +++ b/core/subnet_resource.go @@ -12,6 +12,7 @@ func SubnetResource() *schema.Resource { return &schema.Resource{ Create: createSubnet, Read: readSubnet, + Update: updateSubnet, Delete: deleteSubnet, Schema: map[string]*schema.Schema{ "availability_domain": { @@ -90,6 +91,14 @@ func readSubnet(d *schema.ResourceData, m interface{}) (e error) { return crud.ReadResource(sync) } +func updateSubnet(d *schema.ResourceData, m interface{}) (e error) { + client := m.(client.BareMetalClient) + sync := &SubnetResourceCrud{} + sync.D = d + sync.Client = client + return crud.UpdateResource(sync.D, sync) +} + func deleteSubnet(d *schema.ResourceData, m interface{}) (e error) { sync := &SubnetResourceCrud{} sync.D = d diff --git a/core/subnet_resource_crud.go b/core/subnet_resource_crud.go index af7b564c591..55abd09d754 100644 --- a/core/subnet_resource_crud.go +++ b/core/subnet_resource_crud.go @@ -78,6 +78,18 @@ func (s *SubnetResourceCrud) Get() (e error) { return } +func (s *SubnetResourceCrud) Update() (e error) { + opts := &baremetal.IfMatchDisplayNameOptions{} + compartmentID := s.D.Get("compartment_id").(string) + displayName, ok := s.D.GetOk("display_name") + if ok { + opts.DisplayName = displayName.(string) + } + + s.Resource, e = s.Client.UpdateSubnet(compartmentID, opts) + return +} + func (s *SubnetResourceCrud) SetData() { s.D.Set("availability_domain", s.Resource.AvailabilityDomain) s.D.Set("compartment_id", s.Resource.CompartmentID) diff --git a/core/virtual_network_resource.go b/core/virtual_network_resource.go index 658df83a299..a577cc8362f 100644 --- a/core/virtual_network_resource.go +++ b/core/virtual_network_resource.go @@ -12,6 +12,7 @@ func VirtualNetworkResource() *schema.Resource { return &schema.Resource{ Create: createVirtualNetwork, Read: readVirtualNetwork, + Update: updateVirtualNetwork, Delete: deleteVirtualNetwork, Schema: map[string]*schema.Schema{ "cidr_block": { @@ -69,6 +70,14 @@ func readVirtualNetwork(d *schema.ResourceData, m interface{}) (e error) { return crud.ReadResource(sync) } +func updateVirtualNetwork(d *schema.ResourceData, m interface{}) (e error) { + client := m.(client.BareMetalClient) + sync := &VirtualNetworkResourceCrud{} + sync.D = d + sync.Client = client + return crud.UpdateResource(sync.D, sync) +} + func deleteVirtualNetwork(d *schema.ResourceData, m interface{}) (e error) { client := m.(client.BareMetalClient) sync := &VirtualNetworkResourceCrud{} diff --git a/core/virtual_network_resource_crud.go b/core/virtual_network_resource_crud.go index 0892fe7399b..f5d23fdff4c 100644 --- a/core/virtual_network_resource_crud.go +++ b/core/virtual_network_resource_crud.go @@ -52,6 +52,18 @@ func (s *VirtualNetworkResourceCrud) Get() (e error) { return } +func (s *VirtualNetworkResourceCrud) Update() (e error) { + opts := &baremetal.IfMatchDisplayNameOptions{} + compartmentID := s.D.Get("compartment_id").(string) + displayName, ok := s.D.GetOk("display_name") + if ok { + opts.DisplayName = displayName.(string) + } + + s.Res, e = s.Client.UpdateVirtualNetwork(compartmentID, opts) + return +} + func (s *VirtualNetworkResourceCrud) SetData() { s.D.Set("cidr_block", s.Res.CidrBlock) s.D.Set("compartment_id", s.Res.CompartmentID) diff --git a/core/volume_resource.go b/core/volume_resource.go index 8d950fb266f..fd485825cc4 100644 --- a/core/volume_resource.go +++ b/core/volume_resource.go @@ -43,6 +43,11 @@ func VolumeResource() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "volume_backup_id": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, "time_created": { Type: schema.TypeString, Computed: true, diff --git a/core/volume_resource_crud.go b/core/volume_resource_crud.go index 573f6970c93..f9f60cd1626 100644 --- a/core/volume_resource_crud.go +++ b/core/volume_resource_crud.go @@ -50,6 +50,10 @@ func (s *VolumeResourceCrud) Create() (e error) { if ok { opts.SizeInMBs = sizeInMBs.(int) } + volumeBackupID, ok := s.D.GetOk("volume_backup_id") + if ok { + opts.VolumeBackupID = volumeBackupID.(string) + } s.Res, e = s.Client.CreateVolume(availabilityDomain, compartmentID, opts) diff --git a/docs/datasources/identity/policy.md b/docs/datasources/identity/policy.md new file mode 100644 index 00000000000..f1fb443ff05 --- /dev/null +++ b/docs/datasources/identity/policy.md @@ -0,0 +1,30 @@ +# baremetal\_identity\_policies + +Lists policies + +## Example Usage + +``` + data "baremetal_identity_policies" "p" { + compartment_id = "compartment ocid" + } +``` + +## Argument Reference + +The following arguments are supported: + +* `compartment_id` - (Required) The OCID of the compartment. + +## Attribute Reference +* `policies` - A list of policies + +## Group 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. +* `description` - The description you assign to the policy. Does not have to be unique, and it's changeable. +* `time_created` - Date and time the policy was created. +* `state` - The group's current state. [CREATING, ACTIVE, INACTIVE, DELETING, DELETED] +* `inactive_status` - The detailed status of INACTIVE lifecycleState. +* `version_date` - The version of the policy. If null or set to an empty string, when a request comes in for authorization, the policy will be evaluated according to the current behavior of the services at that moment. If set to a particular date (YYYY-MM-DD), the policy will be evaluated according to the behavior of the services on that date. diff --git a/docs/datasources/identity/swift_password.md b/docs/datasources/identity/swift_password.md new file mode 100644 index 00000000000..bbc48a36ef1 --- /dev/null +++ b/docs/datasources/identity/swift_password.md @@ -0,0 +1,33 @@ +# baremetal\_identity\_swift\_passwords + +Lists swift passwords + +## Example Usage + +``` +data "baremetal_identity_swift_passwords" "p" { + compartment_id = "compartment ocid" + user_id = "user ocid" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `compartment_id` - (Required) The OCID of the compartment container the user. +* `group_id` - (Optional) The OCID of the group. At least one of group_id or user_id is required. +* `user_id` - (Optional) The OCID of the user. At least one of group_id or user_id is required. + +## Attribute Reference +* `passwords` - A list of swift passwords + +## Swift Password Reference +* `id` - The OCID of the Swift password. +* `user_id` - The OCID of the user the password belongs to. +* `password` - The Swift password. The value is available only in the response for CreateSwiftPassword, and not for ListSwiftPasswords or UpdateSwiftPassword. +* `description` - The description you assign to the Swift password. Does not have to be unique, and it's changeable. +* `expires_on` - Date and time the password will expire, in the format defined by RFC3339. +* `time_created` - Date and time the password was created, in the format defined by RFC3339. +* `state` - The membership's current state. [CREATING, ACTIVE, INACTIVE, DELETING, DELETED] +* `inactive_status` - The detailed status of INACTIVE lifecycleState. diff --git a/docs/datasources/identity/user_group_membership.md b/docs/datasources/identity/user_group_membership.md new file mode 100644 index 00000000000..f2f88492bf3 --- /dev/null +++ b/docs/datasources/identity/user_group_membership.md @@ -0,0 +1,32 @@ +# baremetal\_identity\_user_group_memberships + +Lists user_group_memberships + +## Example Usage + +``` +data "baremetal_identity_user_group_memberships" "g_memberships" { + compartment_id = "cid" + group_id = "${baremetal_identity_group.g.id}" +}` +``` + +## Argument Reference + +The following arguments are supported: + +* `compartment_id` - (Required) The OCID of the tenancy containing the user, group, and membership object. +* `group_id` - (Optional) The OCID of the group. At least one of group_id or user_id is required. +* `user_id` - (Optional) The OCID of the user. At least one of group_id or user_id is required. + +## Attribute Reference +* `memberships` - A list of user_group_memberships + +## User Group Membership Reference +* `id` - The OCID of the user. +* `compartment_id` - The OCID of the tenancy containing the user. +* `group_id` - The OCID of the group. +* `user_id` - The OCID of the user. +* `time_created` - Date and time the user was created, in the format defined by RFC3339. +* `state` - The membership's current state. [CREATING, ACTIVE, INACTIVE, DELETING, DELETED] +* `inactive_status` - The detailed status of INACTIVE lifecycleState. diff --git a/docs/resources/core/group.md b/docs/resources/core/group.md deleted file mode 100644 index bbd8b9094d6..00000000000 --- a/docs/resources/core/group.md +++ /dev/null @@ -1,28 +0,0 @@ -# baremetal\_identity\_groups - -Provide a group resource - -## Example Usage - -``` -resource "baremetal_identity_group" "t" { - name = "name!" - description = "desc!" -} -``` - -## Argument Reference - -The following arguments are supported: - -* `name` - (Required) The name you assign to the group during creation. The name must be unique across all groups in the tenancy and cannot be changed. -* `description` - (Required) The description you assign to the group during creation. Does not have to be unique, and it's changeable. - -## Attribute Reference -* `id` - The OCID of the group. -* `compartment_id` - The OCID of the tenancy containing the group. -* `name` - The name you assign to the group during creation. The name must be unique across all groups in the tenancy and cannot be changed. -* `description` - The description you assign to the group. Does not have to be unique, and it's changeable. -* `time_created` - Date and time the ApiKey was created. -* `state` - The compartment's current state. [CREATING, ACTIVE, INACTIVE, DELETING, DELETED] -* `inactive_status` - The detailed status of INACTIVE lifecycleState. diff --git a/docs/resources/core/volume.md b/docs/resources/core/volume.md index 290230a12d9..36d1639e94f 100644 --- a/docs/resources/core/volume.md +++ b/docs/resources/core/volume.md @@ -9,6 +9,7 @@ resource "baremetal_core_volume" "t" { availability_domain = "availability_domain" compartment_id = "compartment_id" size_in_mbs = 262144 + volume_backup_id = "volume_id" } ``` @@ -19,6 +20,7 @@ The following arguments are supported: * `compartment_id` - (Required) The OCID of the compartment. * `availability_domain` - (Required) The Availability Domain of the volume. * `display_name` - (Optional) A user-friendly name. Does not have to be unique, and it's changeable. +* `volume_backup_id` - (Optional) The OCID of the volume backup from which the data should be restored on the newly created volume. ## Attributes Reference * `availability_domain` - The availability domain of the volume. diff --git a/docs/resources/identity/compartment.md b/docs/resources/identity/compartment.md index e677c8e65a4..59cd3c73e42 100644 --- a/docs/resources/identity/compartment.md +++ b/docs/resources/identity/compartment.md @@ -15,8 +15,8 @@ resource "baremetal_identity_compartment" "t" { The following arguments are supported: -* `name` - (Required) The name you assign to the group during creation. The name must be unique across all groups in the tenancy and cannot be changed. -* `description` - (Required) The description you assign to the group during creation. Does not have to be unique, and it's changeable. +* `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. +* `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. diff --git a/docs/resources/identity/group.md b/docs/resources/identity/group.md index e3921783d2c..47b31a42196 100644 --- a/docs/resources/identity/group.md +++ b/docs/resources/identity/group.md @@ -24,5 +24,5 @@ The following arguments are supported: * `name` - The name you assign to the group during creation. The name must be unique across all groups in the tenancy and cannot be changed. * `descriptions` - The description you assign to the group. Does not have to be unique, and it's changeable. * `time_created` - Date and time the group was created. -* `state` - The policy's current state. [CREATING, ACTIVE, INACTIVE, DELETING, DELETED] +* `state` - The group's current state. [CREATING, ACTIVE, INACTIVE, DELETING, DELETED] * `inactive_status` - The detailed status of INACTIVE lifecycleState. diff --git a/docs/resources/identity/swift_password.md b/docs/resources/identity/swift_password.md new file mode 100644 index 00000000000..22d21914e21 --- /dev/null +++ b/docs/resources/identity/swift_password.md @@ -0,0 +1,28 @@ +# baremetal\_identity\_swift\_password + +Provides a swift password resource. + +## Example Usage + +``` +resource "baremetal_identity_swift_password" "t" { + user_id = "user_id" + description = "nah nah nah" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `user_id` - (Required) The OCID of the user. +* `description` - (Required) The description you assign to the Swift password. Does not have to be unique, and it's changeable. + +## Attributes Reference +* `user_id` - The OCID of the user. +* `description` - The description you assign to the Swift password. Does not have to be unique, and it's changeable. +* `password` - The Swift password. The value is available only in the response for CreateSwiftPassword, and not for ListSwiftPasswords or UpdateSwiftPassword. +* `expires_on` - Date and time when this password will expire, in the format defined by RFC3339. Null if it never expires. +* `time_created` - The date and time the password was created. +* `state` - The user's current state. [CREATING, ACTIVE, INACTIVE, DELETING, DELETED] +* `inactive_status` - The detailed status of INACTIVE lifecycleState. \ No newline at end of file diff --git a/docs/resources/identity/user_group_membership.md b/docs/resources/identity/user_group_membership.md new file mode 100644 index 00000000000..07ced8020d8 --- /dev/null +++ b/docs/resources/identity/user_group_membership.md @@ -0,0 +1,30 @@ +# baremetal\_identity\_user\_group\_membership + +Provides a user group membership resource. + +## Example Usage + +``` +resource "baremetal_identity_user_group_membership" "t" { + compartment_id = "cid" + user_id = "${baremetal_identity_user.u.id}" + group_id = "${baremetal_identity_group.g.id}" + } +``` + +## Argument Reference + +The following arguments are supported: + +* `compartment_id` - (Required) The OCID of the tenancy containing the user, group, and membership object. +* `user_id` - (Required) The OCID of the group. +* `group_id` - (Required) The OCID of the user. + +## Attributes Reference +* `id` - The internet gateway's Oracle Cloud ID (OCID). +* `compartment_id` - The OCID of the tenancy containing the user, group, and membership object. +* `user_id` - The OCID of the user. +* `group_id` - The OCID of the group. +* `time_created` - The date and time the security list was created. +* `state` - The user's current state. [CREATING, ACTIVE, INACTIVE, DELETING, DELETED] +* `inactive_status` - Returned only if the user's lifecycleState is INACTIVE. A 16-bit value showing the reason why the user is inactive: [bit 0: SUSPENDED, bit 1: DISABLED, bit 2: BLOCKED] \ No newline at end of file diff --git a/identity/availability_domain_datasource.go b/identity/availability_domain_datasource.go index 5ca4dd2fb0d..5d4117042fe 100644 --- a/identity/availability_domain_datasource.go +++ b/identity/availability_domain_datasource.go @@ -16,9 +16,22 @@ func AvailabilityDomainDatasource() *schema.Resource { Type: schema.TypeString, Required: true, }, - "name": { - Type: schema.TypeString, + "availability_domains": { + Type: schema.TypeList, Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "compartment_id": { + Type: schema.TypeString, + Computed: true, + }, + + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, }, }, } diff --git a/identity/helpers.go b/identity/helpers.go index b686de0c466..a3e39d76b4d 100644 --- a/identity/helpers.go +++ b/identity/helpers.go @@ -4,7 +4,6 @@ package identity import "github.com/hashicorp/terraform/helper/schema" -// Just has a computed compartment_id var baseIdentitySchemaWithID = map[string]*schema.Schema{ "id": { Type: schema.TypeString, @@ -99,3 +98,36 @@ var identitySchema = map[string]*schema.Schema{ }, } +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/identity/policy_datasource.go b/identity/policy_datasource.go new file mode 100644 index 00000000000..b135d00790a --- /dev/null +++ b/identity/policy_datasource.go @@ -0,0 +1,34 @@ +// Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + +package identity + +import ( + "github.com/MustWin/terraform-Oracle-BareMetal-Provider/client" + "github.com/MustWin/terraform-Oracle-BareMetal-Provider/crud" + "github.com/hashicorp/terraform/helper/schema" +) + +func PolicyDatasource() *schema.Resource { + return &schema.Resource{ + Read: readPolicies, + Schema: map[string]*schema.Schema{ + "compartment_id":{ + Type: schema.TypeString, + Required: true, + }, + "policies": { + Type: schema.TypeList, + Computed: true, + Elem: PolicyResource(), + }, + }, + } +} + +func readPolicies(d *schema.ResourceData, m interface{}) (e error) { + client := m.(client.BareMetalClient) + sync := &PolicyDatasourceCrud{} + sync.D = d + sync.Client = client + return crud.ReadResource(sync) +} diff --git a/identity/policy_datasource_crud.go b/identity/policy_datasource_crud.go new file mode 100644 index 00000000000..43f8bd7806e --- /dev/null +++ b/identity/policy_datasource_crud.go @@ -0,0 +1,47 @@ +// Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + +package identity + +import ( + "time" + + "github.com/MustWin/baremetal-sdk-go" + "github.com/MustWin/terraform-Oracle-BareMetal-Provider/crud" +) + +type PolicyDatasourceCrud struct { + crud.BaseCrud + Res *baremetal.ListPolicies +} + +func (s *PolicyDatasourceCrud) Get() (e error) { + compartment_id := s.D.Get("compartment_id").(string) + + s.Res, e = s.Client.ListPolicies(compartment_id, nil) + return +} + +func (s *PolicyDatasourceCrud) SetData() { + if s.Res != nil { + s.D.SetId(time.Now().UTC().String()) + resources := []map[string]interface{}{} + for _, v := range s.Res.Policies { + res := map[string]interface{}{ + "id": v.ID, + "compartment_id": v.CompartmentID, + "name": v.Name, + "statements": v.Statements, + "description": v.Description, + "time_created": v.TimeCreated.String(), + "state": v.State, + "inactive_state": v.InactiveStatus, + "version_date": v.VersionDate.String(), + } + resources = append(resources, res) + } + if err := s.D.Set("policies", resources); err != nil { + panic(err) + } + } + return +} diff --git a/identity/policy_resource.go b/identity/policy_resource.go index a94987fcd8b..f2bb79f029e 100644 --- a/identity/policy_resource.go +++ b/identity/policy_resource.go @@ -11,7 +11,7 @@ import ( func PolicyResource() *schema.Resource { policySchema := make(map[string]*schema.Schema) - for key, value := range identitySchema { + for key, value := range identitySchemaWithID { policySchema[key] = value } @@ -20,6 +20,14 @@ func PolicyResource() *schema.Resource { 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, + } return &schema.Resource{ Create: createPolicy, diff --git a/identity/swift_password_datasource.go b/identity/swift_password_datasource.go new file mode 100644 index 00000000000..778db916b72 --- /dev/null +++ b/identity/swift_password_datasource.go @@ -0,0 +1,34 @@ +// Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + +package identity + +import ( + "github.com/MustWin/terraform-Oracle-BareMetal-Provider/client" + "github.com/MustWin/terraform-Oracle-BareMetal-Provider/crud" + "github.com/hashicorp/terraform/helper/schema" +) + +func SwiftPasswordDatasource() *schema.Resource { + return &schema.Resource{ + Read: readSwiftPasswords, + Schema: map[string]*schema.Schema{ + "user_id":{ + Type: schema.TypeString, + Required: true, + }, + "passwords": { + Type: schema.TypeList, + Computed: true, + Elem: SwiftPasswordResource(), + }, + }, + } +} + +func readSwiftPasswords(d *schema.ResourceData, m interface{}) (e error) { + client := m.(client.BareMetalClient) + sync := &SwiftPasswordDatasourceCrud{} + sync.D = d + sync.Client = client + return crud.ReadResource(sync) +} diff --git a/identity/swift_password_datasource_crud.go b/identity/swift_password_datasource_crud.go new file mode 100644 index 00000000000..17dcd6d12ee --- /dev/null +++ b/identity/swift_password_datasource_crud.go @@ -0,0 +1,45 @@ +// Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + +package identity + +import ( + "time" + + "github.com/MustWin/baremetal-sdk-go" + "github.com/MustWin/terraform-Oracle-BareMetal-Provider/crud" +) + +type SwiftPasswordDatasourceCrud struct { + crud.BaseCrud + Res *baremetal.ListSwiftPasswords +} + +func (s *SwiftPasswordDatasourceCrud) Get() (e error) { + userID := s.D.Get("user_id").(string) + + s.Res, e = s.Client.ListSwiftPasswords(userID) + return +} + +func (s *SwiftPasswordDatasourceCrud) SetData() { + if s.Res != nil { + s.D.SetId(time.Now().UTC().String()) + resources := []map[string]interface{}{} + for _, v := range s.Res.SwiftPasswords { + res := map[string]interface{}{ + "id": v.ID, + "user_id": v.UserID, + "description": v.Description, + "state": v.State, + "inactive_state": v.InactiveStatus, + "time_created": v.TimeCreated.String(), + "expires_on": v.ExpiresOn.String(), + } + resources = append(resources, res) + } + if err := s.D.Set("passwords", resources); err != nil { + panic(err) + } + } + return +} diff --git a/identity/swift_password_resource.go b/identity/swift_password_resource.go new file mode 100644 index 00000000000..af8e6932f98 --- /dev/null +++ b/identity/swift_password_resource.go @@ -0,0 +1,85 @@ +// Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + +package identity + +import ( + "github.com/MustWin/terraform-Oracle-BareMetal-Provider/client" + "github.com/MustWin/terraform-Oracle-BareMetal-Provider/crud" + "github.com/hashicorp/terraform/helper/schema" +) + +func SwiftPasswordResource() *schema.Resource { + return &schema.Resource{ + Create: createSwiftPassword, + Read: readSwiftPassword, + Update: updateSwiftPassword, + Delete: deleteSwiftPassword, + Schema: map[string]*schema.Schema{ + "id": { + Type: schema.TypeString, + Computed: true, + }, + "inactive_state": { + Type: schema.TypeInt, + Computed: true, + }, + "password": { + Type: schema.TypeString, + Computed: true, + }, + "state": { + Type: schema.TypeString, + Computed: true, + }, + "time_created": { + Type: schema.TypeString, + Computed: true, + }, + "user_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "description": { + Type: schema.TypeString, + Required: true, + }, + "expires_on": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func createSwiftPassword(d *schema.ResourceData, m interface{}) (e error) { + client := m.(client.BareMetalClient) + sync := &SwiftPasswordResourceCrud{} + sync.D = d + sync.Client = client + return crud.CreateResource(d, sync) +} + +func readSwiftPassword(d *schema.ResourceData, m interface{}) (e error) { + client := m.(client.BareMetalClient) + sync := &SwiftPasswordResourceCrud{} + sync.D = d + sync.Client = client + return crud.ReadResource(sync) +} + +func updateSwiftPassword(d *schema.ResourceData, m interface{}) (e error) { + client := m.(client.BareMetalClient) + sync := &SwiftPasswordResourceCrud{} + sync.D = d + sync.Client = client + return crud.UpdateResource(d, sync) +} + +func deleteSwiftPassword(d *schema.ResourceData, m interface{}) (e error) { + client := m.(client.BareMetalClient) + sync := &SwiftPasswordResourceCrud{} + sync.D = d + sync.Client = client + return crud.DeleteResource(sync) +} \ No newline at end of file diff --git a/identity/swift_password_resource_crud.go b/identity/swift_password_resource_crud.go new file mode 100644 index 00000000000..9d028fb1409 --- /dev/null +++ b/identity/swift_password_resource_crud.go @@ -0,0 +1,68 @@ +// Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + +package identity + +import ( + "github.com/MustWin/baremetal-sdk-go" + "github.com/MustWin/terraform-Oracle-BareMetal-Provider/crud" +) + +type SwiftPasswordResourceCrud struct { + crud.BaseCrud + Res *baremetal.SwiftPassword +} + +func (s *SwiftPasswordResourceCrud) ID() string { + return s.Res.ID +} + + +func (s *SwiftPasswordResourceCrud) Get() (e error) { + // There is no get resource for swift passwords, so we list them all and match + id := s.D.Id() + userID := s.D.Get("user_id").(string) + var list *baremetal.ListSwiftPasswords + list, e = s.Client.ListSwiftPasswords(userID) + if e != nil { + return + } + for _, sp := range list.SwiftPasswords { + if sp.ID == id { + s.Res = &sp + } + } + return +} + +func (s *SwiftPasswordResourceCrud) Create() (e error) { + userID := s.D.Get("user_id").(string) + desc := s.D.Get("description").(string) + s.Res, e = s.Client.CreateSwiftPassword(userID, desc, nil) + return +} + +func (s *SwiftPasswordResourceCrud) Update() (e error) { + userID := s.D.Get("user_id").(string) + opts := &baremetal.UpdateIdentityOptions{} + if description, ok := s.D.GetOk("description"); ok { + opts.Description = description.(string) + } + + s.Res, e = s.Client.UpdateSwiftPassword(s.D.Id(), userID, opts) + return +} + +func (s *SwiftPasswordResourceCrud) Delete() (e error) { + userID := s.D.Get("user_id").(string) + return s.Client.DeleteSwiftPassword(s.D.Id(), userID, nil) +} + +func (s *SwiftPasswordResourceCrud) SetData() { + s.D.Set("inactive_status", s.Res.InactiveStatus) + s.D.Set("state", s.Res.State) + s.D.Set("password", s.Res.Password) + s.D.Set("time_created", s.Res.TimeCreated.String()) + s.D.Set("user_id", s.Res.UserID) + s.D.Set("description", s.Res.Description) + s.D.Set("expires_on", s.Res.ExpiresOn.String()) +} diff --git a/identity/ui_password_resourc_crud.go b/identity/ui_password_resource_crud.go similarity index 100% rename from identity/ui_password_resourc_crud.go rename to identity/ui_password_resource_crud.go diff --git a/identity/user_group_membership_resource.go b/identity/user_group_membership_resource.go new file mode 100644 index 00000000000..cae1498e30d --- /dev/null +++ b/identity/user_group_membership_resource.go @@ -0,0 +1,75 @@ +// Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + +package identity + +import ( + "github.com/MustWin/terraform-Oracle-BareMetal-Provider/client" + "github.com/MustWin/terraform-Oracle-BareMetal-Provider/crud" + "github.com/hashicorp/terraform/helper/schema" +) + +func UserGroupMembershipResource() *schema.Resource { + return &schema.Resource{ + Create: createUserGroupMembership, + Read: readUserGroupMembership, + Delete: deleteUserGroupMembership, + Schema: map[string]*schema.Schema{ + "id": { + Type: schema.TypeString, + Computed: true, + ForceNew: true, + }, + "user_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "group_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "compartment_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "state": { + Type: schema.TypeString, + Computed: true, + }, + "inactive_state": { + Type: schema.TypeInt, + Computed: true, + }, + "time_created": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func createUserGroupMembership(d *schema.ResourceData, m interface{}) (e error) { + client := m.(client.BareMetalClient) + sync := &UserGroupMembershipResourceCrud{} + sync.D = d + sync.Client = client + return crud.CreateResource(d, sync) +} + +func readUserGroupMembership(d *schema.ResourceData, m interface{}) (e error) { + client := m.(client.BareMetalClient) + sync := &UserGroupMembershipResourceCrud{} + sync.D = d + sync.Client = client + return crud.ReadResource(sync) +} + +func deleteUserGroupMembership(d *schema.ResourceData, m interface{}) (e error) { + client := m.(client.BareMetalClient) + sync := &UserGroupMembershipResourceCrud{} + sync.D = d + sync.Client = client + return sync.Delete() +} diff --git a/identity/user_group_membership_resource_crud.go b/identity/user_group_membership_resource_crud.go new file mode 100644 index 00000000000..6d149b6b6bd --- /dev/null +++ b/identity/user_group_membership_resource_crud.go @@ -0,0 +1,63 @@ +// Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + +package identity + +import ( + "github.com/MustWin/baremetal-sdk-go" + "github.com/MustWin/terraform-Oracle-BareMetal-Provider/crud" +) + +type UserGroupMembershipResourceCrud struct { + *crud.IdentitySync + crud.BaseCrud + Res *baremetal.UserGroupMembership +} + +func (s *UserGroupMembershipResourceCrud) ID() string { + return s.Res.ID +} + +func (s *UserGroupMembershipResourceCrud) State() string { + return s.Res.State +} + +func (s *UserGroupMembershipResourceCrud) Create() (e error) { + userID := s.D.Get("user_id").(string) + groupID := s.D.Get("group_id").(string) + s.Res, e = s.Client.AddUserToGroup(userID, groupID, nil) + return +} + +func (s *UserGroupMembershipResourceCrud) CreatedPending() []string { + return []string{baremetal.ResourceCreating} +} + +func (s *UserGroupMembershipResourceCrud) CreatedTarget() []string { + return []string{baremetal.ResourceActive} +} + +func (s *UserGroupMembershipResourceCrud) DeletedPending() []string { + return []string{baremetal.ResourceDeleting} +} + +func (s *UserGroupMembershipResourceCrud) DeletedTarget() []string { + return []string{baremetal.ResourceDeleted} +} + +func (s *UserGroupMembershipResourceCrud) Get() (e error) { + s.Res, e = s.Client.GetUserGroupMembership(s.D.Id()) + return +} + +func (s *UserGroupMembershipResourceCrud) SetData() { + s.D.Set("compartment_id", s.Res.CompartmentID) + s.D.Set("group_id", s.Res.GroupID) + s.D.Set("user_id", s.Res.UserID) + s.D.Set("inactive_state", s.Res.InactiveStatus) + s.D.Set("state", s.Res.State) + s.D.Set("time_created", s.Res.TimeCreated.String()) +} + +func (s *UserGroupMembershipResourceCrud) Delete() (e error) { + return s.Client.DeleteUserGroupMembership(s.D.Id(), nil) +} diff --git a/identity/user_group_memberships_datasource.go b/identity/user_group_memberships_datasource.go new file mode 100644 index 00000000000..3ce08ea4b11 --- /dev/null +++ b/identity/user_group_memberships_datasource.go @@ -0,0 +1,42 @@ +// Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + +package identity + +import ( + "github.com/MustWin/terraform-Oracle-BareMetal-Provider/client" + "github.com/MustWin/terraform-Oracle-BareMetal-Provider/crud" + "github.com/hashicorp/terraform/helper/schema" +) + +func UserGroupMembershipDatasource() *schema.Resource { + return &schema.Resource{ + Read: readUserGroupMemberships, + Schema: map[string]*schema.Schema{ + "compartment_id":{ + Type: schema.TypeString, + Required: true, + }, + "user_id":{ + Type: schema.TypeString, + Optional: true, + }, + "group_id":{ + Type: schema.TypeString, + Optional: true, + }, + "memberships": { + Type: schema.TypeList, + Computed: true, + Elem: UserGroupMembershipResource(), + }, + }, + } +} + +func readUserGroupMemberships(d *schema.ResourceData, m interface{}) (e error) { + client := m.(client.BareMetalClient) + sync := &UserGroupMembershipDatasourceCrud{} + sync.D = d + sync.Client = client + return crud.ReadResource(sync) +} diff --git a/identity/user_group_memberships_datasource_crud.go b/identity/user_group_memberships_datasource_crud.go new file mode 100644 index 00000000000..d974d98c7ae --- /dev/null +++ b/identity/user_group_memberships_datasource_crud.go @@ -0,0 +1,43 @@ +// Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + +package identity + +import ( + "time" + + "github.com/MustWin/baremetal-sdk-go" + "github.com/MustWin/terraform-Oracle-BareMetal-Provider/crud" +) + +type UserGroupMembershipDatasourceCrud struct { + crud.BaseCrud + Res *baremetal.ListUserGroupMemberships +} + +func (s *UserGroupMembershipDatasourceCrud) Get() (e error) { + s.Res, e = s.Client.ListUserGroupMemberships(nil) + return +} + +func (s *UserGroupMembershipDatasourceCrud) SetData() { + if s.Res != nil { + s.D.SetId(time.Now().UTC().String()) + resources := []map[string]interface{}{} + for _, v := range s.Res.Memberships { + res := map[string]interface{}{ + "compartment_id": v.CompartmentID, + "id": v.ID, + "user_id": v.UserID, + "group_id": v.GroupID, + "inactive_state": v.InactiveStatus, + "state": v.State, + "time_created": v.TimeCreated.String(), + } + resources = append(resources, res) + } + if err := s.D.Set("memberships", resources); err != nil { + panic(err) + } + } + return +} diff --git a/identity_policy_datasource_test.go b/identity_policy_datasource_test.go new file mode 100644 index 00000000000..6a2f97288c0 --- /dev/null +++ b/identity_policy_datasource_test.go @@ -0,0 +1,97 @@ +// Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + +package main + +import ( + "fmt" + "testing" + "time" + + "github.com/MustWin/baremetal-sdk-go" + "github.com/MustWin/terraform-Oracle-BareMetal-Provider/client/mocks" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/terraform" + + "github.com/stretchr/testify/suite" +) + +var testPoliciesConfig = ` + data "baremetal_identity_policies" "p" { + compartment_id = "%s" + } +` + +type ResourceIdentityPoliciesTestSuite struct { + suite.Suite + Client *mocks.BareMetalClient + Provider terraform.ResourceProvider + Providers map[string]terraform.ResourceProvider + TimeCreated time.Time + Config string + PoliciesName string + Policies baremetal.ListPolicies +} + +func (s *ResourceIdentityPoliciesTestSuite) SetupTest() { + s.Client = &mocks.BareMetalClient{} + s.Provider = Provider(func(d *schema.ResourceData) (interface{}, error) { + return s.Client, nil + }, + ) + s.Providers = map[string]terraform.ResourceProvider{ + "baremetal": s.Provider, + } + s.TimeCreated, _ = time.Parse("2006-Jan-02", "2006-Jan-02") + s.Config = fmt.Sprintf(testProviderConfig+testPoliciesConfig, "7") + s.PoliciesName = "data.baremetal_identity_policies.p" + s.Policies = baremetal.ListPolicies{ + Policies: []baremetal.Policy{ + baremetal.Policy{ + ID: "123", + Name: "pol", + Description: "desc", + CompartmentID: "7", + State: baremetal.ResourceActive, + TimeCreated: s.TimeCreated, + Statements: []string{"statementX", "statementY"}, + }, + baremetal.Policy{ + ID: "234", + Name: "pol2", + Description: "desc2", + CompartmentID: "7", + State: baremetal.ResourceActive, + TimeCreated: s.TimeCreated, + Statements: []string{"statementY", "statementZ"}, + }, + }, + } + + s.Client.On( + "ListPolicies", + "7", + (*baremetal.ListOptions)(nil), + ).Return(&s.Policies, nil) + +} + +func (s *ResourceIdentityPoliciesTestSuite) TestListResourceIdentityPolicies() { + resource.UnitTest(s.T(), resource.TestCase{ + Providers: s.Providers, + Steps: []resource.TestStep{ + { + Config: s.Config, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(s.PoliciesName, "policies.0.id", s.Policies.Policies[0].ID), + resource.TestCheckResourceAttr(s.PoliciesName, "policies.0.statements.1", s.Policies.Policies[0].Statements[1]), + ), + }, + }, + }, + ) +} + +func TestResourceIdentityPoliciesTestSuite(t *testing.T) { + suite.Run(t, new(ResourceIdentityPoliciesTestSuite)) +} diff --git a/identity_swift_password_datasource_test.go b/identity_swift_password_datasource_test.go new file mode 100644 index 00000000000..64cc6fa4554 --- /dev/null +++ b/identity_swift_password_datasource_test.go @@ -0,0 +1,98 @@ +// Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + +package main + +import ( + "fmt" + "testing" + "time" + + "github.com/MustWin/baremetal-sdk-go" + "github.com/MustWin/terraform-Oracle-BareMetal-Provider/client/mocks" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/terraform" + + "github.com/stretchr/testify/suite" + "strconv" +) + +var testPasswordsConfig = ` + data "baremetal_identity_swift_passwords" "p" { + user_id = "%s" + } +` + +type ResourceIdentitySwiftPasswordsTestSuite struct { + suite.Suite + Client *mocks.BareMetalClient + Provider terraform.ResourceProvider + Providers map[string]terraform.ResourceProvider + TimeCreated time.Time + Config string + PasswordsName string + PasswordList baremetal.ListSwiftPasswords +} + +func (s *ResourceIdentitySwiftPasswordsTestSuite) SetupTest() { + s.Client = &mocks.BareMetalClient{} + s.Provider = Provider(func(d *schema.ResourceData) (interface{}, error) { + return s.Client, nil + }, + ) + s.Providers = map[string]terraform.ResourceProvider{ + "baremetal": s.Provider, + } + s.TimeCreated, _ = time.Parse("2006-Jan-02", "2006-Jan-02") + s.Config = fmt.Sprintf(testProviderConfig+testPasswordsConfig, "userid") + s.PasswordsName = "data.baremetal_identity_swift_passwords.p" + s.PasswordList = baremetal.ListSwiftPasswords{ + SwiftPasswords: []baremetal.SwiftPassword{ + { + Password: "pass", + ID: "1", + UserID: "userid", + Description: "desc", + State: "available", + InactiveStatus: 0, + TimeCreated: time.Now(), + }, + { + Password: "pass", + ID: "2", + UserID: "userid", + Description: "desc", + State: "available", + InactiveStatus: 0, + TimeCreated: time.Now(), + }, + }, + } + + s.Client.On( + "ListSwiftPasswords", + "userid", + ).Return(&s.PasswordList, nil) + +} + +func (s *ResourceIdentitySwiftPasswordsTestSuite) TestListResourceIdentitySwiftPasswords() { + resource.UnitTest(s.T(), resource.TestCase{ + Providers: s.Providers, + Steps: []resource.TestStep{ + { + Config: s.Config, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(s.PasswordsName, "passwords.0.id", s.PasswordList.SwiftPasswords[0].ID), + resource.TestCheckResourceAttr(s.PasswordsName, "passwords.1.id", s.PasswordList.SwiftPasswords[1].ID), + resource.TestCheckResourceAttr(s.PasswordsName, "passwords.#", strconv.Itoa(len(s.PasswordList.SwiftPasswords))), + ), + }, + }, + }, + ) +} + +func TestResourceIdentitySwiftPasswordsTestSuite(t *testing.T) { + suite.Run(t, new(ResourceIdentitySwiftPasswordsTestSuite)) +} diff --git a/identity_swift_password_test.go b/identity_swift_password_test.go new file mode 100644 index 00000000000..014ff52f140 --- /dev/null +++ b/identity_swift_password_test.go @@ -0,0 +1,135 @@ +// Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + +package main + +import ( + "testing" + "time" + + "github.com/MustWin/baremetal-sdk-go" + "github.com/MustWin/terraform-Oracle-BareMetal-Provider/client/mocks" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/terraform" + + "github.com/stretchr/testify/suite" +) + +type ResourceIdentitySwiftPasswordTestSuite struct { + suite.Suite + Client *mocks.BareMetalClient + Provider terraform.ResourceProvider + Providers map[string]terraform.ResourceProvider + TimeCreated time.Time + Config string + ResourceName string + Res *baremetal.SwiftPassword +} + +func (s *ResourceIdentitySwiftPasswordTestSuite) SetupTest() { + s.Client = &mocks.BareMetalClient{} + + s.Provider = Provider( + func(d *schema.ResourceData) (interface{}, error) { + return s.Client, nil + }, + ) + + s.Providers = map[string]terraform.ResourceProvider{ + "baremetal": s.Provider, + } + + description := "blah blah blah" + s.Config = ` + resource "baremetal_identity_swift_password" "t" { + user_id = "user_id" + description = "` + description + `" + } + ` + s.Config += testProviderConfig + + s.TimeCreated = time.Now() + s.ResourceName = "baremetal_identity_swift_password.t" + + s.Res = &baremetal.SwiftPassword{ + ID: "id", + Password: "password", + TimeCreated: s.TimeCreated, + State: baremetal.ResourceActive, + UserID: "user_id", + Description: description, + } + s.Res.ETag = "etag" + s.Res.RequestID = "opcrequestid" + + s.Client.On("CreateSwiftPassword", "user_id", description, (*baremetal.RetryTokenOptions)(nil)). + Return(s.Res, nil).Once() + s.Client.On("ListSwiftPasswords", "user_id"). + Return( + &baremetal.ListSwiftPasswords{ + SwiftPasswords: []baremetal.SwiftPassword{ + *s.Res, + }, + }, nil).Twice() + s.Client.On("DeleteSwiftPassword", "id", "user_id", (*baremetal.IfMatchOptions)(nil)).Return(nil).Once() +} + +func (s *ResourceIdentitySwiftPasswordTestSuite) TestCreateSwiftPassword() { + resource.UnitTest(s.T(), resource.TestCase{ + Providers: s.Providers, + Steps: []resource.TestStep{ + { + Config: s.Config, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(s.ResourceName, "user_id", "user_id"), + resource.TestCheckResourceAttr(s.ResourceName, "password", "password"), + ), + }, + }, + }) +} + +func (s ResourceIdentitySwiftPasswordTestSuite) TestUpdateDescriptionUpdatesSwiftPassword() { + config := ` + resource "baremetal_identity_swift_password" "t" { + user_id = "user_id" + description = "nah nah nah" + } + ` + config += testProviderConfig + + res := &baremetal.SwiftPassword{} + *res = *s.Res + res.Description = "nah nah nah" + s.Client.On("UpdateSwiftPassword", "id", "user_id", &baremetal.UpdateIdentityOptions{Description: res.Description}). + Return(res, nil) + s.Client.On("ListSwiftPasswords", "user_id"). + Return( + &baremetal.ListSwiftPasswords{ + SwiftPasswords: []baremetal.SwiftPassword{ + *res, + }, + }, nil).Twice() + + resource.UnitTest(s.T(), resource.TestCase{ + Providers: s.Providers, + Steps: []resource.TestStep{ + { + Config: s.Config, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(s.ResourceName, "password", "password"), + ), + }, + { + Config: config, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(s.ResourceName, "description", res.Description), + ), + }, + }, + }) +} + +func TestResourceIdentitySwiftPasswordTestSuite(t *testing.T) { + suite.Run(t, new(ResourceIdentitySwiftPasswordTestSuite)) +} diff --git a/identity_user_group_membership_datasource_test.go b/identity_user_group_membership_datasource_test.go new file mode 100644 index 00000000000..667d11f5079 --- /dev/null +++ b/identity_user_group_membership_datasource_test.go @@ -0,0 +1,202 @@ +// Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + +package main + +import ( + "testing" + "time" + + "github.com/MustWin/baremetal-sdk-go" + "github.com/MustWin/terraform-Oracle-BareMetal-Provider/client/mocks" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/terraform" + + "github.com/stretchr/testify/suite" + "fmt" +) + +type ResourceIdentityUserGroupMembershipsTestSuite struct { + suite.Suite + Client *mocks.BareMetalClient + Config string + Provider terraform.ResourceProvider + Providers map[string]terraform.ResourceProvider + ResourceName string + List *baremetal.ListUserGroupMemberships +} + +func (s *ResourceIdentityUserGroupMembershipsTestSuite) SetupTest() { + s.Client = &mocks.BareMetalClient{} + s.Provider = Provider(func(d *schema.ResourceData) (interface{}, error) { + return s.Client, nil + }) + + s.Providers = map[string]terraform.ResourceProvider{ + "baremetal": s.Provider, + } + + + s.Config = ` + resource "baremetal_identity_user" "u" { + name = "user_name" + description = "user desc" + } + resource "baremetal_identity_group" "g" { + name = "group_name" + description = "group desc" + } + resource "baremetal_identity_user_group_membership" "ug_membership" { + compartment_id = "cid" + user_id = "${baremetal_identity_user.u.id}" + group_id = "${baremetal_identity_group.g.id}" + } + ` + s.Config += testProviderConfig + s.ResourceName = "baremetal_identity_user_group_membership.ug_membership" + u1 := &baremetal.User{ + ID: "user_id", + Name: "user_name", + Description: "user desc", + CompartmentID: "cid", + State: baremetal.ResourceActive, + TimeCreated: time.Now(), + } + g1 := &baremetal.Group{ + ID: "group_id", + Name: "group_name", + Description: "group desc", + CompartmentID: "cid", + State: baremetal.ResourceActive, + TimeCreated: time.Now(), + } + m1 := &baremetal.UserGroupMembership{ + CompartmentID: "cid", + GroupID: g1.ID, + ID: "user_group_id", + State: baremetal.ResourceActive, + TimeCreated: time.Now(), + UserID: u1.ID, + } + + s.List = &baremetal.ListUserGroupMemberships{ + Memberships: []baremetal.UserGroupMembership{*m1}, + } + s.Client.On("CreateUser", "user_name", "user desc", (*baremetal.RetryTokenOptions)(nil)). + Return(u1, nil) + s.Client.On("GetUser", u1.ID).Return(u1, nil) + s.Client.On("CreateGroup", "group_name", "group desc", (*baremetal.RetryTokenOptions)(nil)).Return(g1, nil) + s.Client.On("GetGroup", g1.ID).Return(g1, nil) + s.Client.On("AddUserToGroup", "user_id", "group_id", (*baremetal.RetryTokenOptions)(nil)).Return(m1, nil) + s.Client.On("ListUserGroupMemberships", (*baremetal.ListMembershipsOptions)(nil)).Return(s.List, nil) + s.Client.On("GetUserGroupMembership", m1.ID).Return(m1, nil) + s.Client.On("DeleteUser", "user_id", (*baremetal.IfMatchOptions)(nil)).Return(nil) + s.Client.On("DeleteGroup", "group_id", (*baremetal.IfMatchOptions)(nil)).Return(nil) + s.Client.On("DeleteUserGroupMembership", "user_group_id", (*baremetal.IfMatchOptions)(nil)).Return(nil) +} + +func (s *ResourceIdentityUserGroupMembershipsTestSuite) TestCreateUserGroupMemberships() { + fmt.Println(s.Config) + resource.UnitTest(s.T(), resource.TestCase{ + PreventPostDestroyRefresh: true, + Providers: s.Providers, + Steps: []resource.TestStep{ + { + Config: s.Config, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(s.ResourceName, "id", "user_group_id"), + ), + }, + }, + }, + ) +} + +func (s *ResourceIdentityUserGroupMembershipsTestSuite) TestGetUserGroupMembershipsByGroup() { + config := s.Config + config += ` + data "baremetal_identity_user_group_memberships" "g_memberships" { + compartment_id = "cid" + group_id = "${baremetal_identity_group.g.id}" + }` + resource.UnitTest(s.T(), resource.TestCase{ + PreventPostDestroyRefresh: true, + Providers: s.Providers, + Steps: []resource.TestStep{ + { + Config: s.Config, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(s.ResourceName, "id", "user_group_id"), + ), + }, + { + Config: config, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.baremetal_identity_user_group_memberships.g_memberships", "memberships.0.id", "user_group_id"), + ), + }, + }, + }, + ) +} + +func (s *ResourceIdentityUserGroupMembershipsTestSuite) TestGetUserGroupMembershipsByUser() { + config := s.Config + config += ` + data "baremetal_identity_user_group_memberships" "u_memberships" { + compartment_id = "cid" + user_id = "${baremetal_identity_user.u.id}" + }` + resource.UnitTest(s.T(), resource.TestCase{ + PreventPostDestroyRefresh: true, + Providers: s.Providers, + Steps: []resource.TestStep{ + { + Config: s.Config, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(s.ResourceName, "id", "user_group_id"), + ), + }, + { + Config: config, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.baremetal_identity_user_group_memberships.u_memberships", "memberships.0.id", "user_group_id"), + ), + }, + }, + }, + ) +} + +func (s *ResourceIdentityUserGroupMembershipsTestSuite) TestGetUserGroupMembershipsByUserAndGroup() { + config := s.Config + config += ` + data "baremetal_identity_user_group_memberships" "ug_memberships" { + compartment_id = "cid" + user_id = "${baremetal_identity_user.u.id}" + group_id = "${baremetal_identity_group.g.id}" + }` + resource.UnitTest(s.T(), resource.TestCase{ + PreventPostDestroyRefresh: true, + Providers: s.Providers, + Steps: []resource.TestStep{ + { + Config: s.Config, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(s.ResourceName, "id", "user_group_id"), + ), + }, + { + Config: config, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.baremetal_identity_user_group_memberships.ug_memberships", "memberships.0.id", "user_group_id"), + ), + }, + }, + }, + ) +} + +func TestResourceIdentityUserGroupMembershipsTestSuite(t *testing.T) { + suite.Run(t, new(ResourceIdentityUserGroupMembershipsTestSuite)) +} diff --git a/provider.go b/provider.go index fd58c4e714e..c224d30c559 100644 --- a/provider.go +++ b/provider.go @@ -24,7 +24,7 @@ func init() { "fingerprint": "(Required) The fingerprint for the user's RSA key. This can be found in user settings in the Bare Metal console.", "private_key": "(Optional) A PEM formatted RSA private key for the user.\n" + "A private_key or a private_key_path must be provided.", - "private_key_path": "(Required) The path to the user's PEM formatted private key.\n" + + "private_key_path": "(Optional) The path to the user's PEM formatted private key.\n" + "A private_key or a private_key_path must be provided.", "private_key_password": "(Optional) The password used to secure the private key.", } @@ -67,7 +67,7 @@ func schemaMap() map[string]*schema.Schema { }, "private_key_path": { Type: schema.TypeString, - Required: true, + Optional: true, Description: descriptions["private_key_path"], }, "private_key_password": { @@ -90,9 +90,9 @@ func dataSourcesMap() map[string]*schema.Resource { "baremetal_core_images": core.ImageDatasource(), "baremetal_core_instances": core.InstanceDatasource(), "baremetal_core_internet_gateways": core.InternetGatewayDatasource(), - "baremetal_core_ipsec_config": core.IPSecConfigDatasource(), + "baremetal_core_ipsec_config": core.IPSecConnectionConfigDatasource(), "baremetal_core_ipsec_connections": core.IPSecConnectionsDatasource(), - "baremetal_core_ipsec_status": core.IPSecStatusDatasource(), + "baremetal_core_ipsec_status": core.IPSecConnectionStatusDatasource(), "baremetal_core_route_tables": core.RouteTableDatasource(), "baremetal_core_security_lists": core.SecurityListDatasource(), "baremetal_core_shape": core.ShapeDatasource(), @@ -117,7 +117,10 @@ func dataSourcesMap() map[string]*schema.Resource { "baremetal_identity_availability_domains": identity.AvailabilityDomainDatasource(), "baremetal_identity_compartments": identity.CompartmentDatasource(), "baremetal_identity_groups": identity.GroupDatasource(), + "baremetal_identity_policies": identity.PolicyDatasource(), "baremetal_identity_users": identity.UserDatasource(), + "baremetal_identity_user_group_memberships": identity.UserGroupMembershipDatasource(), + "baremetal_identity_swift_passwords": identity.SwiftPasswordDatasource(), "baremetal_objectstorage_bucket_summaries": objectstorage.BucketSummaryDatasource(), "baremetal_objectstorage_object_head": objectstorage.ObjectHeadDatasource(), "baremetal_objectstorage_objects": objectstorage.ObjectDatasource(), @@ -135,7 +138,7 @@ func resourcesMap() map[string]*schema.Resource { "baremetal_core_image": core.ImageResource(), "baremetal_core_instance": core.InstanceResource(), "baremetal_core_internet_gateway": core.InternetGatewayResource(), - "baremetal_core_ipsec": core.IPSecResource(), + "baremetal_core_ipsec": core.IPSecConnectionResource(), "baremetal_core_route_table": core.RouteTableResource(), "baremetal_core_security_list": core.SecurityListResource(), "baremetal_core_subnet": core.SubnetResource(), @@ -150,6 +153,8 @@ func resourcesMap() map[string]*schema.Resource { "baremetal_identity_policy": identity.PolicyResource(), "baremetal_identity_ui_password": identity.UIPasswordResource(), "baremetal_identity_user": identity.UserResource(), + "baremetal_identity_user_group_membership": identity.UserGroupMembershipResource(), + "baremetal_identity_swift_password": identity.SwiftPasswordResource(), "baremetal_objectstorage_bucket": objectstorage.BucketResource(), "baremetal_objectstorage_object": objectstorage.ObjectResource(), } @@ -174,7 +179,7 @@ func providerConfig(d *schema.ResourceData) (client interface{}, err error) { } else if hasKeyPath && privateKeyPath != "" { clientOpts = append(clientOpts, baremetal.PrivateKeyFilePath(privateKeyPath)) } else { - err = errors.New("private_key_path is required") + err = errors.New("One of private_key or private_key_path is required") return } diff --git a/vendor/github.com/MustWin/baremetal-sdk-go/client.go b/vendor/github.com/MustWin/baremetal-sdk-go/client.go index 6c7fec4225e..9037fc85eb0 100644 --- a/vendor/github.com/MustWin/baremetal-sdk-go/client.go +++ b/vendor/github.com/MustWin/baremetal-sdk-go/client.go @@ -44,6 +44,7 @@ import ( "crypto/x509" "encoding/pem" "errors" + "fmt" "io/ioutil" "net/http" ) @@ -121,20 +122,11 @@ func NewClient(userOCID, tenancyOCID, keyFingerprint string, opts ...NewClientOp for _, opt := range opts { opt(nco) } - if nco.keyPassword == nil { - // the private key file is not encrypted - if nco.keyPath != nil { - auth.privateRSAKey, err = PrivateKeyFromUnencryptedFile(*nco.keyPath) - } else { - auth.privateRSAKey, err = PrivateKeyFromUnencryptedBytes(nco.keyBytes) - } + + if nco.keyPath != nil { + auth.privateRSAKey, err = PrivateKeyFromFile(*nco.keyPath, nco.keyPassword) } else { - // encrypted private key - if nco.keyPath != nil { - auth.privateRSAKey, err = PrivateKeyFromFile(*nco.keyPath, *nco.keyPassword) - } else { - auth.privateRSAKey, err = PrivateKeyFromBytes(nco.keyBytes, *nco.keyPassword) - } + auth.privateRSAKey, err = PrivateKeyFromBytes(nco.keyBytes, nco.keyPassword) } if err != nil { return nil, err @@ -178,31 +170,21 @@ func New(userOCID, tenancyOCID, keyFingerPrint string, privateKey *rsa.PrivateKe } } -// NewFromKeyPath creates a client reading an RSA private key from a file. The -// userOCID and tenancyOCID are obtained from the BareMetal console. -// The fingerprint can be obtained from the BareMetal console or running -// openssl rsa -pubout -outform DER -in private.pem | openssl md5 -c -func NewFromKeyPath(userOCID, tenancyOCID, keyFingerPrint, privateKeyPath, keyPassword string) (c *Client, e error) { - var key *rsa.PrivateKey - - if key, e = PrivateKeyFromFile(privateKeyPath, keyPassword); e != nil { - return - } - - c = New(userOCID, tenancyOCID, keyFingerPrint, key) - - return -} - // PrivateKeyFromBytes is a helper function that will produce a RSA private // key from bytes. -func PrivateKeyFromBytes(pemData []byte, password string) (key *rsa.PrivateKey, e error) { +func PrivateKeyFromBytes(pemData []byte, password *string) (key *rsa.PrivateKey, e error) { if pemBlock, _ := pem.Decode(pemData); pemBlock != nil { - var decrypted []byte + decrypted := pemBlock.Bytes - if decrypted, e = x509.DecryptPEMBlock(pemBlock, []byte(password)); e != nil { - return + if x509.IsEncryptedPEMBlock(pemBlock) { + if password == nil { + e = fmt.Errorf("private_key_password is required for encrypted private keys") + return + } + if decrypted, e = x509.DecryptPEMBlock(pemBlock, []byte(*password)); e != nil { + return + } } key, e = x509.ParsePKCS1PrivateKey(decrypted) @@ -215,10 +197,7 @@ func PrivateKeyFromBytes(pemData []byte, password string) (key *rsa.PrivateKey, return } -// PrivateKeyFromFile is a helper function that will produce an RSA private -// key from a PEM file. The PEM file MUST be created with a password which -// is supplied as an argument. -func PrivateKeyFromFile(pemFilePath, password string) (key *rsa.PrivateKey, e error) { +func PrivateKeyFromFile(pemFilePath string, password *string) (key *rsa.PrivateKey, e error) { var fileData []byte if fileData, e = ioutil.ReadFile(pemFilePath); e != nil { return @@ -229,15 +208,3 @@ func PrivateKeyFromFile(pemFilePath, password string) (key *rsa.PrivateKey, e er return } -func PrivateKeyFromUnencryptedBytes(pemBytes []byte) (*rsa.PrivateKey, error) { - pemBlock, _ := pem.Decode(pemBytes) - return x509.ParsePKCS1PrivateKey(pemBlock.Bytes) -} - -func PrivateKeyFromUnencryptedFile(path string) (*rsa.PrivateKey, error) { - buff, err := ioutil.ReadFile(path) - if err != nil { - return nil, err - } - return PrivateKeyFromUnencryptedBytes(buff) -} diff --git a/vendor/github.com/MustWin/baremetal-sdk-go/core_cpe.go b/vendor/github.com/MustWin/baremetal-sdk-go/core_cpe.go index daf280a37c6..632e582d4b7 100644 --- a/vendor/github.com/MustWin/baremetal-sdk-go/core_cpe.go +++ b/vendor/github.com/MustWin/baremetal-sdk-go/core_cpe.go @@ -78,9 +78,9 @@ func (c *Client) CreateCpe(compartmentID, ipAddress string, opts *CreateOptions) return } -// GetCpe retrieves information on a customer premise equipment resource. +// UpdateCpe retrieves information on a customer premise equipment resource. // -// See https://docs.us-az-phoenix-1.oracleiaas.com/api/#/en/core/20160918/Cpe/GetCpe +// https://docs.us-az-phoenix-1.oracleiaas.com/api/#/en/iaas/20160918/Cpe/UpdateCpe func (c *Client) GetCpe(id string) (cpe *Cpe, e error) { details := &requestDetails{ name: resourceCustomerPremiseEquipment, @@ -96,6 +96,26 @@ func (c *Client) GetCpe(id string) (cpe *Cpe, e error) { return } +// Updates the specified CPE's display name. +// +// See https://docs.us-az-phoenix-1.oracleiaas.com/api/#/en/iaas/20160918/Cpe/UpdateCpe +func (c *Client) UpdateCpe(id string, opts *IfMatchDisplayNameOptions) (cpe *Cpe, e error) { + details := &requestDetails{ + name: resourceCustomerPremiseEquipment, + ids: urlParts{id}, + optional: opts, + } + var resp *response + if resp, e = c.coreApi.request(http.MethodPut, details); e != nil { + return + } + + cpe = &Cpe{} + e = resp.unmarshal(cpe) + + return +} + // DeleteCpe removes customer premise equipment resource // // See https://docs.us-az-phoenix-1.oracleiaas.com/api/#/en/core/20160918/Cpe/DeleteCpe diff --git a/vendor/github.com/MustWin/baremetal-sdk-go/core_drg.go b/vendor/github.com/MustWin/baremetal-sdk-go/core_drg.go index 5e826c5f94f..f12aad04d19 100644 --- a/vendor/github.com/MustWin/baremetal-sdk-go/core_drg.go +++ b/vendor/github.com/MustWin/baremetal-sdk-go/core_drg.go @@ -68,6 +68,26 @@ func (c *Client) GetDrg(id string) (res *Drg, e error) { return } +// Updates the specified DRG's display name. +// +// See https://docs.us-az-phoenix-1.oracleiaas.com/api/#/en/iaas/20160918/Drg/UpdateDrg +func (c *Client) UpdateDrg(id string, opts *IfMatchDisplayNameOptions) (drg *Drg, e error) { + details := &requestDetails{ + name: resourceDrgs, + ids: urlParts{id}, + optional: opts, + } + var resp *response + if resp, e = c.coreApi.request(http.MethodPut, details); e != nil { + return + } + + drg = &Drg{} + e = resp.unmarshal(drg) + + return +} + // DeleteDrg removes a gateway // // See https://docs.us-az-phoenix-1.oracleiaas.com/api/#/en/core/20160918/Drg/DeleteDrg diff --git a/vendor/github.com/MustWin/baremetal-sdk-go/core_drg_attachment.go b/vendor/github.com/MustWin/baremetal-sdk-go/core_drg_attachment.go index 8a423c074b3..a2a6ef272ce 100644 --- a/vendor/github.com/MustWin/baremetal-sdk-go/core_drg_attachment.go +++ b/vendor/github.com/MustWin/baremetal-sdk-go/core_drg_attachment.go @@ -78,6 +78,26 @@ func (c *Client) GetDrgAttachment(id string) (res *DrgAttachment, e error) { return } +// Updates the display name for the specified DrgAttachment. +// +// See https://docs.us-az-phoenix-1.oracleiaas.com/api/#/en/iaas/20160918/DrgAttachment/UpdateDrgAttachment +func (c *Client) UpdateDrgAttachment(id string, opts *IfMatchDisplayNameOptions) (drg *DrgAttachment, e error) { + details := &requestDetails{ + name: resourceDrgAttachments, + ids: urlParts{id}, + optional: opts, + } + var resp *response + if resp, e = c.coreApi.request(http.MethodPut, details); e != nil { + return + } + + drg = &DrgAttachment{} + e = resp.unmarshal(drg) + + return +} + // DeleteDrgAttachment detaches a drg from its vcn // // See https://docs.us-az-phoenix-1.oracleiaas.com/api/#/en/core/20160918/DrgAttachment/DeleteDrgAttachment diff --git a/vendor/github.com/MustWin/baremetal-sdk-go/core_ipsec.go b/vendor/github.com/MustWin/baremetal-sdk-go/core_ipsec.go index fdbcdc084b5..ea695ab744d 100644 --- a/vendor/github.com/MustWin/baremetal-sdk-go/core_ipsec.go +++ b/vendor/github.com/MustWin/baremetal-sdk-go/core_ipsec.go @@ -144,6 +144,26 @@ func (c *Client) GetIPSecConnection(id string) (conn *IPSecConnection, e error) return } +// Updates the display name for the specified IPSec connection. +// +// See https://docs.us-az-phoenix-1.oracleiaas.com/api/#/en/iaas/20160918/IPSecConnection/UpdateIPSecConnection +func (c *Client) UpdateIPSecConnection(id string, opts *IfMatchDisplayNameOptions) (conn *IPSecConnection, e error) { + details := &requestDetails{ + name: resourceIPSecConnections, + ids: urlParts{id}, + optional: opts, + } + var resp *response + if resp, e = c.coreApi.request(http.MethodPut, details); e != nil { + return + } + + conn = &IPSecConnection{} + e = resp.unmarshal(conn) + + return +} + // DeleteIPSecConnection deletes an IPSec connection. // // See https://docs.us-az-phoenix-1.oracleiaas.com/api/core.html#deleteIPSecConnection diff --git a/vendor/github.com/MustWin/baremetal-sdk-go/core_subnet.go b/vendor/github.com/MustWin/baremetal-sdk-go/core_subnet.go index 12d1bbf7df8..d966ea61720 100644 --- a/vendor/github.com/MustWin/baremetal-sdk-go/core_subnet.go +++ b/vendor/github.com/MustWin/baremetal-sdk-go/core_subnet.go @@ -93,6 +93,26 @@ func (c *Client) GetSubnet(id string) (subnet *Subnet, e error) { return } +// Updates the display name for the specified Subnet. +// +// See https://docs.us-az-phoenix-1.oracleiaas.com/api/#/en/iaas/20160918/Subnet/UpdateSubnet +func (c *Client) UpdateSubnet(id string, opts *IfMatchDisplayNameOptions) (subnet *Subnet, e error) { + details := &requestDetails{ + name: resourceSubnets, + ids: urlParts{id}, + optional: opts, + } + var resp *response + if resp, e = c.coreApi.request(http.MethodPut, details); e != nil { + return + } + + subnet = &Subnet{} + e = resp.unmarshal(subnet) + + return +} + // DeleteSubnet will delete a subnet with subnetID. // // See https://docs.us-az-phoenix-1.oracleiaas.com/api/#/en/core/20160918/Subnet/DeleteSubnet diff --git a/vendor/github.com/MustWin/baremetal-sdk-go/core_virtual_network.go b/vendor/github.com/MustWin/baremetal-sdk-go/core_virtual_network.go index 3253e336b0a..19c8e527ebe 100644 --- a/vendor/github.com/MustWin/baremetal-sdk-go/core_virtual_network.go +++ b/vendor/github.com/MustWin/baremetal-sdk-go/core_virtual_network.go @@ -85,7 +85,7 @@ func (c *Client) GetVirtualNetwork(id string) (vcn *VirtualNetwork, e error) { // UpdateVirtualNetwork updates information about a virtual network // // See https://docs.us-az-phoenix-1.oracleiaas.com/api/#/en/iaas/20160918/Vcn/UpdateVcn -func (c *Client) UpdateVirtualNetwork(id string, opts *UpdateBackupOptions) (vcn *VirtualNetwork, e error) { +func (c *Client) UpdateVirtualNetwork(id string, opts *IfMatchDisplayNameOptions) (vcn *VirtualNetwork, e error) { details := &requestDetails{ ids: urlParts{id}, name: resourceVirtualNetworks, diff --git a/vendor/github.com/MustWin/baremetal-sdk-go/request_options.go b/vendor/github.com/MustWin/baremetal-sdk-go/request_options.go index bcbb179a59d..2a3266d2fa0 100644 --- a/vendor/github.com/MustWin/baremetal-sdk-go/request_options.go +++ b/vendor/github.com/MustWin/baremetal-sdk-go/request_options.go @@ -101,6 +101,11 @@ type UpdateOptions struct { DisplayNameOptions } +type IfMatchDisplayNameOptions struct { + IfMatchOptions + DisplayNameOptions +} + type UpdateBackupOptions struct { IfMatchOptions DisplayNameOptions diff --git a/vendor/vendor.json b/vendor/vendor.json index 7aa20e19426..59ffc4052b2 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -315,10 +315,10 @@ "revisionTime": "2017-02-01T00:43:30Z" }, { - "checksumSHA1": "wYaTLm75UavI6/pIUQmjn0ADuFQ=", + "checksumSHA1": "q7sNDDQOLVldBMnCjLt2TqtiPIE=", "path": "github.com/MustWin/baremetal-sdk-go", - "revision": "a752832acbe62467024ca9b5bc2a745b7d6ce96d", - "revisionTime": "2017-02-28T02:28:25Z" + "revision": "1a3103a9916bda38973c427d117ae4e19dd66bea", + "revisionTime": "2017-03-07T20:36:27Z" }, { "checksumSHA1": "Aqy8/FoAIidY/DeQ5oTYSZ4YFVc=",