Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional resource creation PoC #191

Merged
merged 1 commit into from
Sep 13, 2023
Merged

Conversation

ytsarev
Copy link
Member

@ytsarev ytsarev commented Sep 13, 2023

Description of your changes

Conditional resource creation PoC. Use at your own risk :D

A PoC that uses special condition utilizing the provider-terraform Workspace and proceeds with the execution only when VPC with a special name does not exist in the infrastructure. If it does, it breaks the execution with invalid metadata.name intentionally violating RFC1123.

I have:

  • Run make reviewable to ensure this PR is ready for review.

How has this code been tested

k apply -f xsubnetblocking.yaml
k apply -f xsubnetnotblocking.yaml

 k get managed
NAME                                                           READY   SYNCED   EXTERNAL-NAME              AGE
subnet.ec2.aws.upbound.io/subnet-with-non-blocking-vpc-9z8z7   True    True     subnet-04455565ce8411aca   41m
subnet.ec2.aws.upbound.io/subnet-with-blocking-vpc-2m87z               False                               4m17s

NAME                                              READY   SYNCED   EXTERNAL-NAME           AGE
vpc.ec2.aws.upbound.io/blockmenotnonblockingvpc   True    True     vpc-0778542c8e5d3324b   41m

NAME                                                         READY   SYNCED   AGE
workspace.tf.upbound.io/subnet-with-non-blocking-vpc-rcprv   True    True     41m
workspace.tf.upbound.io/subnet-with-blocking-vpc-xvm8j       True    True     4m17s

 k get xsubnet
NAME                           SYNCED   READY   COMPOSITION                           AGE
subnet-with-non-blocking-vpc   True     True    xsubnets.aws.platformref.upbound.io   42m
subnet-with-blocking-vpc       False    False   xsubnets.aws.platformref.upbound.io   4m51s

k describe xsubnet subnet-with-blocking-vpc

<omitted for brevity>
Status:
  Block:  -block.me
  Conditions:
    Last Transition Time:  2023-09-13T12:12:59Z
    Message:               cannot compose resources: cannot apply composed resource: cannot create object: VPC.ec2.aws.upbound.io "-block.meblockingvpc" is invalid: metadata.name: Invalid value: "-block.meblockingvpc": a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')
    Reason:                ReconcileError

Signed-off-by: Yury Tsarev <yury@upbound.io>
Copy link
Collaborator

@bobh66 bobh66 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely an interesting scenario. It would be nice if AWS would make Name unique and block duplicates at the MR level so this wouldn't be needed. LGTM

@ytsarev ytsarev merged commit 9a22e93 into upbound:main Sep 13, 2023
@ytsarev ytsarev deleted the blockthatdude branch September 13, 2023 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants