Skip to content
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

add resource providers for vpc endpoint and prefix list #10735

Merged
merged 7 commits into from Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
135 changes: 135 additions & 0 deletions localstack/services/ec2/resource_providers/aws_ec2_prefixlist.py
@@ -0,0 +1,135 @@
# LocalStack Resource Provider Scaffolding v2
from __future__ import annotations

from pathlib import Path
from typing import Optional, TypedDict

import localstack.services.cloudformation.provider_utils as util
from localstack.services.cloudformation.resource_provider import (
OperationStatus,
ProgressEvent,
ResourceProvider,
ResourceRequest,
)


class EC2PrefixListProperties(TypedDict):
AddressFamily: Optional[str]
MaxEntries: Optional[int]
PrefixListName: Optional[str]
Arn: Optional[str]
Entries: Optional[list[Entry]]
OwnerId: Optional[str]
PrefixListId: Optional[str]
Tags: Optional[list[Tag]]
Version: Optional[int]


class Tag(TypedDict):
Key: Optional[str]
Value: Optional[str]


class Entry(TypedDict):
Cidr: Optional[str]
Description: Optional[str]


REPEATED_INVOCATION = "repeated_invocation"


class EC2PrefixListProvider(ResourceProvider[EC2PrefixListProperties]):
TYPE = "AWS::EC2::PrefixList" # Autogenerated. Don't change
SCHEMA = util.get_schema_path(Path(__file__)) # Autogenerated. Don't change

def create(
self,
request: ResourceRequest[EC2PrefixListProperties],
) -> ProgressEvent[EC2PrefixListProperties]:
"""
Create a new resource.

Primary identifier fields:
- /properties/PrefixListId

Required properties:
- PrefixListName
- MaxEntries
- AddressFamily



Read-only properties:
- /properties/PrefixListId
- /properties/OwnerId
- /properties/Version
- /properties/Arn

IAM permissions required:
- EC2:CreateManagedPrefixList
- EC2:DescribeManagedPrefixLists
- EC2:CreateTags

"""
model = request.desired_state
create_params = util.select_attributes(
model, ["PrefixListName", "Entrie", "MaxEntries", "AddressFamily", "Tags"]
pinzon marked this conversation as resolved.
Show resolved Hide resolved
)

if "Tags" in create_params:
create_params["TagSpecifications"] = [
{"ResourceType": "prefix-list", "Tags": create_params.pop("Tags")}
]

response = request.aws_client_factory.ec2.create_managed_prefix_list(**create_params)
model["Arn"] = response["PrefixList"]["PrefixListId"]
model["OwnerId"] = response["PrefixList"]["OwnerId"]
model["PrefixListId"] = response["PrefixList"]["PrefixListId"]
model["Version"] = response["PrefixList"]["Version"]
pinzon marked this conversation as resolved.
Show resolved Hide resolved

return ProgressEvent(status=OperationStatus.SUCCESS, resource_model=model)

def read(
self,
request: ResourceRequest[EC2PrefixListProperties],
) -> ProgressEvent[EC2PrefixListProperties]:
"""
Fetch resource information

IAM permissions required:
- EC2:GetManagedPrefixListEntries
- EC2:DescribeManagedPrefixLists
"""
raise NotImplementedError

def delete(
self,
request: ResourceRequest[EC2PrefixListProperties],
) -> ProgressEvent[EC2PrefixListProperties]:
"""
Delete a resource

IAM permissions required:
- EC2:DeleteManagedPrefixList
- EC2:DescribeManagedPrefixLists
"""
request.aws_client_factory.ec2.delete_managed_prefix_list(
PrefixListId=request.desired_state["PrefixListId"]
)
return ProgressEvent(status=OperationStatus.SUCCESS, resource_model=None)
pinzon marked this conversation as resolved.
Show resolved Hide resolved

def update(
self,
request: ResourceRequest[EC2PrefixListProperties],
) -> ProgressEvent[EC2PrefixListProperties]:
"""
Update a resource

IAM permissions required:
- EC2:DescribeManagedPrefixLists
- EC2:GetManagedPrefixListEntries
- EC2:ModifyManagedPrefixList
- EC2:CreateTags
- EC2:DeleteTags
"""
raise NotImplementedError
@@ -0,0 +1,152 @@
{
"typeName": "AWS::EC2::PrefixList",
"description": "Resource schema of AWS::EC2::PrefixList Type",
"sourceUrl": "https://github.com/aws-cloudformation/aws-cloudformation-rpdk.git",
"definitions": {
"Tag": {
"type": "object",
"properties": {
"Key": {
"type": "string",
"minLength": 1,
"maxLength": 128
},
"Value": {
"type": "string",
"maxLength": 256
}
},
"required": [
"Key"
],
"additionalProperties": false
},
"Entry": {
"type": "object",
"properties": {
"Cidr": {
"type": "string",
"minLength": 1,
"maxLength": 46
},
"Description": {
"type": "string",
"minLength": 0,
"maxLength": 255
}
},
"required": [
"Cidr"
],
"additionalProperties": false
}
},
"properties": {
"PrefixListName": {
"description": "Name of Prefix List.",
"type": "string",
"minLength": 1,
"maxLength": 255
},
"PrefixListId": {
"description": "Id of Prefix List.",
"type": "string"
},
"OwnerId": {
"description": "Owner Id of Prefix List.",
"type": "string"
},
"AddressFamily": {
"description": "Ip Version of Prefix List.",
"type": "string",
"enum": [
"IPv4",
"IPv6"
]
},
"MaxEntries": {
"description": "Max Entries of Prefix List.",
"type": "integer",
"minimum": 1
},
"Version": {
"description": "Version of Prefix List.",
"type": "integer"
},
"Tags": {
"description": "Tags for Prefix List",
"type": "array",
"items": {
"$ref": "#/definitions/Tag"
}
},
"Entries": {
"description": "Entries of Prefix List.",
"type": "array",
"items": {
"$ref": "#/definitions/Entry"
}
},
"Arn": {
"description": "The Amazon Resource Name (ARN) of the Prefix List.",
"type": "string"
}
},
"required": [
"PrefixListName",
"MaxEntries",
"AddressFamily"
],
"readOnlyProperties": [
"/properties/PrefixListId",
"/properties/OwnerId",
"/properties/Version",
"/properties/Arn"
],
"primaryIdentifier": [
"/properties/PrefixListId"
],
"tagging": {
"taggable": true,
"tagOnCreate": true,
"tagUpdatable": true,
"cloudFormationSystemTags": true
},
"handlers": {
"create": {
"permissions": [
"EC2:CreateManagedPrefixList",
"EC2:DescribeManagedPrefixLists",
"EC2:CreateTags"
]
},
"read": {
"permissions": [
"EC2:GetManagedPrefixListEntries",
"EC2:DescribeManagedPrefixLists"
]
},
"update": {
"permissions": [
"EC2:DescribeManagedPrefixLists",
"EC2:GetManagedPrefixListEntries",
"EC2:ModifyManagedPrefixList",
"EC2:CreateTags",
"EC2:DeleteTags"
]
},
"delete": {
"permissions": [
"EC2:DeleteManagedPrefixList",
"EC2:DescribeManagedPrefixLists"
]
},
"list": {
"permissions": [
"EC2:DescribeManagedPrefixLists",
"EC2:GetManagedPrefixListEntries"
]
}
},
"additionalProperties": false
}
@@ -0,0 +1,20 @@
from typing import Optional, Type

from localstack.services.cloudformation.resource_provider import (
CloudFormationResourceProviderPlugin,
ResourceProvider,
)


class EC2PrefixListProviderPlugin(CloudFormationResourceProviderPlugin):
name = "AWS::EC2::PrefixList"

def __init__(self):
self.factory: Optional[Type[ResourceProvider]] = None

def load(self):
from localstack.services.ec2.resource_providers.aws_ec2_prefixlist import (
EC2PrefixListProvider,
)

self.factory = EC2PrefixListProvider