@@ -5,11 +5,11 @@ package provider
55import (
66 "context"
77 "fmt"
8+ "strconv"
9+ "strings"
810
911 "github.com/hashicorp/terraform/helper/schema"
1012
11- "strconv"
12-
1313 oci_identity "github.com/oracle/oci-go-sdk/identity"
1414)
1515
@@ -86,6 +86,7 @@ func createUser(d *schema.ResourceData, m interface{}) error {
8686 sync := & UserResourceCrud {}
8787 sync .D = d
8888 sync .Client = m .(* OracleClients ).identityClient
89+ sync .Configuration = m .(* OracleClients ).configuration
8990
9091 return CreateResource (d , sync )
9192}
@@ -118,6 +119,7 @@ func deleteUser(d *schema.ResourceData, m interface{}) error {
118119type UserResourceCrud struct {
119120 BaseCrud
120121 Client * oci_identity.IdentityClient
122+ Configuration map [string ]string
121123 Res * oci_identity.User
122124 DisableNotFoundRetries bool
123125}
@@ -156,7 +158,12 @@ func (s *UserResourceCrud) Create() error {
156158 if compartmentId , ok := s .D .GetOkExists ("compartment_id" ); ok {
157159 tmp := compartmentId .(string )
158160 request .CompartmentId = & tmp
159- } else {
161+ } else { // @next-break: remove
162+ // Prevent potentially inferring wrong TenancyOCID from InstancePrincipal
163+ if auth := s .Configuration ["auth" ]; strings .ToLower (auth ) == strings .ToLower (authInstancePrincipalSetting ) {
164+ return fmt .Errorf ("compartment_id must be specified for this resource" )
165+ }
166+ // Maintain legacy contract of compartment_id defaulting to tenancy ocid if not specified
160167 c := * s .Client .ConfigurationProvider ()
161168 if c == nil {
162169 return fmt .Errorf ("cannot access tenancyOCID" )
0 commit comments