-
-
Notifications
You must be signed in to change notification settings - Fork 281
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
Automatically populate PropertySource with instance metadata when running within an EC2-based environment #962
base: main
Are you sure you want to change the base?
Conversation
Thanks @kennyk65 for a PR! We need an integration test for that. Until Localstack supports metadata endpoint (localstack/localstack#8911) we would need to mock it - ideally with WireMock, to make sure whole flow works as expected. |
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.
Overall - great stuff! Thanks a lot! While most comments are details, an integration test is a must to merge it.
public void init() { | ||
if (!imdsUtils.isRunningOnCloudEnvironment()) | ||
return; | ||
properties.putAll(imdsUtils.getEc2InstanceMetadata()); |
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.
I'm thinking if there should not be an option to add prefix for properties retrieved with Imds. For example, profile
property can already come from another property source and in such case it would be overwritten.
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.
I thought about that, but wanted to limit the scope for the initial commit. This is my first one and it was starting to get big.
ImdsPropertySource propertySource = new ImdsPropertySource("test", mockUtils); | ||
propertySource.init(); | ||
|
||
assertTrue("Resulting PropertySource should contain the test data", |
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.
not a dealbreaker and i can fix it myself, but we use AssertJ assertions so would be nice if you change it too for sake of consistency.
Co-authored-by: Maciej Walkowiak <walkowiak.maciej@yahoo.com>
…ud-aws into imds-changes
📢 Type of change
📜 Description
A new package added to the autoconfigure project (with test classes) to populate a PropertySource whenever IMDS is present, which occurs on EC2, ElasticBeanstalk, ECS, EKS, etc. Auto configuration silently ignores the absence of IMDS. A starter pom is added, docs are updated.
💡 Motivation and Context
Issue addressed is: #954
There are various times when an application needs to know its IP address, availability zone, region, mac address, etc. All this is available via IMDS. This feature simply adds these properties to the Environment when available.
💚 How did you test it?
Three new classes, three new JUnit tests. Plus I created a sample application using the libraries for a sanity test.
📝 Checklist
🔮 Next steps
Others may wish to expand this to retrieve dynamic data, user data, set a common prefix, etc. May want to use a ConfigProperties only to cause the one and only property to be documented.