* fix(autoscaling): tag member instances with aws:autoscaling:groupName
Auto Scaling adds the aws:autoscaling:groupName tag, valued with the
group's name, to every instance it launches or attaches, and removes it
when the instance is detached. Floci never set it, so filtering EC2
instances on tag:aws:autoscaling:groupName found none of a group's
members.
- Launches add the tag after the launch template's instance tags and the
group's PropagateAtLaunch tags, so the group's actual name wins over
any stored tag with that key.
- AttachInstances applies the group's PropagateAtLaunch tags and the
group-name tag to the instances EC2 holds. It refuses the whole batch
with ValidationError when an instance already belongs to a group, so
one group cannot overwrite another group's tag, and an instance named
twice in one request joins once. An ID EC2 has no instance for still
joins, as before, but gets no tags, which would otherwise outlive it
in EC2's DescribeTags.
- DetachInstances removes only the group-name tag, and only where it
still names that group. It goes through a new service-owned EC2 tag
delete, because the public DeleteTags refuses aws: keys.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* test(compat): cover the Auto Scaling group-name tag through the SDK
Drives launch, attach, a refused second attach and detach with the AWS
SDK for Java and checks the instance tags EC2 reports after each step.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
---------
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
Honor group preferences and inherited targets in the shared launch path. Preserve failed launch state, limit fallback to capacity shortages, and validate all supplied numeric Query target members. Reuse existing SDK coverage.
Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
* fix(autoscaling): honor launch configuration metadata options
CreateLaunchConfiguration ignored MetadataOptions, so
DescribeLaunchConfigurations never returned them and every instance
launched from the configuration got EC2's defaults, HttpTokens=optional
included.
- The Query handler and the AWS::AutoScaling::LaunchConfiguration
provisioner read the structure, validate it as EC2 does
(ValidationError for a value outside the allowed set or range) and
store it. CloudFormation resolves Fn::If and AWS::NoValue inside it.
- DescribeLaunchConfigurations returns the structure with defaults for
the members left out, and omits it when it was never given.
- The reconciler passes it to every launch, instance refresh
replacements included.
- Auto Scaling launches from a launch template, directly or through a
mixed instances policy, and CreateFleet forward the template's
metadata options, which they dropped before.
Split out of #5671 at review.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* test(autoscaling): clean up after the launch configuration metadata tests
The metadata tests now delete the groups, launch configurations and
stacks they create, so later reconcileAll calls in the shared test
application stop reconciling leaked groups. They build their
Authorization headers with EnforcementFixtures.auth, and the case that
expects no MetadataOptions first checks that the launch configuration
was found.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* fix(autoscaling): word metadata option errors as Auto Scaling does
CreateLaunchConfiguration refused bad MetadataOptions with EC2's
InvalidParameterValue text under a ValidationError code. It now answers
with Auto Scaling's model-validation text, for example "1 validation
error detected: Value '65' at 'metadataOptions.httpPutResponseHopLimit'
failed to satisfy constraint: Member must have value less than or equal
to 64", and reports every invalid member of the structure in one
error, "N validation errors detected: ...; ...". EC2's validator is no
longer shared.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* fix(cloudformation): refuse list or object launch configuration metadata members
A MetadataOptions member given as a list or an object, such as
HttpTokens: [required], read as an empty string and so as absent: the
launch configuration was created with that member at its default,
HttpTokens=optional included. Such a member now fails the resource with
ValidationError, as the whole structure already does when it is not an
object.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* test(autoscaling): cover every metadata member in the combined error
The test that sends several invalid MetadataOptions members now makes
all three invalid, so the position of HttpEndpoint in the combined
ValidationError is checked, and confirms that no launch configuration
was created.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* fix(cloudformation): report metadata type errors as CloudFormation does
A launch configuration MetadataOptions block or member of the wrong
JSON type failed with wording Floci made up, such as "HttpTokens must
be a string.". It now fails with CloudFormation's schema type error, as
the S3 and DynamoDB provisioners already report it, for example "Model
validation failed (#/MetadataOptions/HttpTokens: expected type: String,
found: JSONArray)". A value of the right type that Auto Scaling rejects
keeps Auto Scaling's ValidationError.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* fix(cloudformation): report an oversized metadata hop limit as out of range
A whole-number HttpPutResponseHopLimit too large for an int, such as
2147483648, failed with the contradictory "expected type: Integer,
found: Integer". It is an integer outside 1 to 64, so it now fails with
the same Auto Scaling ValidationError text as 65 or 0, with the value
as written.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* fix(cloudformation): count an oversized hop limit with the other metadata errors
An oversized CloudFormation HttpPutResponseHopLimit was refused before
the other MetadataOptions members were checked, so an invalid
HttpTokens beside it went unreported, and the value was echoed as
written, "+002147483648" included. Auto Scaling now builds the whole
error from the options and the hop limit as a BigInteger, so the
oversized value is counted with every other violation and printed as
a plain number.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* refactor(autoscaling): build metadata option errors through SmithyValidationErrors
The launch configuration MetadataOptions validator assembled its "N
validation errors detected" message by hand. It now uses
SmithyValidationErrors, which main adopted for Auto Scaling's other
checks. The error code and text are unchanged.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* fix(cloudformation): read launch configuration metadata through CfnPropertyTypes
The MetadataOptions reader had its own type check and answered every
wrongly typed value with the handler's "Model validation failed"
message. It now reads the block through CfnPropertyTypes, as the Events
and Lambda provisioners do:
- a value of the wrong type fails template validation first, for
example "Property [HttpTokens] expected type: String, found:
JSONArray", and a hop limit of 4.5 is "found: Float";
- a hop limit beyond 32 bits fails the handler's model validation,
before Auto Scaling's own check runs;
- a number or a boolean given for a string member arrives at Auto
Scaling as its text, as CloudFormation converts it, and fails its
enum check there.
The hand-written type helpers go away.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* refactor(autoscaling): fold the metadata options error back into its validator
The public metadataOptionsError took the hop limit as a BigInteger so
that CloudFormation could report a value beyond 32 bits through it.
CloudFormation now refuses such a value in model validation, before
Auto Scaling, so the helper goes back to a private validator over the
Integer field. The error code and text are unchanged.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* test(ec2): delete the launch template the metadata test creates
Ec2LaunchTemplateMetadataOptionsIntegrationTest never deleted its
launch template, and its cleanup began only after the fleet or group
had launched, so an earlier failure left everything behind. Everything
after the template is created now runs in the try block, and the
finally block removes the group or the instance and then the template,
ignoring the status so a test's own failure is kept.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* fix(ec2): check template metadata options before a CreateFleet dry run
A launch template stores its metadata options unchecked, as AWS does,
so they fail at launch. CreateFleet forwards them to the launch since
this branch, but a dry run returned DryRunOperation before any launch
ran, saying a fleet would succeed that then fails with
InvalidParameterValue. CreateFleet now checks every launch's metadata
options with the rest of its pre-launch checks, as RunInstances does
before honoring DryRun.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* test(autoscaling): pin the Query answer for a hop limit beyond 32 bits
CreateLaunchConfiguration with MetadataOptions.HttpPutResponseHopLimit=
2147483648 answers MalformedInput, as for any value that is not a
32-bit integer: the awsQuery protocol binds the member before model
validation runs. A row now covers it beside the non-numeric case.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
---------
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* fix(ec2): preserve IAM instance profile identity
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* fix(ec2): probe metadata readiness with IMDSv2
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* fix(autoscaling): preserve launch profiles and metadata options
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* fix(ec2): preserve automatic public addresses across launch paths
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* fix(ec2): honor metadata token requirements and profile identity
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* fix(ec2): keep synthesized node identity and mock addresses consistent
- IMDS iam/info serves the instance profile identity EKS synthesizes for
its cluster nodes while IAM holds no such profile. The node carries a
stable IAM-shaped profile id, which DescribeInstances now copies too.
- Mock instances get their automatic public address however the launch
completes, DescribeInstanceStatus included. An associated Elastic IP
replaces it, disassociating gives a running instance a new one, and
termination leaves none.
- CreateFleet forwards the launch template's metadata options and its
primary interface AssociatePublicIpAddress.
- Launch templates store a profile name and ARN pair as given and the
launch from them rejects it, since AWS does not fully validate
template parameters at creation.
- CloudFormation launch-configuration MetadataOptions resolve Fn::If and
AWS::NoValue.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* fix(ec2): refuse profile pairs for groups and keep Elastic IPs exclusive
- Auto Scaling refuses a group whose launch template, directly or
through its mixed instances policy, names both an instance profile
name and an ARN, with ValidationError, instead of accepting a group
that can never launch.
- AssociateAddress disassociates the Elastic IP an instance already
has, as AWS documents. In mock mode a terminated instance takes no
address, and an unchanged address is not written again.
- IMDS iam/info falls back to a cluster node's synthesized identity
only while IAM holds no profile at that ARN; a held profile without a
role answers 404.
- CreateFleet takes the subnet of the device-index-0 interface first,
as RunInstances does.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* test(ec2): assert profile ids and launch configuration metadata via the SDK
Ec2InstanceProfilePathTest now checks that direct, template, override
and fleet launches report IAM's InstanceProfileId, and AutoScalingTest
round-trips launch configuration MetadataOptions through the AWS SDK for
Java v2, including the absent structure and a rejected hop limit.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* fix(ec2): displace an Elastic IP a retained interface carries
- AssociateAddress also disassociates an Elastic IP held by the
instance's primary interface, which a retained network interface
carries from an earlier instance, so one instance never holds two.
- Mock stop and terminate change the instance's state and public
address under its lock, like the launch and Elastic IP writes.
- Docs and comments say where the profile pair fails and when
CreateFleet falls back to another interface's subnet.
- Tests cover the retained-interface address, the group update path,
the full refusal message and the fleet's availability zone, and the
SDK launch configuration test cleans up on failure.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* fix(ec2): refuse reserved RunInstances tags before resolving the profile
Resolving the instance profile called the EC2 service before tag parsing,
so a reserved aws: tag was refused only after that lookup. Parse tags first,
as the reserved-tag check requires.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* test(autoscaling): assert the refresh launched the replacement
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* test(autoscaling): describe what the refresh assertion checks
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* test(cloudformation): cover invalid launch-configuration metadata options
Invalid HttpTokens, invalid HttpEndpoint, hop limits of 0 and 65 and a
non-integer hop limit each fail the AWS::AutoScaling::LaunchConfiguration
resource with the validation message, roll the stack back and leave no
launch configuration behind.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* test(cloudformation): pin metadata failure reasons and accepted hop limits
Assert the exact resource failure reason, and cover hop limits of 1 and 64,
a string hop limit and one from a Number parameter.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* refactor(ec2): leave IMDS token enforcement to a separate change
HttpTokens=required enforcement, the IMDSv2 readiness probe and the helper
shell environment reset move to their own pull request, so this change
keeps only the instance profile identity.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* refactor(ec2): leave mock public addresses to a separate change
Mock public IPv4 assignment, primary-interface public IP and subnet handling
and Elastic IP displacement move to their own pull request.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* refactor(autoscaling): leave launch metadata options to a separate change
Launch-configuration MetadataOptions over Query and CloudFormation, and
metadata options forwarded from launch templates and EC2 Fleet, move to
their own pull request. Launch-configuration profile resolution stays.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* test(ec2): use the shared metadata and authorization fixtures
Ec2MetadataProfileIntegrationTest starts its metadata server and requests
tokens through Ec2MetadataTestFixture, and it and
Ec2InstanceProfileIdentityIntegrationTest build their Authorization header
with EnforcementFixtures.auth.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* docs(ec2): close the Auto Scaling profile paragraph's code fence
Removes a stray fence that rendered the launch-configuration profile
paragraph as code, and a doubled blank line before the iam/info paragraph.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* test(ec2): find profile identity launches by a run tag
Each launch carries a tag unique to the test run, and the tests look their
instances up by that tag rather than by client token.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* refactor(ec2): leave the client-token filter to a separate change
The instance filter is not part of the profile identity, and this copy let
a wildcard match instances launched without a token.
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
---------
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
* feat(autoscaling): implement DescribeTags
DescribeTags returned UnsupportedOperation while CreateOrUpdateTags and
DeleteTags already stored group tags. Serve it from those stored tags:
filters auto-scaling-group, key, value and propagate-at-launch (values
within a filter ORed, filters ANDed, unknown filter names rejected with
ValidationError), MaxRecords/NextToken paging reusing the offset token
DescribeInstanceRefreshes uses, results ordered by group then key.
* fix(autoscaling): reject non-numeric MaxRecords and sparse filter indices in DescribeTags
* fix(autoscaling): harden DescribeTags paging, vanished groups and oversized indices
- rejectIndexGap compares member indices as BigInteger, so an index past
int range is a 400 ValidationError instead of a NumberFormatException 500.
- describeTags skips a null group value (deleted between StorageBackedMap's
key snapshot and value read).
- NextToken is now an opaque cursor on the last (group, key) returned, not
an offset, so tags added or removed between pages are neither skipped
nor repeated.
- Import hamcrest containsString in the integration test.
* fix(autoscaling): sign DescribeTags NextToken and route DescribeTags by Version
A token that decodes to a (group, key) it was never issued for is now
refused with InvalidNextToken, as AWS refuses a token it did not mint:
the cursor carries an HMAC-SHA256 over region and cursor under a
per-process key. DescribeTags joins the autoscaling action set so a
request without a credential scope reaches autoscaling under its
2011-01-01 Version instead of ec2.
* fix(autoscaling): bind DescribeTags NextToken to the account; per-instance HMAC key
A static SecureRandom key can be initialized at native-image build time and
baked into every process; hold it on the ApplicationScoped bean instead. The
MAC now covers the caller's account id, so a token issued under one account
is InvalidNextToken under another.
* fix(autoscaling): draw the DescribeTags cursor key with nextBytes, not generateSeed
* fix(autoscaling): AND repeated DescribeTags filters of the same name
Each Filters.member entry is now its own filter, so two 'key' filters
must both match instead of being merged into one ORed value list, per
the Filter shape: multiple filters are joined with AND.
Also cover a NextToken whose own cursor tag is deleted between pages.
* fix(autoscaling): page DescribeTags through core Pagination, read filters to first gap
Per review: the NextToken is now a (group, key) cursor through
core.common.Pagination with a namespace and InvalidNextToken, replacing
the HMAC, per-instance key and account binding (groups are stored per
account, and the per-instance key voided every token on restart).
rejectIndexGap is gone; filters are read up to the first missing index
like every other member list in the handler. propagate-at-launch values
match exactly, as the Filter model says values are case-sensitive.
* fix(autoscaling): round-trip InstanceMaintenancePolicy, AvailabilityZoneDistribution, CapacityReservationSpecification, ServiceLinkedRoleARN, WeightedCapacity and EnabledMetrics
DescribeAutoScalingGroups dropped several members of the AutoScalingGroup shape
that CreateAutoScalingGroup and UpdateAutoScalingGroup accept, so a client that
set them read them back as absent and saw a permanent diff.
- AsgOptionalFields gains ServiceLinkedRoleARN, InstanceMaintenancePolicy,
AvailabilityZoneDistribution and CapacityReservationSpecification with its
CapacityReservationTarget. The four-argument constructor stays, so existing
call sites are unchanged.
- MixedInstancesPolicy launch template overrides carry WeightedCapacity.
- EnableMetricsCollection and DisableMetricsCollection are implemented, and
DescribeAutoScalingGroups reports EnabledMetrics.
- Validation follows the botocore model. MinHealthyPercentage 0 to 100 and
MaxHealthyPercentage 100 to 200, both required, at most 100 apart, and -1
on both clears the policy. CapacityDistributionStrategy and
CapacityReservationPreference enums. No target with preference none.
CapacityReservationIds 1 to 255 characters matching [A-Za-z0-9-_/] and
resource group ARNs 1 to 1600. ServiceLinkedRoleARN 1 to 1600 characters.
WeightedCapacity 1 to 999 in at most 32 characters, set on every override
or none. Granularity required and 1Minute. Known metric names only.
- The AWS::AutoScaling::AutoScalingGroup provisioner passes the new properties
and MetricsCollection through, and its update rollback snapshot restores
them. It requires CapacityReservationPreference and each entry's
Granularity as the resource schema does, and rejects an unknown metric
before creating the group.
- The Java SDK compatibility suite gains a round-trip case that sets every
new member, reads it back through DescribeAutoScalingGroups, then clears
the maintenance policy and the enabled metrics.
* fix(autoscaling): route the metrics collection actions and close the review gaps
EnableMetricsCollection and DisableMetricsCollection now route to Auto
Scaling when a request carries no credential scope. Both hold the group
lock, so concurrent calls keep each other's changes and a call racing a
delete cannot write the group back.
A failed stack update now clears the service-linked role, AZ
distribution and capacity reservation when the group had none before.
A blank ServiceLinkedRoleARN or WeightedCapacity in a template reaches
the service's validation instead of reading as unset. The provisioner
reuses the service's granularity rule and message.
* fix(autoscaling): round-trip the dropped Auto Scaling group fields
CreateAutoScalingGroup and UpdateAutoScalingGroup accepted DesiredCapacityType,
CapacityRebalance, MaxInstanceLifetime and DefaultInstanceWarmup and threw them
away, so DescribeAutoScalingGroups never read them back. A mixed instances policy
launch template override that selected instance types by InstanceRequirements
instead of by name was dropped the same way, and because the override parser used
InstanceType's presence as its only "is there another override" signal, such an
override also truncated the whole Overrides list.
The four scalar members now travel into AutoScalingService as one AsgOptionalFields
record and are stored on AutoScalingGroup as boxed, uninitialised fields, so a group
that never set one omits it from the Describe response rather than reporting a
default. Update keeps its partial-update semantics: an absent member leaves the
stored value alone. DefaultInstanceWarmup honours the documented -1 removal
sentinel, MaxInstanceLifetime must be 0 or at least 86400, and DesiredCapacityType
is checked against units, vcpu and memory-mib.
LaunchTemplateOverrides.InstanceRequirements parses and echoes every member of the
botocore shape except BaselinePerformanceFactors, and an override that sets both
InstanceType and InstanceRequirements raises ValidationError as AWS does.
Verified against botocore autoscaling/2011-01-01/service-2.json from awscli 2.35.24.
* fix(autoscaling): enforce the attribute-based instance selection rules
Two rules that botocore states but does not encode as constraints were missing.
DesiredCapacityType is typed XmlStringMaxLen255 with no enum, and
CreateAutoScalingGroupType.members.DesiredCapacityType.documentation carries the
rule: "Amazon EC2 Auto Scaling supports DesiredCapacityType for attribute-based
instance type selection only." Floci accepted vcpu and memory-mib for a group
whose launch template names a fixed instance type. Both values now raise
ValidationError unless the mixed instances policy left in effect by the request
carries a launch template override with a non-empty InstanceRequirements. units
is the documented default and stays legal everywhere, and an absent member is
not validated.
The effective policy is the one the request supplies on create. On update it is
the policy the request supplies, the stored policy when the request names no
launch source, or none when the request switches the group to a launch
configuration or a plain launch template. The effective DesiredCapacityType is
likewise the request value or, when absent, the stored one, so an update cannot
strip attribute-based selection out from under a stored vcpu.
shapes.InstanceRequirements.required is ["VCpuCount", "MemoryMiB"] and the shape
documentation repeats it as "You must specify VCpuCount and MemoryMiB". An
override carrying InstanceRequirements without both ranges was stored and
returned 200; it now raises ValidationError. Both rules run on create and on
update.
createGroupCarryingEveryOptionalField is @Order(1) and seeds the group the later
ordered tests reuse, so its setup moved from a launch template naming t3.micro
to a mixed instances policy whose override sets VCpuCount and MemoryMiB. That
makes its DesiredCapacityType=vcpu legal without relaxing any assertion, and the
ordered updates that follow still see attribute-based selection in effect.
CreateLaunchConfiguration stores InstanceMonitoring.Enabled and
BlockDeviceMappings, and DescribeLaunchConfigurations returns both
structures the way AWS does, with monitoring defaulting to enabled and
mappings to an empty list. The Terraform provider read the missing
elements as disabled monitoring and no root device, which forced a
replacement on every plan.
Ported from lex00/floci#132.
* feat(autoscaling): warm pools, scheduled actions, traffic sources, and process suspension
PutWarmPool/DescribeWarmPool/DeleteWarmPool, PutScheduledUpdateGroupAction/
DescribeScheduledActions/DeleteScheduledAction, AttachTrafficSources/
DetachTrafficSources/DescribeTrafficSources, and SuspendProcesses/
ResumeProcesses, parsed against botocore's autoscaling/2011-01-01 wire model.
Deleting a group also removes its scheduled actions and warm pool.
* fix(autoscaling): scope scheduled-action cleanup to the group's region
Deleting a group removed scheduled actions with the same group name in every region. PutScheduledUpdateGroupAction now rejects a malformed StartTime or EndTime with ValidationError instead of treating it as absent.