We have a go backend implementing a automation API...
# automation-api
e
We have a go backend implementing a automation API.
func CreateStorageBucket(ctx *pulumi.Context, cmnLogs []zapcore.Field, provider *gcp.Provider, config config.Config) (err error) {
log.Logger.Debug(log.TraceMsgFuncStart(CreateStorageBucketMethod), log.TraceMethodInputs(cmnLogs, config)...)
defer log.Logger.Debug(log.TraceMsgFuncEnd(CreateStorageBucketMethod), log.TraceError(cmnLogs, err)...)
// Declare variables
var bucket *storage.Bucket
bucketName := fmt.Sprintf("%s-%s", config.BucketName, uuid.New().String())
bucket, err = storage.NewBucket(ctx, bucketName, &storage.BucketArgs{
Location: pulumi.String(config.Location),
}, pulumi.Provider(provider))
if err != nil {
log.Logger.Error(log.TraceMsgErrorOccurredFrom(NewBucketMethod), log.TraceError(cmnLogs, err)...)
return err
}
// Export the bucket details
exportBucketDetails(ctx, bucket)
return nil
}
This is where the storage bucket create. When we create a postaman req like this it'll create the bucket.
{
"stack": "dev",
"pulumi_project": "pulumi-compute-project",
"workload_specs": {
"type": "storage",
"cloud": "gcp",
"properties": {
"name": "mys3-225",
"bucketName": "mys3-2256",
"project": "prj-dev-platform-next",
"location": "us-central1"
}
}
}
now what's happening is when i rename the bucketName and send the req again, it'll only rename the bucketName. I want to create a new storage with the new name. How do i do that ?
h
Are you using the same stack? You will need to create a new stack for new objects or add another bucket in the same stack.
e
yes I'm using the same stack. can i add a new storage for the same stack ?
h
guess it depends on what you are using this storage for? this s not for your pulumi state backend right ?
e
nope. storages are using for another things
h
ok. Then yes a stack can have as many things you need...
e
but when i send a different bucketName, it'll only change the current bucket name i can't create a new one
h
every object you create has a unique ID besides the name you are giving. The pulumi state tracks these objects using their unique ID and NOT the names. name just happens to be a property of the object. If you need to create another bucket, add the same logic/code once more to create a new object. You will need to learn a few more basics on iac stuff.
e
ohh, can't i do it without adding a new code piece???, because this is going to containerize and deploy.
h
guess not sure what yo are trying to do. From a programming language perspective there are many tricks - new piece of code / new section / a loop with as many objects you need SO cant say whats best for you. Also what if you want to change some thing for what you have already deployed ? how do you plan to address the life cycle of the object?
e
no this is for a client. requirement is they want to be able to deploy as many as resource from the frontend via a API call
h
ok. so you need a generic code and ask them what resources they want to deploy / and if they want to modify an existing resource etc. //disclaimer// - may not be a solution for you. we developed qmcloud.io exactly for this kind of ask but its a commercial tool with a UI etc. and it generates code automatically in TS. built with automation api but we have a front end wrapper with diagramming etc..
e
understood ! thanks for this