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

cuddly-leather-18640

10/19/2018, 7:51 PM
I’m getting the following error:
Cannot call '.get' during update or preview
and I think it’s from the following new TS I added to my index.ts:
Copy code
let apiIntentRobotServiceAccount = new k8s.core.v1.ServiceAccount(
  'api-intent-robot-service-account', {
    metadata: {
      name: 'api-intent-robot',
      namespace: context.inferredNamespace
    }
  }
)

let apiIntentEphemeralRobotRole = new k8s.rbac.v1.Role(
  'api-intent-ephemeral-robot-role',
  {
    metadata: {
      name: 'api-intent-robot-role',
      namespace: EPHEMERAL_NAMESPACE_NAME
    },
    rules: [
      {
        apiGroups: [''],
        resources: ['pods', 'pods/status'],
        verbs: ['get', 'create', 'patch', 'delete', 'list', 'status']
      }
    ]
  }
)

let apiIntentEphemeralRolebinding = new k8s.rbac.v1.RoleBinding(
  'api-intent-ephemeral-robot-rolebinding',
  {
    metadata: {
      name: 'api-intent-robot-rolebinding',
      namespace: EPHEMERAL_NAMESPACE_NAME
    },
    roleRef: {
      name: apiIntentEphemeralRobotRole.metadata.get().name,
      apiGroup: apiIntentEphemeralRobotRole.apiVersion,
      kind: apiIntentEphemeralRobotRole.kind
    },
    subjects: [
      {
        kind: apiIntentRobotServiceAccount.kind,
        name: apiIntentRobotServiceAccount.metadata.get().name,
      }
    ]
  })
Am I not allowed to get the name of a resource to use in the spec of another resource?
c

creamy-potato-29402

10/19/2018, 7:54 PM
@cuddly-leather-18640 try this instead:
Copy code
apiIntentRobotServiceAccount.metadata.apply(m => m.name)
get
does something else.
.apply
is the method you want.
c

cuddly-leather-18640

10/19/2018, 7:55 PM
it worked!
c

creamy-potato-29402

10/19/2018, 7:56 PM
👍🏼
c

cuddly-leather-18640

10/19/2018, 7:56 PM
is there documentation on this somewhere? I’m surprised that
get
doesn’t give me the resource
followup question @creamy-potato-29402: I created the resources in my paste first through yaml and applied them. Now i’m trying to move the resources to pulumi and the preview is showing that they all need to be created. is that expected behavior?
c

creamy-potato-29402

10/19/2018, 7:59 PM
@cuddly-leather-18640 yes, these docs are generated from the typescript comments: https://pulumi.io/reference/pkg/nodejs/@pulumi/pulumi/index.html#method-get
w

white-balloon-205

10/19/2018, 7:59 PM
There's some light conceptual docs on this here https://pulumi.io/reference/programming-model.html#outputs. But more is definitely needed. /cc also @lemon-spoon-91807.
c

creamy-potato-29402

10/19/2018, 7:59 PM
So if you are using vscode or something like that, hovering over
get
should tell you what the method does.
@cuddly-leather-18640 I’m not sure I understand your follow-up question?
Have you created those resources in Pulumi?
If you haven’t run
pulumi up
before, the preview is going to tell you that it’s going to create those resources.
c

cuddly-leather-18640

10/19/2018, 8:02 PM
ah gotcha, even if those resources already exist pre-pulumi? I’ve already written and applied a k8s yaml spec with a service account, role and rolebinding. Now I’m moving this yaml to pulumi and it seems that
preview
isn’t seeing what I’ve already applied
c

creamy-potato-29402

10/19/2018, 8:02 PM
Pulumi will not know about them if you didn’t create them with Pulumi
You can use
k8s.core.v1.ServiceAccount.get('api-intent-robot')
to reference resources that already exist.
c

cuddly-leather-18640

10/19/2018, 8:06 PM
ah gotcha
thanks 🙂
g

glamorous-printer-66548

10/20/2018, 1:58 AM
@cuddly-leather-18640 since this a common pattern I actually added a utility function to our library few days ago.
Copy code
apiIntentRobotServiceAccount.metadata.apply(m => m.name)
you can just write:
Copy code
import { getName} from '@solvvy/pulumi-util';

getName(apiIntentRobotServiceAccount);
🙂
❤️ 1
2 Views