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

initial implementation of lambda #23

Merged
merged 3 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 135 additions & 0 deletions compositions/terrajet-aws-provider/lambda/container.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0

apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: container.lambda.jet.awsblueprints.io
labels:
awsblueprints.io/provider: aws-jet
awsblueprints.io/environment: dev
spec:
writeConnectionSecretsToNamespace: crossplane-system
compositeTypeRef:
apiVersion: awsblueprints.io/v1alpha1
kind: XLambdaFunction
patchSets:
- name: common-fields
patches:
- type: FromCompositeFieldPath
fromFieldPath: spec.resourceConfig.deletionPolicy
toFieldPath: spec.deletionPolicy
- type: FromCompositeFieldPath
fromFieldPath: spec.resourceConfig.region
toFieldPath: spec.forProvider.region
- type: FromCompositeFieldPath
fromFieldPath: spec.resourceConfig.tags
toFieldPath: spec.forProvider.tags
policy:
mergeOptions:
appendSlice: true
- fromFieldPath: spec.writeConnectionSecretToRef.namespace
toFieldPath: spec.writeConnectionSecretToRef.namespace
- type: FromCompositeFieldPath
fromFieldPath: spec.resourceConfig.name
toFieldPath: metadata.annotations[crossplane.io/external-name]
resources:
- name: function
base:
apiVersion: lambda.aws.jet.crossplane.io/v1alpha1
kind: Function
spec:
deletionPolicy: Delete
forProvider:
memorySize: 128
timeout: 30
packageType: Image
patches:
- type: PatchSet
patchSetName: common-fields
- type: FromCompositeFieldPath
fromFieldPath: spec.resourceConfig.jetProviderConfigName
toFieldPath: spec.providerConfigRef.name
- fromFieldPath: "metadata.uid"
toFieldPath: "spec.writeConnectionSecretToRef.name"
transforms:
- type: string
string:
fmt: "%s-lambda-function"
- type: FromCompositeFieldPath
fromFieldPath: metadata.name
toFieldPath: spec.forProvider.functionName
- type: FromCompositeFieldPath
fromFieldPath: spec.imageUri
toFieldPath: spec.forProvider.imageUri
- type: FromCompositeFieldPath
fromFieldPath: spec.runTime
toFieldPath: spec.forProvider.
- type: FromCompositeFieldPath
fromFieldPath: spec.handler
toFieldPath: spec.forProvider.handler
- type: FromCompositeFieldPath
fromFieldPath: status.functionRoleArn
toFieldPath: spec.forProvider.role
- type: ToCompositeFieldPath
fromFieldPath: status.atProvider.arn
toFieldPath: status.functionArn
- name: function-role
base:
apiVersion: iam.aws.crossplane.io/v1beta1 # https://github.com/crossplane-contrib/provider-jet-aws/issues/176
kind: Role
spec:
deletionPolicy: Delete
forProvider:
assumeRolePolicyDocument: |-
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
patches:
- type: PatchSet
patchSetName: common-fields
- type: FromCompositeFieldPath
fromFieldPath: spec.resourceConfig.providerConfigName
toFieldPath: spec.providerConfigRef.name
- fromFieldPath: "metadata.uid"
toFieldPath: "spec.writeConnectionSecretToRef.name"
transforms:
- type: string
string:
fmt: "%s-lambda-function-role"
- type: ToCompositeFieldPath
fromFieldPath: status.atProvider.arn
toFieldPath: status.functionRoleArn
- type: FromCompositeFieldPath
fromFieldPath: spec.permissionsBoundaryArn
toFieldPath: spec.forProvider.permissionsBoundary
- name: lambda-basic-policy-attachment
base:
apiVersion: iam.aws.crossplane.io/v1beta1
kind: RolePolicyAttachment
spec:
forProvider:
policyArn: arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
roleNameSelector:
matchControllerRef: true
patches:
- type: PatchSet
patchSetName: common-fields
- type: FromCompositeFieldPath
fromFieldPath: spec.resourceConfig.providerConfigName
toFieldPath: spec.providerConfigRef.name
- fromFieldPath: "metadata.uid"
toFieldPath: "spec.writeConnectionSecretToRef.name"
transforms:
- type: string
string:
fmt: "%s-lambda-basic-role-attachment"
73 changes: 73 additions & 0 deletions compositions/terrajet-aws-provider/lambda/definitions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0

apiVersion: apiextensions.crossplane.io/v1
kind: CompositeResourceDefinition
metadata:
name: xlambdafunctions.awsblueprints.io
spec:
group: awsblueprints.io
names:
kind: XLambdaFunction
plural: xlambdafunctions
claimNames:
kind: LambdaFunction
plural: lambdafunctions
versions:
- name: v1alpha1
served: true
referenceable: true
schema:
openAPIV3Schema:
description: Table is the Schema for the tables API
properties:
spec:
description: TableSpec defines the desired state of Table
properties:
imageUri:
type: string
timeout:
type: integer
runTime:
type: string
handler:
type: string
permissionsBoundaryArn:
type: string
resourceConfig:
description: ResourceConfig defines general properties of this AWS
resource.
properties:
deletionPolicy:
description: Defaults to Delete
enum:
- Delete
- Orphan
type: string
name:
description: Set the name of this resource in AWS to the value
provided by this field.
type: string
providerConfigName:
type: string
jetProviderConfigName:
type: string
region:
type: string
required:
- region
type: object
required:
- resourceConfig
type: object
status:
properties:
functionRoleArn:
type: string
functionArn:
description: Indicates this function's ARN
type: string
type: object
required:
- spec
type: object