gorgeous-minister-41131
04/30/2021, 11:27 PMtags
attr for a resource Input.tags = merge_dict(self.default_tags, {})
tags["Name"] = self.cluster_randomized_name
@property
def cluster_randomized_name(self):
if not self._cluster_randomized_name:
self._cluster_randomized_name = pulumi_random.RandomPet(
f"eks-cluster-{self.cluster_name}", prefix="eks"
).id
return self._cluster_randomized_name
role = pulumi_aws.iam.Role(
cluster_role_name_key,
name=self.cluster_randomized_name,
assume_role_policy=template_rendered(
template_env=self.template_env,
template_file="assume_role_policy_eks_service.json.j2",
),
tags=tags,
opts=pulumi.ResourceOptions(
ignore_changes=["tags"] if import_id is not None else [],
import_=import_id,
),
)
File "/Users/thomasfarvour/.local/share/virtualenvs/pulumi-bYKQDQ7d/lib/python3.8/site-packages/google/protobuf/internal/well_known_types.py", line 731, in _SetStructValue
struct_value.struct_value.update(value)
File "/Users/thomasfarvour/.local/share/virtualenvs/pulumi-bYKQDQ7d/lib/python3.8/site-packages/google/protobuf/internal/well_known_types.py", line 805, in update
_SetStructValue(self.fields[key], value)
TypeError: <pulumi.output.Output object at 0x116a9b130> has type Output, but expected one of: bytes, unicode
error: an unhandled error occurred: Program exited with non-zero exit code: 1
Exception ignored in: <coroutine object Output.apply.<locals>.run at 0x116aafe40>
Traceback (most recent call last):
File "/Users/thomasfarvour/.local/share/virtualenvs/pulumi-bYKQDQ7d/lib/python3.8/site-packages/pulumi/output.py", line 209, in run
result_resources.set_result(resources)
UnboundLocalError: local variable 'resources' referenced before assignment
Exception ignored in: <coroutine object Output.apply.<locals>.run at 0x116ab82c0>
Traceback (most recent call last):
tags = {
"Name": subnet_name_key,
"tier": subnet_scope,
}
tags[
pulumi.Output.concat("<http://kubernetes.io/cluster/|kubernetes.io/cluster/>", self.cluster_randomized_name)
] = "owned"
stale-hamburger-8953
05/01/2021, 4:40 AMred-match-15116
05/02/2021, 12:55 AMdef get_tags(subnet_name_key, subnet_scope, cluster_name):
return {
"Name": subnet_name_key,
"tier": subnet_scope,
f"<http://kubernetes.io/cluster/{cluster_name}|kubernetes.io/cluster/{cluster_name}>": "owned"
}
tags = pulumi.Output
.all(subnet_name_key, subnet_scope, self.cluster_randomized_name)
.apply(lambda args: get_tags(args[0], args[1], args[2]))
subnet = pulumi_aws.ec2.Subnet(
subnet_name_key,
cidr_block=params["cidr_block"],
vpc_id=self.vpc_id,
tags=tags,
opts=pulumi.ResourceOptions(
ignore_changes=["tags"] if import_id is not None else [],
import_=import_id,
),
)
gorgeous-minister-41131
05/03/2021, 6:30 PMred-match-15116
05/03/2021, 6:43 PMIt works though!Indeed! It works because you are creating the dictionary within the
apply
just as my suggestion does.
And yes, there are many ways of doing the same thing, but there is a reason that the recommendation not to create resources within your apply exists. You are free to ignore the recommendation, but it can lead to unexpected behavior 😄gorgeous-minister-41131
05/03/2021, 9:03 PMdef subnet_route_table_assoc_1(
rtb, rtb_id, rtb_tags, subnet_params, subnet_resource
):
if subnet_params["zone"] == rtb_tags["zone"]:
rta_name = f"vpc-{self.default_vpc_name}-rta-{rtb_id}-{subnet_params['cidr_block']}"
pulumi_aws.ec2.RouteTableAssociation(
rta_name,
route_table_id=rtb_id,
subnet_id=subnet_resource.id,
opts=pulumi.ResourceOptions(parent=rtb, depends_on=[rtb]),
)
def subnet_route_table_assoc(rtbs, subnet_params, subnet_resource):
for rtb in rtbs.values():
pulumi.Output.all(
rtb, rtb.id, rtb.tags, subnet_params, subnet_resource
).apply(lambda args1: subnet_route_table_assoc_1(*args1))
for subnet in self.in_private_subnets:
self._cluster_private_subnets[subnet["cidr_block"]] = self.create_subnet(
params=subnet,
is_public=False,
)
# Associate the route table for the appropriate zone and scope to this
# if it is passed in.
pulumi.Output.all(
self.private_route_tables,
subnet,
self.cluster_private_subnets[subnet["cidr_block"]],
).apply(lambda args: subnet_route_table_assoc(*args))
should_create
and allow that to be a future..should_create
pulumi opt/input[T]?count
directive… since the entire HCL was declarative, there was no if/else block — thus the resource had to physically exist in the code in the main thread, but didn’t necessarily get created unless the future count was truthy…
so I guess, TL;DR, this is the type of flag I’m looking for on a pulumi resource.. woudl be very handy! and maybe it exists already and I’m unaware of it?