Thread
#general
    b

    bored-barista-23480

    8 months ago
    Hi folks! I have some trouble using transformations on a K8s config file. It's essentially the same as in this [Example](https://www.pulumi.com/docs/guides/adopting/from_kubernetes/) (under Configuration Transformations). I check for the kind of the resource and if it is a certain type I change a value. But I get the error:
    TypeError: 'ResourceTransformationArgs' object is not subscriptable
    . I could not find any mention of this error specific to this class. I also could't find any helpful examples of how to use transformations other than the mentioned one. Anyone have a clue why it does not work and how to fix it?
    p

    prehistoric-activity-61023

    8 months ago
    it looks like a python error - you can get it when you want to use object like a dict, that is instead of
    obj.a
    , you try to use
    obj["a"]
    let me try to repro it locally, maybe docs are not up-to-date
    It works for me on: • Python 3.8.5 • Pulumi 3.22.1 • pulumi-kubernetes==3.14.1
    import pulumi
    import pulumi_kubernetes as k8s
    
    # Create resources from standard Kubernetes guestbook YAML example.
    def make_frontend_public(obj):
        if obj['kind'] == "Service" and obj['metadata']['name'] == "frontend":
            obj['spec']['type'] = "LoadBalancer"
    
    guestbook = k8s.yaml.ConfigFile('guestbook', 'guestbook-all-in-one.yaml', transformations=[make_frontend_public])
    (it’s copy’n’paste example from the docs)
    @bored-barista-23480 can you paste your environment setup here? Things like: • python version
    python --version
    • pulumi cli version
    pulumi version
    • python modules
    (within venv) pip freeze | grep pulumi
    You can also try to upgrade the dependencies first and see if that resolves the issue.
    b

    bored-barista-23480

    8 months ago
    Python:
    3.8.10
    Pulumi:
    3.22.1
    Modules:
    pulumi==3.22.1
    pulumi-aws==4.35.0
    pulumi-eks==0.36.0
    pulumi-kubernetes==3.14.1
    Obviously I am trying to use the subscript functionality. But that's how it is used in the example as well. I think I even used it like that before. That's why I'm irritated.
    p

    prehistoric-activity-61023

    8 months ago
    (yeah, just to be clear, I successfully run the code above that uses subscription as well)
    what’s weird, you’ve got the same versions as I have (except python but that shouldn’t cause such an issue)
    oh wait… I think I know that might be wrong (let me check, it’s just a guess)
    @bored-barista-23480 make sure you’re passing
    transformations
    as
    ConfigMap
    field and not using generic resource transformations available through
    opts
    and pulumi.ResourceOptions: WORKING EXAMPLE
    guestbook = k8s.yaml.ConfigFile(
      'guestbook',
      'guestbook-all-in-one.yaml', 
      transformations=[make_frontend_public],
    )
    ERROR
    guestbook = k8s.yaml.ConfigFile(
      'guestbook',
      'guestbook-all-in-one.yaml', 
      opts=pulumi.ResourceOptions(transformations=[make_frontend_public]),
    )
    b

    bored-barista-23480

    8 months ago
    Ah! Yes, that solves the issue! I just missed that little difference. Thank you very much! 🙂