|
4 | 4 |
|
5 | 5 | from moto import mock_aws |
6 | 6 | from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID |
| 7 | +from moto.core.types import Base64EncodedString |
7 | 8 | from tests import EXAMPLE_AMI_ID |
8 | 9 |
|
9 | 10 | from .utils import setup_networking |
@@ -363,3 +364,35 @@ def test_launch_template_with_tags(): |
363 | 364 | tags = instances["Reservations"][0]["Instances"][0]["Tags"] |
364 | 365 | assert {"Value": "TestTagValue1", "Key": "TestTagKey1"} in tags |
365 | 366 | assert {"Key": "from_lt", "Value": "val"} in tags |
| 367 | + |
| 368 | + |
| 369 | +@mock_aws |
| 370 | +def test_launch_template_with_user_data(): |
| 371 | + mocked_networking = setup_networking() |
| 372 | + user_data = Base64EncodedString.from_raw_string("test user data") |
| 373 | + ec2_client = boto3.client("ec2", region_name="us-east-1") |
| 374 | + template = ec2_client.create_launch_template( |
| 375 | + LaunchTemplateName="test_launch_template", |
| 376 | + LaunchTemplateData={ |
| 377 | + "ImageId": EXAMPLE_AMI_ID, |
| 378 | + "InstanceType": "t2.micro", |
| 379 | + "UserData": str(user_data), |
| 380 | + }, |
| 381 | + )["LaunchTemplate"] |
| 382 | + as_client = boto3.client("autoscaling", region_name="us-east-1") |
| 383 | + as_client.create_auto_scaling_group( |
| 384 | + AutoScalingGroupName="myasgroup", |
| 385 | + MinSize=2, |
| 386 | + MaxSize=3, |
| 387 | + LaunchTemplate={"LaunchTemplateId": template["LaunchTemplateId"]}, |
| 388 | + VPCZoneIdentifier=mocked_networking["subnet1"], |
| 389 | + ) |
| 390 | + resp = ec2_client.describe_instances( |
| 391 | + Filters=[{"Name": "tag:aws:autoscaling:groupName", "Values": ["myasgroup"]}] |
| 392 | + ) |
| 393 | + instances = resp["Reservations"][0]["Instances"] |
| 394 | + for instance in instances: |
| 395 | + attr_resp = ec2_client.describe_instance_attribute( |
| 396 | + InstanceId=instance["InstanceId"], Attribute="userData" |
| 397 | + ) |
| 398 | + assert attr_resp["UserData"]["Value"] == str(user_data) |
0 commit comments