Skip to content

Commit

Permalink
Merge pull request #955 from ulidtko/fix/IMDS-tags
Browse files Browse the repository at this point in the history
Add IMDS named tags & ExtendedMeta
  • Loading branch information
endgame committed Aug 14, 2023
2 parents 5461403 + 3fdc493 commit a8f1d24
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lib/amazonka/CHANGELOG.md
Expand Up @@ -14,6 +14,8 @@
Before this fix you had to create an empty credentials file for these methods to work correctly.
- `amazonka`: During logging, do not print bytestrings that have unprintable characters
[\#952](https://github.com/brendanhay/amazonka/pull/952)
- `amazonka`: Support reading values of IMDS metadata tags, add `Metadata.Other` constructor
[\#955](https://github.com/brendanhay/amazonka/pull/955)


## [2.0.0](https://github.com/brendanhay/amazonka/tree/2.0.0)
Expand Down
23 changes: 18 additions & 5 deletions lib/amazonka/src/Amazonka/EC2/Metadata.hs
Expand Up @@ -214,6 +214,12 @@ data Metadata
Spot !Spot
| -- | See: 'Tags'
Tags !Tags
| -- | Any other piece of metadata specified by arbitrary key.
--
-- This is provided for forward compatibility: should there ever appear any gap
-- between a future version of IMDS API and what this library covers,
-- this constructor provides a workaround.
Other !Text
deriving stock (Eq, Ord, Show, Generic)

instance ToText Metadata where
Expand Down Expand Up @@ -252,6 +258,7 @@ instance ToText Metadata where
Services m -> "services/" <> toText m
Spot m -> "spot/" <> toText m
Tags m -> "tags/" <> toText m
Other m -> m

-- | Metadata keys for @autoscaling/*@.
data Autoscaling
Expand Down Expand Up @@ -573,18 +580,24 @@ instance ToText Spot where
SInstanceAction -> "instance-action"
STerminationTime -> "termination-time"

-- | Metadata keys for @tags/*@.
-- | Instance Metadata tags: @tags/instance@, @tags/instance/*@.
--
-- See [these 2 curl examples](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html#instance-metadata-ex-7)
-- in AWSEC2 User Guide.
--
-- Only available if you [explicitly allow access](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html#allow-access-to-tags-in-IMDS)
-- to instance metadata tags.
data Tags
= -- | The instance tags associated with the instance. Only
-- available if you explicitly allow access to tags in instance
-- metadata. For more information, see
-- [Allow access to tags in instance metadata](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html#allow-access-to-tags-in-IMDS).
= -- | The keys of available tags, @\n@-separated, if enabled in instance settings.
Instance
-- | A specific named tag in Instance Metadata, if enabled in instance settings.
| InstanceTag !Text
deriving stock (Eq, Ord, Show, Generic)

instance ToText Tags where
toText = \case
Instance -> "instance"
InstanceTag t -> "instance/" <> t

latest :: Text
latest = "http://169.254.169.254/latest/"
Expand Down

0 comments on commit a8f1d24

Please sign in to comment.