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

fierce-engine-31599

05/06/2021, 12:20 PM
Hey all! I'm trying to rollout gradually my cloud run service but with no success so far and I would love your advise:
Copy code
const runningService = pulumi.output(
  gcp.cloudrun.getService(
    { name, location },
    {
      async: true,
    },
  ),
);
const service = new gcp.cloudrun.Service(
  name,
  {
    name,
    // autogenerateRevisionName: true,
    location,
    traffics: runningService.traffics,
    template: {
      metadata: {
        name: 'api-rolling-test3',
        annotations: {
          '<http://run.googleapis.com/vpc-access-connector|run.googleapis.com/vpc-access-connector>': vpcConnector.name,
          '<http://run.googleapis.com/vpc-access-egress|run.googleapis.com/vpc-access-egress>': 'private-ranges-only',
        },
      },
      spec: {
        serviceAccountName: serviceAccount.email,
        containers: [
          {
            image,
            resources: { limits: { cpu: '1', memory: '512Mi' } },
            envs: secrets,
          },
        ],
        containerConcurrency: 250,
      },
    },
  },
  { dependsOn: [...iamMembers, redis] },
);
Above is the service creation and then I want to update only the traffic property so I'm trying to create another service:
Copy code
new gcp.cloudrun.Service(
  name,
  {
    name,
    location,
    traffics: [
      {
        revisionName: runningService.traffics[0].revisionName,
        percent: 99,
      },
      {
        revisionName: service.template.apply(
          (template) => template?.metadata.name || '',
        ),
        percent: 1,
      },
    ],
  },
  { dependsOn: [service] },
);
But it throws duplicate urn error 🥴
b

bumpy-summer-9075

05/06/2021, 12:52 PM
Well, you're creating both resources with the same
name
, the first parameter should be different for every resource of the same type
f

fierce-engine-31599

05/06/2021, 1:53 PM
Yes, but they are the same resource actually. I'm just trying to change the
traffics
object somehow. If it was a regular JavaScript program I would just do
service.traffics = ...
but I can't so I'm trying to find a workaround
r

red-match-15116

05/06/2021, 2:38 PM
If you want to change the traffics object just change it in your original resource definition and it will update on the next pulumi up
f

fierce-engine-31599

05/06/2021, 3:06 PM
I want to do it gradually. First create the resource without driving traffic and then slowly increase it. Like a CD process of sorts
r

red-match-15116

05/06/2021, 3:10 PM
Pulumi drives to a declarative state defined in your program. So writing the same resource with different properties won’t do what you are trying. You might try looking at automation api to do something of this sort.