Update TF to latest (#5266)
This commit is contained in:
parent
6cf37c4b4b
commit
2364b7770f
@ -149,6 +149,10 @@ class FakeLaunchConfiguration(CloudFormationModel):
|
||||
self.spot_price = spot_price
|
||||
self.ebs_optimized = ebs_optimized
|
||||
self.associate_public_ip_address = associate_public_ip_address
|
||||
if isinstance(associate_public_ip_address, str):
|
||||
self.associate_public_ip_address = (
|
||||
associate_public_ip_address.lower() == "true"
|
||||
)
|
||||
self.block_device_mapping_dict = block_device_mapping_dict
|
||||
self.metadata_options = metadata_options
|
||||
self.classic_link_vpc_id = classic_link_vpc_id
|
||||
@ -323,7 +327,7 @@ class FakeAutoScalingGroup(CloudFormationModel):
|
||||
self.load_balancers = load_balancers
|
||||
self.target_group_arns = target_group_arns
|
||||
self.placement_group = placement_group
|
||||
self.termination_policies = termination_policies
|
||||
self.termination_policies = termination_policies or ["Default"]
|
||||
self.new_instances_protected_from_scale_in = (
|
||||
new_instances_protected_from_scale_in
|
||||
)
|
||||
@ -333,6 +337,8 @@ class FakeAutoScalingGroup(CloudFormationModel):
|
||||
self.tags = tags or []
|
||||
self.set_desired_capacity(desired_capacity)
|
||||
|
||||
self.metrics = []
|
||||
|
||||
@property
|
||||
def tags(self):
|
||||
return self._tags
|
||||
@ -624,6 +630,17 @@ class FakeAutoScalingGroup(CloudFormationModel):
|
||||
def replace_autoscaling_group_instances(self, count_needed, propagated_tags):
|
||||
propagated_tags[ASG_NAME_TAG] = self.name
|
||||
|
||||
# VPCZoneIdentifier:
|
||||
# A comma-separated list of subnet IDs for a virtual private cloud (VPC) where instances in the Auto Scaling group can be created.
|
||||
# We'll create all instances in a single subnet to make things easier
|
||||
subnet_id = (
|
||||
self.vpc_zone_identifier.split(",")[0] if self.vpc_zone_identifier else None
|
||||
)
|
||||
associate_public_ip = (
|
||||
self.launch_config.associate_public_ip_address
|
||||
if self.launch_config
|
||||
else None
|
||||
)
|
||||
reservation = self.autoscaling_backend.ec2_backend.add_instances(
|
||||
self.image_id,
|
||||
count_needed,
|
||||
@ -634,6 +651,8 @@ class FakeAutoScalingGroup(CloudFormationModel):
|
||||
placement=random.choice(self.availability_zones),
|
||||
launch_config=self.launch_config,
|
||||
is_instance_type_default=False,
|
||||
associate_public_ip=associate_public_ip,
|
||||
subnet_id=subnet_id,
|
||||
)
|
||||
for instance in reservation.instances:
|
||||
instance.autoscaling_group = self
|
||||
@ -648,6 +667,9 @@ class FakeAutoScalingGroup(CloudFormationModel):
|
||||
append = [x for x in target_group_arns if x not in self.target_group_arns]
|
||||
self.target_group_arns.extend(append)
|
||||
|
||||
def enable_metrics_collection(self, metrics):
|
||||
self.metrics = metrics or []
|
||||
|
||||
|
||||
class AutoScalingBackend(BaseBackend):
|
||||
def __init__(self, region_name, account_id):
|
||||
@ -859,7 +881,7 @@ class AutoScalingBackend(BaseBackend):
|
||||
)
|
||||
return group
|
||||
|
||||
def describe_auto_scaling_groups(self, names):
|
||||
def describe_auto_scaling_groups(self, names) -> [FakeAutoScalingGroup]:
|
||||
groups = self.autoscaling_groups.values()
|
||||
if names:
|
||||
return [group for group in groups if group.name in names]
|
||||
@ -1267,5 +1289,9 @@ class AutoScalingBackend(BaseBackend):
|
||||
]
|
||||
return tags
|
||||
|
||||
def enable_metrics_collection(self, group_name, metrics):
|
||||
group = self.describe_auto_scaling_groups([group_name])[0]
|
||||
group.enable_metrics_collection(metrics)
|
||||
|
||||
|
||||
autoscaling_backends = BackendDict(AutoScalingBackend, "autoscaling")
|
||||
|
@ -439,6 +439,13 @@ class AutoScalingResponse(BaseResponse):
|
||||
template = self.response_template(DESCRIBE_TAGS_TEMPLATE)
|
||||
return template.render(tags=tags, next_token=None)
|
||||
|
||||
def enable_metrics_collection(self):
|
||||
group_name = self._get_param("AutoScalingGroupName")
|
||||
metrics = self._get_params().get("Metrics")
|
||||
self.autoscaling_backend.enable_metrics_collection(group_name, metrics)
|
||||
template = self.response_template(ENABLE_METRICS_COLLECTION_TEMPLATE)
|
||||
return template.render()
|
||||
|
||||
|
||||
CREATE_LAUNCH_CONFIGURATION_TEMPLATE = """<CreateLaunchConfigurationResponse xmlns="http://autoscaling.amazonaws.com/doc/2011-01-01/">
|
||||
<ResponseMetadata>
|
||||
@ -666,7 +673,6 @@ DESCRIBE_AUTOSCALING_GROUPS_TEMPLATE = """<DescribeAutoScalingGroupsResponse xml
|
||||
<AutoScalingGroupName>{{ group.name }}</AutoScalingGroupName>
|
||||
<HealthCheckType>{{ group.health_check_type }}</HealthCheckType>
|
||||
<CreatedTime>2013-05-06T17:47:15.107Z</CreatedTime>
|
||||
<EnabledMetrics/>
|
||||
{% if group.launch_config_name %}
|
||||
<LaunchConfigurationName>{{ group.launch_config_name }}</LaunchConfigurationName>
|
||||
{% elif group.launch_template %}
|
||||
@ -744,6 +750,16 @@ DESCRIBE_AUTOSCALING_GROUPS_TEMPLATE = """<DescribeAutoScalingGroupsResponse xml
|
||||
<PlacementGroup>{{ group.placement_group }}</PlacementGroup>
|
||||
{% endif %}
|
||||
<NewInstancesProtectedFromScaleIn>{{ group.new_instances_protected_from_scale_in|string|lower }}</NewInstancesProtectedFromScaleIn>
|
||||
{% if group.metrics %}
|
||||
<EnabledMetrics>
|
||||
{% for met in group.metrics %}
|
||||
<member>
|
||||
<Metric>{{ met }}</Metric>
|
||||
<Granularity>1Minute</Granularity>
|
||||
</member>
|
||||
{% endfor %}
|
||||
</EnabledMetrics>
|
||||
{% endif %}
|
||||
</member>
|
||||
{% endfor %}
|
||||
</AutoScalingGroups>
|
||||
@ -1219,3 +1235,10 @@ DESCRIBE_TAGS_TEMPLATE = """<DescribeTagsResponse xmlns="http://autoscaling.amaz
|
||||
{% endif %}
|
||||
</DescribeTagsResult>
|
||||
</DescribeTagsResponse>"""
|
||||
|
||||
|
||||
ENABLE_METRICS_COLLECTION_TEMPLATE = """<EnableMetricsCollectionResponse xmlns="http://autoscaling.amazonaws.com/doc/2011-01-01/">
|
||||
<ResponseMetadata>
|
||||
<RequestId></RequestId>
|
||||
</ResponseMetadata>
|
||||
</EnableMetricsCollectionResponse>"""
|
||||
|
@ -62,6 +62,7 @@ class Instance(TaggedEC2Resource, BotoInstance, CloudFormationModel):
|
||||
"groupSet",
|
||||
"ebsOptimized",
|
||||
"sriovNetSupport",
|
||||
"disableApiStop",
|
||||
}
|
||||
|
||||
def __init__(self, ec2_backend, image_id, user_data, security_groups, **kwargs):
|
||||
@ -134,6 +135,7 @@ class Instance(TaggedEC2Resource, BotoInstance, CloudFormationModel):
|
||||
self.virtualization_type = ami.virtualization_type if ami else "paravirtual"
|
||||
self.architecture = ami.architecture if ami else "x86_64"
|
||||
self.root_device_name = ami.root_device_name if ami else None
|
||||
self.disable_api_stop = False
|
||||
|
||||
# handle weird bug around user_data -- something grabs the repr(), so
|
||||
# it must be clean
|
||||
@ -543,7 +545,7 @@ class InstanceBackend:
|
||||
def __init__(self):
|
||||
self.reservations = OrderedDict()
|
||||
|
||||
def get_instance(self, instance_id):
|
||||
def get_instance(self, instance_id) -> Instance:
|
||||
for instance in self.all_instances():
|
||||
if instance.id == instance_id:
|
||||
return instance
|
||||
|
@ -1,26 +1,26 @@
|
||||
From ca8880871b241df7bdc9ea3cf0d13f816e815f16 Mon Sep 17 00:00:00 2001
|
||||
From 64093955e96cff42a797880b4a6921663af6040d Mon Sep 17 00:00:00 2001
|
||||
From: Bert Blommers <info@bertblommers.nl>
|
||||
Date: Wed, 13 Apr 2022 12:33:25 +0000
|
||||
Subject: [PATCH] Patch: Hardcode endpoints to local server
|
||||
Date: Sun, 19 Jun 2022 19:32:26 +0000
|
||||
Subject: [PATCH] Patch: Hardcode endpoints
|
||||
|
||||
---
|
||||
internal/conns/conns.go | 14 ++++++++++++++
|
||||
internal/conns/config.go | 15 +++++++++++++++
|
||||
internal/provider/provider.go | 2 +-
|
||||
2 files changed, 15 insertions(+), 1 deletion(-)
|
||||
2 files changed, 16 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/internal/conns/conns.go b/internal/conns/conns.go
|
||||
index 1feb0be2f1..9ed8a64776 100644
|
||||
--- a/internal/conns/conns.go
|
||||
+++ b/internal/conns/conns.go
|
||||
@@ -628,6 +628,16 @@ func (client *AWSClient) RegionalHostname(prefix string) string {
|
||||
return fmt.Sprintf("%s.%s.%s", prefix, client.Region, client.DNSSuffix)
|
||||
diff --git a/internal/conns/config.go b/internal/conns/config.go
|
||||
index 7bfd3100fd..b59083068a 100644
|
||||
--- a/internal/conns/config.go
|
||||
+++ b/internal/conns/config.go
|
||||
@@ -78,8 +78,23 @@ type Config struct {
|
||||
UseFIPSEndpoint bool
|
||||
}
|
||||
|
||||
|
||||
+// XXX: added by bblommers
|
||||
+func GetLocalEndpoints() map[string]string {
|
||||
+ const localEndpoint = "http://localhost:4566"
|
||||
+ var localEndpoints = map[string]string{}
|
||||
+ for _, name := range names.HCLKeys() {
|
||||
+ for _, name := range names.Aliases() {
|
||||
+ localEndpoints[name] = localEndpoint
|
||||
+ }
|
||||
+ return localEndpoints
|
||||
@ -28,23 +28,19 @@ index 1feb0be2f1..9ed8a64776 100644
|
||||
+
|
||||
// Client configures and returns a fully initialized AWSClient
|
||||
func (c *Config) Client(ctx context.Context) (interface{}, diag.Diagnostics) {
|
||||
awsbaseConfig := awsbase.Config{
|
||||
@@ -727,6 +737,10 @@ func (c *Config) Client(ctx context.Context) (interface{}, diag.Diagnostics) {
|
||||
DNSSuffix = p.DNSSuffix()
|
||||
}
|
||||
|
||||
+ // XXX: added by bblommers
|
||||
+ // insert custom endpoints
|
||||
+ c.Endpoints = GetLocalEndpoints()
|
||||
+
|
||||
client := &AWSClient{
|
||||
AccessAnalyzerConn: accessanalyzer.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints[names.AccessAnalyzer])})),
|
||||
AccountConn: account.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints[names.Account])})),
|
||||
+ // XXX: added by bblommers
|
||||
+ // insert custom endpoints
|
||||
+ c.Endpoints = GetLocalEndpoints()
|
||||
+
|
||||
awsbaseConfig := awsbase.Config{
|
||||
AccessKey: c.AccessKey,
|
||||
APNInfo: StdUserAgentProducts(c.TerraformVersion),
|
||||
diff --git a/internal/provider/provider.go b/internal/provider/provider.go
|
||||
index df93e4b5c5..da009a9e4c 100644
|
||||
index 7e6200d9ac..7005caccd3 100644
|
||||
--- a/internal/provider/provider.go
|
||||
+++ b/internal/provider/provider.go
|
||||
@@ -2011,7 +2011,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData, terraformVer
|
||||
@@ -2082,7 +2082,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData, terraformVer
|
||||
CustomCABundle: d.Get("custom_ca_bundle").(string),
|
||||
EC2MetadataServiceEndpoint: d.Get("ec2_metadata_service_endpoint").(string),
|
||||
EC2MetadataServiceEndpointMode: d.Get("ec2_metadata_service_endpoint_mode").(string),
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,23 +1,23 @@
|
||||
From 211ea82c418b51a35b94b1e3ded0d689b4434863 Mon Sep 17 00:00:00 2001
|
||||
From e356afa8e19d90c7e343120897f4385d616ae9d2 Mon Sep 17 00:00:00 2001
|
||||
From: Bert Blommers <info@bertblommers.nl>
|
||||
Date: Fri, 15 Apr 2022 19:22:04 +0000
|
||||
Subject: [PATCH] Patch IAM wait times
|
||||
Date: Sun, 19 Jun 2022 19:39:31 +0000
|
||||
Subject: [PATCH] IAM: Reduce wait times
|
||||
|
||||
---
|
||||
internal/service/iam/wait.go | 4 ++--
|
||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/internal/service/iam/wait.go b/internal/service/iam/wait.go
|
||||
index 51e5d1c9c7..057446ae1d 100644
|
||||
index 705d88d664..527f4fa9b8 100644
|
||||
--- a/internal/service/iam/wait.go
|
||||
+++ b/internal/service/iam/wait.go
|
||||
@@ -17,7 +17,7 @@ const (
|
||||
// as this will negatively impact user experience when configurations
|
||||
// have incorrect references or permissions.
|
||||
// Reference: https://docs.aws.amazon.com/IAM/latest/UserGuide/troubleshoot_general.html#troubleshoot_general_eventual-consistency
|
||||
- PropagationTimeout = 2 * time.Minute
|
||||
+ PropagationTimeout = 2 * time.Second
|
||||
|
||||
- propagationTimeout = 2 * time.Minute
|
||||
+ propagationTimeout = 2 * time.Second
|
||||
|
||||
RoleStatusARNIsUniqueID = "uniqueid"
|
||||
RoleStatusARNIsARN = "arn"
|
||||
@@ -72,7 +72,7 @@ func waitDeleteServiceLinkedRole(conn *iam.IAM, deletionTaskID string) error {
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit f34a786a6672e5629456a523e2b74cc4d368db45
|
||||
Subproject commit 3c1f58b59a45aaecc9a4b243d5b1004283b3353b
|
@ -130,7 +130,8 @@ lambda:
|
||||
meta:
|
||||
- TestAccMetaBillingServiceAccountDataSource
|
||||
mq:
|
||||
- TestAccMQBroker
|
||||
- TestAccMQBrokerDataSource
|
||||
- TestAccMQBroker_
|
||||
quicksight:
|
||||
- TestAccQuickSightUser
|
||||
redshift:
|
||||
|
@ -150,7 +150,7 @@ def test_create_autoscaling_groups_defaults():
|
||||
group["HealthCheckType"].should.equal("EC2")
|
||||
group["LoadBalancerNames"].should.equal([])
|
||||
group.shouldnt.have.key("PlacementGroup")
|
||||
group["TerminationPolicies"].should.equal([])
|
||||
group["TerminationPolicies"].should.equal(["Default"])
|
||||
group["Tags"].should.equal([])
|
||||
|
||||
|
||||
|
49
tests/test_autoscaling/test_autoscaling_metrics.py
Normal file
49
tests/test_autoscaling/test_autoscaling_metrics.py
Normal file
@ -0,0 +1,49 @@
|
||||
import boto3
|
||||
import sure # noqa # pylint: disable=unused-import
|
||||
|
||||
from moto import mock_autoscaling, mock_elb, mock_ec2
|
||||
|
||||
from .utils import setup_networking
|
||||
from tests import EXAMPLE_AMI_ID
|
||||
|
||||
|
||||
@mock_autoscaling
|
||||
@mock_ec2
|
||||
@mock_elb
|
||||
def test_enable_metrics_collection():
|
||||
mocked_networking = setup_networking()
|
||||
elb_client = boto3.client("elb", region_name="us-east-1")
|
||||
elb_client.create_load_balancer(
|
||||
LoadBalancerName="test_lb",
|
||||
Listeners=[{"Protocol": "http", "LoadBalancerPort": 80, "InstancePort": 8080}],
|
||||
AvailabilityZones=[],
|
||||
)
|
||||
|
||||
as_client = boto3.client("autoscaling", region_name="us-east-1")
|
||||
as_client.create_launch_configuration(
|
||||
LaunchConfigurationName="tester_config",
|
||||
ImageId=EXAMPLE_AMI_ID,
|
||||
InstanceType="t2.medium",
|
||||
)
|
||||
|
||||
as_client.create_auto_scaling_group(
|
||||
AutoScalingGroupName="tester_group",
|
||||
LaunchConfigurationName="tester_config",
|
||||
MinSize=2,
|
||||
MaxSize=2,
|
||||
VPCZoneIdentifier=mocked_networking["subnet1"],
|
||||
)
|
||||
|
||||
as_client.enable_metrics_collection(
|
||||
AutoScalingGroupName="tester_group",
|
||||
Metrics=["GroupMinSize"],
|
||||
Granularity="1Minute",
|
||||
)
|
||||
|
||||
resp = as_client.describe_auto_scaling_groups(
|
||||
AutoScalingGroupNames=["tester_group"]
|
||||
)["AutoScalingGroups"][0]
|
||||
resp.should.have.key("EnabledMetrics").length_of(1)
|
||||
resp["EnabledMetrics"][0].should.equal(
|
||||
{"Metric": "GroupMinSize", "Granularity": "1Minute"}
|
||||
)
|
@ -136,6 +136,46 @@ def test_create_launch_configuration_additional_parameters():
|
||||
)
|
||||
|
||||
|
||||
@mock_autoscaling
|
||||
@mock_ec2
|
||||
def test_create_launch_configuration_without_public_ip():
|
||||
ec2 = boto3.resource("ec2", "us-east-1")
|
||||
vpc = ec2.create_vpc(CidrBlock="10.0.0.0/16")
|
||||
subnet = ec2.create_subnet(VpcId=vpc.id, CidrBlock="10.0.0.0/27")
|
||||
|
||||
ec2_client = boto3.client("ec2", region_name="us-east-1")
|
||||
random_image_id = ec2_client.describe_images()["Images"][0]["ImageId"]
|
||||
|
||||
client = boto3.client("autoscaling", region_name="us-east-1")
|
||||
client.create_launch_configuration(
|
||||
LaunchConfigurationName="tester",
|
||||
ImageId=EXAMPLE_AMI_ID,
|
||||
InstanceType="t1.micro",
|
||||
AssociatePublicIpAddress=False,
|
||||
)
|
||||
|
||||
launch_config = client.describe_launch_configurations()["LaunchConfigurations"][0]
|
||||
launch_config["AssociatePublicIpAddress"].should.equal(False)
|
||||
|
||||
asg_name = f"asg-{random_image_id}"
|
||||
client.create_auto_scaling_group(
|
||||
AutoScalingGroupName=asg_name,
|
||||
LaunchConfigurationName=launch_config["LaunchConfigurationName"],
|
||||
MinSize=1,
|
||||
MaxSize=1,
|
||||
DesiredCapacity=1,
|
||||
VPCZoneIdentifier=subnet.id,
|
||||
)
|
||||
|
||||
instances = client.describe_auto_scaling_instances()["AutoScalingInstances"]
|
||||
instance_id = instances[0]["InstanceId"]
|
||||
|
||||
instance = ec2_client.describe_instances(InstanceIds=[instance_id])["Reservations"][
|
||||
0
|
||||
]["Instances"][0]
|
||||
instance.shouldnt.have.key("PublicIpAddress")
|
||||
|
||||
|
||||
@mock_autoscaling
|
||||
def test_create_launch_configuration_additional_params_default_to_false():
|
||||
client = boto3.client("autoscaling", region_name="us-east-1")
|
||||
|
Loading…
Reference in New Issue
Block a user