This message was deleted.
# python
s
This message was deleted.
f
It won’t work like that because
bootstrap_storage_account_name
is also an
Output
You will want to invert where the
json.dumps
happens:
Copy code
protected_settings=combined_output.apply(lambda lst: json.dumps({'storageAccountName': lst[0], 'storageAccountKey': lst[1]}))
c
how do I pass
combined_output
to a component?
f
You had
combined_output = Output.all(install_scripts_storage_account.name, install_scripts_storage_account.primary_access_key, install_scripts_storage_blob.url)
earlier
And that should work just fine
c
yeah, but that's in my
___main___.py
, the
protected_settings
is in a different file, a component, so I have to pass the
combined_output
to the component
f
Ah, I didn’t realize that. You can pass it any way you’d normally pass state between files in Python. For example, if the other file defines functions, one of which creates that component, and your
__main__.py
calls that function, you can pass it as an arg when calling that function.
c
interestingly, that's what I have done in my snippet above, just wasn't clear about the fact that the
compute.extensions
is part of the component and the
combined_output
is in the main. That's what threw the error I mentioned.
f
Gotcha. Were you able to get this working by having the
json.dumps
within the lambda?
c
I just tried this: `___main___.py`:
Copy code
storage_information = [
  install_scripts_storage_account.name,
  install_scripts_storage_account.primary_access_key,
  install_scripts_storage_blob.url
]
vms = Compute("vms",
  ComputeArgs(
    resource_group_name=resource_group.name,
    vnet=network.vnet,
    public_subnet_id=network.public_subnet_id,
    storage_info=storage_information
  )
)
`component.py`:
Copy code
class ComputeArgs:
  def __init__(
    self,
    resource_group_name: str,
    vnet: network.VirtualNetwork,
    public_subnet_id: str,
    storage_info: list
  ):
    self.resource_group_name = resource_group_name
    self.vnet = vnet
    self.public_subnet_id = public_subnet_id
    self.storage_info = storage_info

compute.Extension("{0}install".format(server),
        name="{0}install".format(server),
        virtual_machine_id=vm.id,
        publisher="Microsoft.Compute",
        type="CustomScriptExtension",
        type_handler_version="1.9",
        auto_upgrade_minor_version=True,
        settings=args.storage_info.apply(lambda lst: json.dumps({'commandToExecute': command_to_execute, 'fileUris': [args.bootstrap_file_name]})),
        protected_settings=args.storage_info.apply(lambda lst: json.dumps({'storageAccountName': lst[0], 'storageAccountKey': lst[1]}))
      )
This doesn't work, saying that
list
doesn't have an
apply
method. I believe I need to do the
apply
in the
main
, which I have tried, but that never worked.
I think I got it working now.
main
Copy code
install_extension_settings = combined_output.apply(lambda lst: json.dumps({'commandToExecute': command_to_execute, 'fileUris': [lst[2]]}))
install_extension_protected_settings = combined_output.apply(lambda lst: json.dumps({'storageAccountName': lst[0], 'storageAccountKey': lst[1]}))
Passing that over to the component. Would've liked to do this inside the component though. Seems like Outputs don't like to do that though.