-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Replicator: support generating specific VPC ids #11772
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
Conversation
LocalStack Community integration with Pro 2 files 2 suites 22s ⏱️ Results for commit 732e393. ♻️ This comment has been updated with latest results. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks pretty good. Glad you were able to make it work! 🚀
I think you are missing out on the power of the generate
method. It does all of the conditional stuff for you!
The fix would probably be better if done in moto, modifying create_vpc
and random_vpc_id
directly. That would allow us to remove a lot of dirty patch work! 🤣 But this can also be tackled in batches once we have progressed more on a service rather than a resource by resource pr. Should we keep a tally?
custom_ids = [tag["Value"] for tag in tags if tag["Key"] == TAG_KEY_CUSTOM_ID] | ||
custom_id = custom_ids[0] if len(custom_ids) > 0 else None | ||
|
||
# try to generate a custom id from the id store | ||
if not custom_id: | ||
resource_identifier = VpcIdentifier(self.account_id, self.region_name, cidr_block) | ||
id = localstack_id_manager.get_custom_id(resource_identifier) | ||
if id: | ||
custom_id = id | ||
|
||
# Check if custom id is unique | ||
if custom_id and custom_id in self.vpcs: | ||
raise InvalidVpcDuplicateCustomIdError(custom_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the generate method will do all the work for you! It also looks at the TAG_KEY_CUSTOM_ID
, and duplicate ids. It will not raise though 🤔 and instead will generate a new id... so maybe you will want to leave that part out?
custom_ids = [tag["Value"] for tag in tags if tag["Key"] == TAG_KEY_CUSTOM_ID] | |
custom_id = custom_ids[0] if len(custom_ids) > 0 else None | |
# try to generate a custom id from the id store | |
if not custom_id: | |
resource_identifier = VpcIdentifier(self.account_id, self.region_name, cidr_block) | |
id = localstack_id_manager.get_custom_id(resource_identifier) | |
if id: | |
custom_id = id | |
# Check if custom id is unique | |
if custom_id and custom_id in self.vpcs: | |
raise InvalidVpcDuplicateCustomIdError(custom_id) | |
resource_identifier = VpcIdentifier(self.account_id, self.region_name, cidr_block) | |
custom_id = resource_identifier.generate(tags=tags, existing_ids=self.vpcs.keys()) |
suffix = "".join(random.choice(string.ascii_letters) for _ in range(17)) | ||
return f"vpc-{suffix}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we could return ""
. And maybe add a comment that moto does the generation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I think @cloutierMat merged recently a PR so moto resource can have the custom id generation. I think this utility is for our LocalStack store resources.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but moto now has its own way to generate a custom Id. I think 🤔
9d566b9
to
2fc8407
Compare
We allow a default fallback for tag_specification as this is not always required
1eaec09
to
732e393
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing the comments. 🚀
Motivation
For the Replicator project, we need the ability to create resources with fixed IDs. VPCs have a random ID that is not an input parameter on creation. E.g. `vpc-abcdefg0123456789'. We need the ability to generate knwon ids using the ID store.
Changes