https://pulumi.com logo
#general
Title
# general
t

thousands-planet-78612

08/25/2021, 1:01 PM
i am creating multiple eks cluster in single stack using automation api in golang, Now i would like to delete one of eks cluster using automation api , could anyone pls point me to some example to delete resource in stack
b

brash-quill-35776

08/25/2021, 1:03 PM
don't think you can delete one single resource inside a stack, this is for IAC usage, if you just want to randomly play around resources, you should do it manually
t

thousands-planet-78612

08/25/2021, 1:11 PM
Thanks @brash-quill-35776 for reply to delete resource manually , one method i am using URN as per following code
Copy code
ursrole := []string{"urn:pulumi:stack1::project1::aws:eks/cluster:Cluster::eks-cluster-1"}
	// destroy the stack
	//we'll write all of the logs to stdout so we can watch requests get processed
	_, err = s.Destroy(ctx, optdestroy.Target(ursrole))
	if err != nil {
		fmt.Println(err.Error())
	}
I am getting following error , is this right method to delete resource manually.?
Copy code
failed to destroy stack: exit status 1
code: 1
stdout: 
stderr: Error: unknown flag: --target urn:pulumi:stack1::project1::aws:eks/cluster:Cluster::eks-cluster-1
Usage:
Also i would like to confirm if i am providing right format to delete resources
Copy code
ursrole := []string{"urn:pulumi:stack1::project1::aws:eks/cluster:Cluster::eks-cluster-1"}
b

brash-quill-35776

08/25/2021, 1:15 PM
it depends, please check AWS doc. Pulumi is mean to create resources in IAC fashion so you can programatically create and destroy environment in reproducible way, rather than manually doing so. if you are sure that 1 resource is no longer require, you should remove it from your pulumi and update the stack again.
t

thousands-planet-78612

08/25/2021, 1:51 PM
Thanks @brash-quill-35776 this were i am struggling how to remove resource programtically using automation api the only option i found is to destroy stack and resources.
Copy code
// destroy the stack
	//we'll write all of the logs to stdout so we can watch requests get processed
	_, err = s.Destroy(ctx, optdestroy.ProgressStreams(os.Stdout))
	if err != nil {
		fmt.Println(err.Error())
	}
b

brash-quill-35776

08/25/2021, 1:52 PM
simply remove it from your code and
pulumi up
should be all good
t

thousands-planet-78612

08/25/2021, 1:59 PM
do you mean removing the resource from stack file and then pulumi up?
b

brash-quill-35776

08/25/2021, 1:59 PM
ya
which from your code
t

thousands-planet-78612

08/25/2021, 2:00 PM
What do you mean by
which from your code
b

brash-quill-35776

08/25/2021, 2:01 PM
literally remove it from your code
like you created 3 resources, and now you remove 1 of them , then run
pulumi up
t

thousands-planet-78612

08/25/2021, 2:13 PM
i am using this example
<https://github.com/pulumi/examples/blob/master/aws-go-eks/main.go>
to create multiple eks cluster using rest api which mean the same code can be used to create multile cluster in single stack, what i am not understand what code need to be remove to destroy specific eks clsuter. How pulumi will understand which specific cluster resource need deleting if i remove form a specific section of my code. Also the values for the resources are dynamically provided during cluster creation.
b

brash-quill-35776

08/25/2021, 2:14 PM
please try it
d

dry-autumn-28966

10/01/2021, 1:29 PM
@thousands-planet-78612 Did you ever found a solution to that
unknown flag: --target
error? I am getting the same when using the Go automation API but the URN is definitely valid.
In case anyone run into the same issue: https://github.com/pulumi/pulumi/pull/8109
3 Views