@@ -17,6 +17,8 @@ const (
1717 hostname = "shadecloud"
1818 refIDTagName = "refID"
1919 cloudCredRefIDTagName = "cloudCredRefID" //nolint:gosec // not a secret
20+ instanceNameFormat = "%v_%v"
21+ instanceNameSeparator = "_"
2022)
2123
2224func (c * ShadeformClient ) CreateInstance (ctx context.Context , attrs v1.CreateInstanceAttrs ) (* v1.Instance , error ) { //nolint:gocyclo,funlen // ok
@@ -88,7 +90,7 @@ func (c *ShadeformClient) CreateInstance(ctx context.Context, attrs v1.CreateIns
8890 Cloud : * cloudEnum ,
8991 Region : region ,
9092 ShadeInstanceType : shadeInstanceType ,
91- Name : attrs .Name ,
93+ Name : c . getInstanceNameForShadeform ( attrs .RefID , attrs . Name ) ,
9294 ShadeCloud : true ,
9395 Tags : tags ,
9496 SshKeyId : & sshKeyID ,
@@ -123,6 +125,19 @@ func (c *ShadeformClient) CreateInstance(ctx context.Context, attrs v1.CreateIns
123125 return createdInstance , nil
124126}
125127
128+ func (c * ShadeformClient ) getInstanceNameForShadeform (refID string , providedName string ) string {
129+ return fmt .Sprintf (instanceNameFormat , refID , providedName )
130+ }
131+
132+ func (c * ShadeformClient ) getProvidedInstanceName (shadeformInstanceName string ) string {
133+ before , after , found := strings .Cut (shadeformInstanceName , instanceNameSeparator )
134+ if found {
135+ return after
136+ } else {
137+ return before
138+ }
139+ }
140+
126141func (c * ShadeformClient ) addSSHKey (ctx context.Context , keyPairName string , publicKey string ) (string , error ) {
127142 authCtx := c .makeAuthContext (ctx )
128143
@@ -261,7 +276,7 @@ func (c *ShadeformClient) convertInstanceInfoResponseToV1Instance(instanceInfo o
261276 delete (tags , cloudCredRefIDTagName )
262277
263278 instance := & v1.Instance {
264- Name : instanceInfo .Name ,
279+ Name : c . getProvidedInstanceName ( instanceInfo .Name ) ,
265280 CreatedAt : instanceInfo .CreatedAt ,
266281 CloudID : v1 .CloudProviderInstanceID (instanceInfo .Id ),
267282 PublicIP : instanceInfo .Ip ,
0 commit comments