def __init__(self, name, opts=None): super().__init__("my:component:MyComponent", name, {}, opts) self.child = SimpleResource(f"{name}-child1", {"input": "hello"}, ResourceOptions(parent=self)) self.child = SimpleResource(f"{name}-child2", {"input": "hello"}, ResourceOptions(parent=self)) self.register_outputs({})
def subnet_special( stem, name, virtual_network_name, address_prefix, route_table_id, depends_on=None, ): sn = network.Subnet( f'{stem}{s}sn', name=name, resource_group_name=resource_group_name, virtual_network_name=virtual_network_name, address_prefixes=[address_prefix], opts=ResourceOptions( parent=self, delete_before_replace=True, depends_on=depends_on, ), ) rta = network.SubnetRouteTableAssociation( f'{stem}{s}sn{s}rta', route_table_id=route_table_id, subnet_id=sn.id, opts=ResourceOptions(parent=self, depends_on=depends_on), ) return sn
def __init__(self, name: str, args: DbArgs, opts: ResourceOptions = None): super().__init__('custom:resource:Backend', name, {}, opts) # Create RDS subnet group to put RDS instance on. subnet_group_name = f'{name}-sng' rds_subnet_group = rds.SubnetGroup(subnet_group_name, subnet_ids=args.subnet_ids, tags={ 'Name': subnet_group_name }, opts=ResourceOptions(parent=self) ) rds_name = f'{name}-rds' self.db = rds.Instance(rds_name, name=args.db_name, allocated_storage=args.allocated_storage, engine=args.engine, engine_version=args.engine_version, instance_class=args.instance_class, storage_type=args.storage_type, db_subnet_group_name=rds_subnet_group.id, username=args.db_user, password=args.db_password, vpc_security_group_ids=args.security_group_ids, skip_final_snapshot=args.skip_final_snapshot, publicly_accessible=args.publicly_accessible, opts=ResourceOptions(parent=self) ) self.register_outputs({})
def expressroute_gateway(stem, subnet_id, depends_on=None): er_gw_pip = network.PublicIp( f'{stem}{s}er{s}gw{s}pip{s}{suffix}', resource_group_name=resource_group_name, location=location, allocation_method='Dynamic', tags=tags, opts=ResourceOptions(parent=self, depends_on=depends_on), ) er_gw = network.VirtualNetworkGateway( f'{stem}{s}er{s}gw{s}{suffix}', resource_group_name=resource_group_name, location=location, sku='Standard', type='ExpressRoute', vpn_type='RouteBased', ip_configurations=[ network.VirtualNetworkGatewayIpConfigurationArgs( name=f'{stem}{s}er{s}gw{s}ipc', public_ip_address_id=er_gw_pip.id, subnet_id=subnet_id, ) ], tags=tags, opts=ResourceOptions( parent=self, depends_on=depends_on, custom_timeouts=CustomTimeouts( create='1h', update='1h', delete='1h', ), ), ) return er_gw
def vpn_gateway(stem, subnet_id, depends_on=None): vpn_gw_pip = network.PublicIp( f'{stem}-vpn-gw-pip-', resource_group_name=resource_group_name, allocation_method='Dynamic', tags=tags, opts=ResourceOptions(parent=self), ) vpn_gw = network.VirtualNetworkGateway( f'{stem}-vpn-gw-', resource_group_name=resource_group_name, sku='VpnGw1', type='Vpn', vpn_type='RouteBased', ip_configurations=[ network.VirtualNetworkGatewayIpConfigurationArgs( name=f'{stem}-vpn-gw-ipconf', public_ip_address_id=vpn_gw_pip.id, subnet_id=subnet_id, ) ], tags=tags, opts=ResourceOptions( parent=self, depends_on=depends_on, custom_timeouts=CustomTimeouts( create='1h', update='1h', delete='1h', ), ), ) return vpn_gw
def __init__(self, name: str, args: VpcArgs, opts: ResourceOptions = None): super().__init__("my:modules:Vpc", name, {}, opts) child_opts = ResourceOptions(parent=self) self.network = compute.Network(name, auto_create_subnetworks=False, opts=ResourceOptions(parent=self)) self.subnets = [] for i, ip_cidr_range in enumerate(args.subnet_cidr_blocks): subnet = compute.Subnetwork( f"{name}-{i}", network=self.network.self_link, ip_cidr_range=ip_cidr_range, opts=ResourceOptions(parent=self.network)) self.subnets.append(subnet) self.router = compute.Router(name, network=self.network.self_link, opts=ResourceOptions(parent=self.network)) self.nat = compute.RouterNat( name, router=self.router.name, nat_ip_allocate_option="AUTO_ONLY", source_subnetwork_ip_ranges_to_nat="ALL_SUBNETWORKS_ALL_IP_RANGES", opts=ResourceOptions(parent=self.network)) self.register_outputs({})
def expressroute_gateway(stem, subnet_id, depends_on=None): er_gw_pip = network.PublicIp( f'{stem}-er-gw-pip-', resource_group_name=resource_group_name, allocation_method='Dynamic', tags=tags, opts=ResourceOptions(parent=self), ) er_gw = network.VirtualNetworkGateway( f'{stem}-er-gw-', resource_group_name=resource_group_name, sku='Standard', type='ExpressRoute', vpn_type='RouteBased', ip_configurations=[{ 'name': f'{stem}-er-gw-ipconf', 'publicIpAddressId': er_gw_pip.id, 'subnet_id': subnet_id, }], tags=tags, opts=ResourceOptions( parent=self, depends_on=depends_on, custom_timeouts=CustomTimeouts( create='1h', update='1h', delete='1h', ), ), ) return er_gw
def __init__(self, name, opts=None): super().__init__("my:module:ComponentThree", name, None, opts) # Note that both un-prefixed and parent-name-prefixed child names are supported. For the # later, the implicit alias inherited from the parent alias will include replacing the name # prefix to match the parent alias name. resource1 = Resource1(name + "-child", ResourceOptions(parent=self)) resource2 = Resource1("otherchild", ResourceOptions(parent=self))
def vpn_gateway(stem, subnet_id, depends_on=[]): vpn_gw_pip = network.PublicIp( f'{stem}-vpn-gw-pip-', resource_group_name=resource_group_name, location=location, allocation_method='Dynamic', tags=tags, opts=ResourceOptions(parent=self), ) vpn_gw = network.VirtualNetworkGateway( f'{stem}-vpn-gw-', resource_group_name=resource_group_name, location=location, sku='VpnGw1', type='Vpn', vpn_type='RouteBased', ip_configurations=[{ 'name': f'{stem}-vpn-gw-ipconf', 'subnet_id': subnet_id, 'publicIpAddressId': vpn_gw_pip.id, }], tags=tags, opts=ResourceOptions( parent=self, depends_on=depends_on, custom_timeouts=CustomTimeouts(create='1h', update='1h', delete='1h'), ), ) return vpn_gw
def bastion_host(stem, virtual_network_name, address_prefix, depends_on=None): ab_sn = network.Subnet( f'{stem}{s}ab{s}sn', name='AzureBastionSubnet', # name required resource_group_name=resource_group_name, virtual_network_name=virtual_network_name, address_prefixes=[address_prefix], opts=ResourceOptions( parent=self, delete_before_replace=True, depends_on=depends_on, ), ) ab_pip = network.PublicIp( f'{stem}{s}ab{s}pip{s}{suffix}', resource_group_name=resource_group_name, location=location, sku='Standard', allocation_method='Static', tags=tags, opts=ResourceOptions(parent=self, depends_on=depends_on), ) ab = compute.BastionHost( f'{stem}{s}ab{s}{suffix}', resource_group_name=resource_group_name, location=location, ip_configuration=compute.BastionHostIpConfigurationArgs( name=f'{stem}{s}ab{s}ipc', public_ip_address_id=ab_pip.id, subnet_id=ab_sn.id, ), tags=tags, opts=ResourceOptions(parent=self, depends_on=depends_on), ) return ab
def firewall(stem, subnet_id, depends_on=[]): fw_pip = network.PublicIp( f'{stem}-fw-pip-', resource_group_name=resource_group_name, sku='Standard', allocation_method='Static', tags=tags, opts=ResourceOptions(parent=self), ) fw = network.Firewall( f'{stem}-fw-', resource_group_name=resource_group_name, ip_configurations=[{ 'name': f'{stem}-fw-ipconf', 'subnet_id': subnet_id, 'publicIpAddressId': fw_pip.id, }], tags=tags, opts=ResourceOptions( parent=self, depends_on=depends_on, custom_timeouts=CustomTimeouts( create='1h', update='1h', delete='1h', ), ), ) return fw
def __init__(self, name, cluster, health_check_path, listener_arn, security_groups, service_path, service_port, subnets, task_definition, vpc_id, namespace_id=None, opts: ResourceOptions = None): super().__init__("redata:service:WebService", name, {}, opts) tg = aws.lb.TargetGroup(f"{name}-tg", health_check=aws.lb.TargetGroupHealthCheckArgs( path=health_check_path), port=service_port, protocol='HTTP', target_type='ip', vpc_id=vpc_id, opts=ResourceOptions(parent=self)) lr = aws.lb.ListenerRule( f"{name}-listener-rule", listener_arn=listener_arn, actions=[ aws.lb.ListenerRuleActionArgs( type="forward", target_group_arn=tg.arn, ) ], conditions=[ aws.lb.ListenerRuleConditionArgs( path_pattern=aws.lb.ListenerRuleConditionPathPatternArgs( values=[f"{service_path}*"], ), ), ], opts=ResourceOptions(parent=self)) self.service = BackendService( name, cluster=cluster, subnets=subnets, task_definition=task_definition, namespace_id=namespace_id, security_groups=security_groups, load_balancers=[ aws.ecs.ServiceLoadBalancerArgs( target_group_arn=tg.arn, container_name=f"redata-{name}", container_port=service_port, ) ], opts=ResourceOptions(parent=self), ) self.register_outputs({})
def firewall(stem, fw_sn_id, fwm_sn_id, private_ranges, depends_on=None): fw_pip = network.PublicIPAddress( f'{stem}{s}fw{s}pip', public_ip_address_name=f'{stem}{s}fw{s}pip{s}{suffix}', resource_group_name=resource_group_name, location=location, sku=network.PublicIPAddressSkuArgs(name='Standard', ), public_ip_allocation_method='Static', tags=tags, opts=ResourceOptions(parent=self, depends_on=depends_on), ) fwm_pip = network.PublicIPAddress( f'{stem}{s}fwm{s}pip', public_ip_address_name=f'{stem}{s}fwm{s}pip{s}{suffix}', resource_group_name=resource_group_name, location=location, sku=network.PublicIPAddressSkuArgs(name='Standard', ), public_ip_allocation_method='Static', tags=tags, opts=ResourceOptions(parent=self, depends_on=depends_on), ) fw = network.AzureFirewall( f'{stem}{s}fw', azure_firewall_name=f'{stem}{s}fw{s}{suffix}', resource_group_name=resource_group_name, location=location, additional_properties={ "Network.SNAT.PrivateRanges": private_ranges, }, sku=network.AzureFirewallSkuArgs( name='AZFW_VNet', tier='Standard', ), ip_configurations=[ network.AzureFirewallIPConfigurationArgs( name=f'{stem}{s}fw{s}ipconf{s}{suffix}', public_ip_address=network.PublicIPAddressArgs(id=fw_pip.id, ), subnet=network.SubnetArgs(id=fw_sn_id, ), ) ], management_ip_configuration=network.AzureFirewallIPConfigurationArgs( name=f'{stem}{s}fwm{s}ipconf{s}{suffix}', public_ip_address=network.PublicIPAddressArgs(id=fwm_pip.id, ), subnet=network.SubnetArgs(id=fwm_sn_id, ), ), tags=tags, opts=ResourceOptions( parent=self, depends_on=depends_on, custom_timeouts=CustomTimeouts( create='1h', update='1h', delete='1h', ), ), ) return fw
def __init__(self, name: str, replicas: int = 1, image: str = None, ports: [int] = None, envvars: [dict] = None, opts: ResourceOptions = None): super().__init__("my:modules:SimpleDeployment", name, {}, opts) labels = {"app": name} container = { "name": name, "image": image, "ports": [{ "container_port": p } for p in ports] if ports else None, "env": envvars, } self.deployment = Deployment(name, spec={ "selector": { "match_labels": labels }, "replicas": replicas, "template": { "metadata": { "labels": labels }, "spec": { "containers": [container] }, }, }, opts=ResourceOptions(parent=self)) self.service = Service( name, metadata={ "name": name, "labels": self.deployment.metadata['labels'], }, spec={ "ports": [{ "port": p, "targetPort": p } for p in ports] if ports else None, "selector": self.deployment.spec['template']['metadata']['labels'], "type": "LoadBalancer", }, opts=ResourceOptions(parent=self)) self.register_outputs({})
def create_resources(name, create_children=None, parent=None): # Use all parent defaults. Resource(f"{name}/r0", create_children, ResourceOptions(parent=parent)) # Override protect Resource(f"{name}/r1", create_children, ResourceOptions(parent=parent, protect=False)) Resource(f"{name}/r2", create_children, ResourceOptions(parent=parent, protect=True)) # Override provider prov = Provider(f"{name}-p", ResourceOptions(parent=parent)) Resource(f"{name}/r3", create_children, ResourceOptions(parent=parent, provider=prov))
def create_components(name, create_children=None, parent=None): # Use all parent defaults. Component(f"{name}/c0", create_children, ResourceOptions(parent=parent)) # Override protect Component(f"{name}/c1", create_children, ResourceOptions(parent=parent, protect=False)) Component(f"{name}/c2", create_children, ResourceOptions(parent=parent, protect=True)) # Override providers provider = Provider(f"{name}-p", ResourceOptions(parent=parent)) Component(f"{name}/c3", create_children, ResourceOptions(parent=parent, provider=provider))
def __init__(self, name, opts=None): # Add an alias that references the old type of this resource... aliases = [ Alias(type_=f"my:module:ComponentSixParent-v{i}") for i in range(0, 10) ] # ..and then make the super call with the new type of this resource and the added alias. opts = ResourceOptions(aliases=aliases) super().__init__("my:module:ComponentSixParent-v10", name, None, opts) child = ComponentSix("child", ResourceOptions(parent=self))
def __init__( self, name, cluster, subnets, task_definition, load_balancers: List[aws.ecs.ServiceLoadBalancerArgs] = None, namespace_id=None, security_groups=None, opts: ResourceOptions = None, ): super().__init__("redata:service:BackendService", name, {}, opts) svc_registries_args = None if namespace_id is not None: sd_svc = aws.servicediscovery.Service( f"{name}-sd-svc", name=name, dns_config=aws.servicediscovery.ServiceDnsConfigArgs( namespace_id=namespace_id, dns_records=[ aws.servicediscovery.ServiceDnsConfigDnsRecordArgs( ttl=10, type="A") ], routing_policy="MULTIVALUE", ), health_check_custom_config=aws.servicediscovery. ServiceHealthCheckCustomConfigArgs(failure_threshold=1, ), opts=ResourceOptions(parent=self, delete_before_replace=True), ) svc_registries_args = aws.ecs.ServiceServiceRegistriesArgs( registry_arn=sd_svc.arn) self.service = aws.ecs.Service( f"{name}-svc", cluster=cluster, desired_count=1, launch_type="FARGATE", platform_version="1.4.0", service_registries=svc_registries_args, task_definition=task_definition, network_configuration=aws.ecs.ServiceNetworkConfigurationArgs( subnets=subnets, security_groups=security_groups, ), load_balancers=load_balancers, opts=ResourceOptions(parent=self), ) self.register_outputs({})
def __init__(self, name, opts=ResourceOptions()): # Add an alias that references the old type of this resource... aliases = [Alias(type_="my:module:ComponentFour")] if opts.aliases is not None: for alias in opts.aliases: aliases.append(alias) # ..and then make the super call with the new type of this resource and the added alias. opts_copy = copy.copy(opts) opts_copy.aliases = aliases super().__init__("my:differentmodule:ComponentFourWithADifferentTypeName", name, None, opts_copy) # The child resource will also pick up an implicit alias due to the new type of the component it is parented # to. res1 = Resource1("otherchild", ResourceOptions(parent=self))
def firewall(stem, fw_sn_id, fwm_sn_id, private_ranges, depends_on=None): fw_pip = network.PublicIp( f'{stem}-fw-pip-', resource_group_name=resource_group_name, sku='Standard', allocation_method='Static', tags=tags, opts=ResourceOptions(parent=self, depends_on=depends_on), ) fwm_pip = network.PublicIp( f'{stem}-fwm-pip-', resource_group_name=resource_group_name, sku='Standard', allocation_method='Static', tags=tags, opts=ResourceOptions(parent=self, depends_on=depends_on), ) fw = network.Firewall( f'{stem}-fw-', resource_group_name=resource_group_name, # additional_properties = { # "Network.SNAT.PrivateRanges": private_ranges, # }, # sku = 'AZFW_VNet', ip_configurations=[ network.FirewallIpConfigurationArgs( name=f'{stem}-fw-ipconf', public_ip_address_id=fw_pip.id, subnet_id=fw_sn_id, ) ], management_ip_configuration=network.FirewallIpConfigurationArgs( name=f'{stem}-fwm-ipconf', public_ip_address_id=fwm_pip.id, subnet_id=fwm_sn_id, ), tags=tags, opts=ResourceOptions( parent=self, depends_on=depends_on, custom_timeouts=CustomTimeouts( create='1h', update='1h', delete='1h', ), ), ) return fw
def __init__(self, name: str, args: DbArgs, opts: ResourceOptions = None): super().__init__('custom:resource:Postgres', name, {}, opts) database_instance_name = f'{name}-dbinstance' self.sql = sql.DatabaseInstance( database_instance_name, database_version=args.database_version, settings=sql.DatabaseInstanceSettingsArgs( tier=args.tier, activation_policy=args.activation_policy, availability_type=args.availability_type, disk_size=args.disk_size, ip_configuration=args.private_network, user_labels=args.tags, backup_configuration={ "enabled": args.backup_configuration_enabled, "point_in_time_recovery_enabled": args.backup_configuration_point_in_time_recovery_enabled }, ), deletion_protection=args.deletion_protection, opts=ResourceOptions(parent=self)) # creates a random password https://www.pulumi.com/docs/reference/pkg/random/randompassword/ mypassword = random.RandomPassword(f'{name}-random', length=12, special=False, lower=True, min_lower=4, min_numeric=4, min_upper=4, number=True) users_name = f'{name}-user' self.users = sql.User(users_name, instance=self.sql.id, name="pulumiadmin", password=mypassword.result, opts=ResourceOptions(parent=self.sql)) database_name = f'{name}-pulumidb' self.database = sql.Database(database_name, instance=self.sql.id, charset="UTF8", opts=ResourceOptions(parent=self.sql)) self.register_outputs({})
def __init__(self, name, opts=None): super().__init__("my:component:MyComponent", name, {}, opts) childOpts = ResourceOptions(parent=self, additional_secret_outputs=["output2"]) self.child = SimpleResource(f"{name}-child", {"input": "hello"}, childOpts) self.register_outputs({})
def __init__(self, urn): props = { "foo": None, "bar": None, } super().__init__("unused", "unused:unused:unused", True, props, ResourceOptions(urn=urn), False, False)
def res1_transformation(args: ResourceTransformationArgs): print("res1 transformation") return ResourceTransformationResult( props=args.props, opts=ResourceOptions.merge( args.opts, ResourceOptions(additional_secret_outputs=["output"], )))
def __init__(self, name: str, children: int, options: Optional[ResourceOptions] = None): super().__init__('testcomponent:index:Component', name, {}, options) for i in range(0, children): Echo(f'child-{name}-{i+1}', i + 1, ResourceOptions(parent=self))
def subnet_route_table(stem, route_table_id, subnet_id): rta = network.SubnetRouteTableAssociation( f'{stem}-sn-rta', route_table_id=route_table_id, subnet_id=subnet_id, opts=ResourceOptions(parent=self), ) return rta
def firewall(stem, fw_sn_id, fwm_sn_id, depends_on=None): fw_pip = network.PublicIp( f'{stem}-fw-pip-', resource_group_name=resource_group_name, sku='Standard', allocation_method='Static', tags=tags, opts=ResourceOptions(parent=self), ) # fwm_pip = network.PublicIp( # requires api 2019-11-01 or later # f'{stem}-fwm-pip-', # resource_group_name = resource_group_name, # sku = 'Standard', # allocation_method = 'Static', # tags = tags, # opts = ResourceOptions(parent=self), # ) fw = network.Firewall( f'{stem}-fw-', resource_group_name=resource_group_name, # sku = 'AZFW_VNet', # not required but distinguishes from 'AZFW_Hub' ip_configurations=[ network.FirewallIpConfigurationArgs( name=f'{stem}-fw-ipconf', public_ip_address_id=fw_pip.id, subnet_id=fw_sn_id, ) ], # management_ip_configuration = { # requires api 2019-11-01 or later # 'name': f'{stem}-fwm-ipconf', # 'publicIpAddressId': fwm_pip.id, # 'subnet_id': fwm_sn_id, # }, tags=tags, opts=ResourceOptions( parent=self, depends_on=depends_on, custom_timeouts=CustomTimeouts( create='1h', update='1h', delete='1h', ), ), ) return fw
def subnet(stem, virtual_network_name, address_prefix, depends_on=None): sn = network.Subnet( f'{stem}-sn-', resource_group_name=resource_group_name, address_prefixes=[address_prefix], virtual_network_name=virtual_network_name, opts=ResourceOptions(parent=self, depends_on=depends_on), ) return sn
def __init__(self, name, opts=ResourceOptions()): child_opts = copy.copy(opts) if child_opts.aliases is None: child_opts.aliases = [ Alias(parent=ROOT_STACK_RESOURCE), Alias(parent=ROOT_STACK_RESOURCE) ] super().__init__("my:module:Component4", name, None, child_opts)
def virtual_network(stem, address_spaces): vn = network.VirtualNetwork( f'{stem}-vn-', resource_group_name=resource_group_name, address_spaces=address_spaces, tags=tags, opts=ResourceOptions(parent=self), ) return vn