sparse-intern-71089
01/21/2022, 3:15 PMprehistoric-activity-61023
01/21/2022, 3:16 PMprehistoric-activity-61023
01/21/2022, 3:16 PMsticky-airline-40485
01/21/2022, 3:17 PMBucket bucket
object, but how can I then modify this bucket
?prehistoric-activity-61023
01/21/2022, 3:18 PMprehistoric-activity-61023
01/21/2022, 3:18 PMmillions-furniture-75402
01/21/2022, 3:18 PMprehistoric-activity-61023
01/21/2022, 3:19 PMpulumi up
sticky-airline-40485
01/21/2022, 3:20 PMprehistoric-activity-61023
01/21/2022, 3:20 PMprehistoric-activity-61023
01/21/2022, 3:21 PMsticky-airline-40485
01/21/2022, 3:21 PMprehistoric-activity-61023
01/21/2022, 3:21 PMprehistoric-activity-61023
01/21/2022, 3:22 PMprehistoric-activity-61023
01/21/2022, 3:22 PMsticky-airline-40485
01/21/2022, 3:24 PMimport
the only way to modify an existing resouce then? Because Bucket.Get
doesn't allow a BucketArgs
parameter (it only has a similar BucketState
parameter, which only helps qualify the search)prehistoric-activity-61023
01/21/2022, 3:24 PMsticky-airline-40485
01/21/2022, 3:25 PMprehistoric-activity-61023
01/21/2022, 3:27 PMBucket.Get
allows you to GET some information about an existing resource (so you can use that in other resources managed by pulumi). However, it does NOT ADD IT TO THE STATE so the resource is not managed by pulumi and because of that, it cannot be altered.
import
DOES ADD TO THE STATE so the resource becomes pulumi-managed. That means if you don’t alter your code appropriately (based on the code snippet pulumi import
should print for you), pulumi will think you want to delete that resource (it goes like this: “it’s present in the state, it’s not defined in code => remove it from the cloud so code==state)millions-furniture-75402
01/21/2022, 3:28 PMconst myBucketModifications = new aws.s3.Bucket(`${appName}-with-mods`, {
bucket: aws.s3.Bucket.get("my-bucket", "my-bucket-id").bucket,
serverSideEncryptionConfiguration: {
rule: {
applyServerSideEncryptionByDefault: {
sseAlgorithm: "AES256",
},
},
},
});
millions-furniture-75402
01/21/2022, 3:31 PMprehistoric-activity-61023
01/21/2022, 3:31 PMprehistoric-activity-61023
01/21/2022, 3:37 PM❯ pulumi -s <REDACTED> import gcp:storage/bucket:Bucket my-python-var-name example-pulumi-bucket
...
Please copy the following code into your Pulumi application. Not doing so
will cause Pulumi to report that an update will happen on the next update command.
Please note that the imported resources are marked as protected. To destroy them
you will need to remove the `protect` option and run `pulumi update` *before*
the destroy will take effect.
import pulumi
import pulumi_gcp as gcp
my_python_var_name = gcp.storage.Bucket("my-python-var-name",
force_destroy=False,
location="US",
name="example-pulumi-bucket",
storage_class="STANDARD",
opts=pulumi.ResourceOptions(protect=True))
as you can see, at the end there’s a python snippet I should add to my code to match the (already) modified state.
I added this snippet to my main.py
and when I run pulumi up
, it says there’s nothing to change. Now, when I modify it like this:
my_python_var_name = gcp.storage.Bucket("my-python-var-name",
force_destroy=False,
location="US",
name="example-pulumi-bucket",
storage_class="STANDARD",
=> versioning=gcp.storage.BucketVersioningArgs(enabled=True),
opts=pulumi.ResourceOptions(protect=True))
it wants to alter my bucket:
Type Name Plan Info
pulumi:pulumi:Stack <REDACTED>
~ └─ gcp:storage:Bucket my-python-var-name update [diff: +versioning]
Resources:
~ 1 to update
10 unchanged