Last active
July 28, 2021 13:20
-
-
Save 1oglop1/dcb258471cd33f572bedf67c63b7fe00 to your computer and use it in GitHub Desktop.
pulumi problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""A Python Pulumi program.""" | |
import enum | |
import pulumi | |
import pulumi_aws.ec2 as ec2 | |
from pulumi import ResourceOptions | |
class Situation(str, enum.Enum): | |
current = "a" | |
expected = "b" | |
def merge_opts_a(child_opts: ResourceOptions, parent_opts: ResourceOptions): | |
return child_opts.merge(parent_opts) | |
def merge_opts_b(child_opts: ResourceOptions, parent_opts: ResourceOptions): | |
return pulumi.ResourceOptions.merge(parent_opts, child_opts) | |
class AnotherComponent(pulumi.ComponentResource): | |
def __init__(self, name, parent_opts: pulumi.ResourceOptions = None): | |
super().__init__( | |
"org:infrastructure:aws:another-resource", | |
f"{name}-component", | |
None, | |
parent_opts, | |
) | |
child_opts = ResourceOptions(parent=self) | |
if SITUATION == Situation.current: | |
merged_opts = merge_opts_a(child_opts, parent_opts) | |
else: | |
merged_opts = merge_opts_b(child_opts, parent_opts) | |
self.sg = ec2.SecurityGroup( | |
"my-sg", | |
opts=merged_opts | |
) | |
class RDSDatabase(pulumi.ComponentResource): | |
def __init__(self, name, security_group: ec2.SecurityGroup, parent_opts: pulumi.ResourceOptions = None): | |
super().__init__( | |
"org:infrastructure:aws:database:RDSDatabase", | |
f"{name}-component", | |
None, | |
parent_opts, | |
) | |
child_opts = ResourceOptions(parent=self) | |
if SITUATION == Situation.current: | |
merged_opts = merge_opts_a(child_opts, parent_opts) | |
else: | |
merged_opts = merge_opts_b(child_opts, parent_opts) | |
ec2.SecurityGroupRule( | |
"some-rule", | |
from_port=123, | |
to_port=123, | |
type="ingress", | |
protocol=ec2.ProtocolType.TCP, | |
cidr_blocks=["0.0.0.0/0"], | |
opts=merged_opts, | |
security_group_id=security_group.id | |
) | |
class AppComponent(pulumi.ComponentResource): | |
def __init__(self, name, parent_opts: pulumi.ResourceOptions = None): | |
super().__init__( | |
"org:infrastructure:aws:app", | |
f"{name}-component", | |
None, | |
parent_opts, | |
) | |
child_opts = ResourceOptions(parent=self) | |
if SITUATION == Situation.current: | |
merged_opts = merge_opts_a(child_opts, parent_opts) | |
else: | |
merged_opts = merge_opts_b(child_opts, parent_opts) | |
self.another = AnotherComponent( | |
f"{name}-another", | |
parent_opts=merged_opts | |
) | |
self.app_db = RDSDatabase( | |
name=f"{name}-db", | |
security_group=self.another.sg, | |
parent_opts=merged_opts | |
) | |
if __name__ == '__main__': | |
# SITUATION = Situation.current | |
SITUATION = Situation.expected | |
app = AppComponent( | |
name='an-app' | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Type Name Plan | |
pulumi:pulumi:Stack tqs-core-core | |
└─ org:infrastructure:aws:app an-app-component | |
├─ org:infrastructure:aws:another-resource an-app-another-component | |
+ │ └─ aws:ec2:SecurityGroup my-sg create | |
├─ org:infrastructure:aws:database:RDSDatabase an-app-db-component | |
+ │ └─ aws:ec2:SecurityGroupRule some-rule create | |
- ├─ aws:ec2:SecurityGroupRule some-rule delete | |
- └─ aws:ec2:SecurityGroup my-sg delete | |
Resources: | |
+ 2 to create | |
- 2 to delete | |
4 changes. 4 unchanged |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment