Skip to content

Commit

Permalink
Merge pull request #77 from PeyGis/elasticache
Browse files Browse the repository at this point in the history
Add ECR repo and Elasticache cluster to template asset
  • Loading branch information
matarpeles authored Dec 13, 2023
2 parents d582962 + a3bf021 commit e9a2630
Show file tree
Hide file tree
Showing 9 changed files with 401 additions and 0 deletions.
12 changes: 12 additions & 0 deletions aws/aws_blueprints_template/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,16 @@ module "port_eks_cluster" {
source = "../eks_cluster"
count = contains(var.resources, "eks_cluster") ? 1 : 0
depends_on = [port-labs_blueprint.region]
}

module "port_elasticache_cluster" {
source = "../elasticache_cluster"
count = contains(var.resources, "elasticache_cluster") ? 1 : 0
depends_on = [port-labs_blueprint.region]
}

module "port_ecr_repository" {
source = "../ecr_repository"
count = contains(var.resources, "ecr_repository") ? 1 : 0
depends_on = [port-labs_blueprint.region]
}
71 changes: 71 additions & 0 deletions aws/ecr_repository/blueprint.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
terraform {
required_providers {
port-labs = {
source = "port-labs/port-labs"
version = "0.10.4"
}
}
}

resource "port-labs_blueprint" "ecr_repository" {
title = "ECR Repository"
icon = "Service"
identifier = "ecr_repository"

properties {
identifier = "link"
type = "string"
format = "url"
title = "Link"
}

properties {
identifier = "imageTagMutability"
type = "string"
title = "Image Tag Mutability"
}

properties {
identifier = "repositoryArn"
type = "string"
title = "Repository ARN"
}

properties {
identifier = "repositoryUri"
type = "string"
title = "Repository URI"
}

properties {
identifier = "scanningConfiguration"
type = "object"
title = "Scanning Configuration"
}

properties {
identifier = "encryptionConfiguration"
type = "object"
title = "Encryption Configuration"
}

properties {
identifier = "lifecyclePolicy"
type = "object"
title = "Lifecycle Policy"
}

properties {
identifier = "tags"
type = "array"
title = "Tags"
}

relations {
target = "region"
title = "Region"
identifier = "region"
many = false
required = false
}
}
27 changes: 27 additions & 0 deletions aws/ecr_repository/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"kind":"AWS::ECR::Repository",
"port":{
"entity":{
"mappings":[
{
"identifier":".RepositoryName",
"title":".RepositoryName",
"blueprint":"ecr_repository",
"properties":{
"imageTagMutability":".ImageTagMutability",
"scanningConfiguration":".ImageScanningConfiguration",
"repositoryArn":".Arn",
"link":"\"https://console.aws.amazon.com/go/view?arn=\" + .Arn",
"repositoryUri":".RepositoryUri",
"encryptionConfiguration":".EncryptionConfiguration",
"lifecyclePolicy":".LifecyclePolicy",
"tags":".Tags"
},
"relations":{
"region":".Arn | split(\":\") | .[3]"
}
}
]
}
}
}
70 changes: 70 additions & 0 deletions aws/ecr_repository/event_rule.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
ECRRepositoryEventRule:
Type: AWS::Events::Rule
Properties:
EventBusName: default
EventPattern:
detail-type:
- AWS API Call via CloudTrail
source:
- aws.ecr
detail:
eventSource:
- ecr.amazonaws.com
eventName:
- prefix: CreateRepository
- prefix: DeleteRepository
- prefix: DeleteLifecyclePolicy
- prefix: PutLifecyclePolicy
Name: port-aws-exporter-sync-ecr-trails
State: ENABLED
Targets:
- Id: PortAWSExporterEventsQueue
Arn:
Fn::ImportValue:
Fn::Sub: ${PortAWSExporterStackName}-EventsQueueARN
InputTransformer:
InputPathsMap:
awsRegion: $.detail.awsRegion
eventName: $.detail.eventName
repositoryName: $.detail.requestParameters.repositoryName
InputTemplate: >-
{
"resource_type": "AWS::ECR::Repository",
"region": "\"<awsRegion>\"",
"identifier": "\"<repositoryName>\"",
"action": "if \"<eventName>\" | startswith(\"DeleteRepository\") then \"delete\" else \"upsert\" end"
}
ECRRepositoryTagRule:
Type: AWS::Events::Rule
Properties:
EventBusName: default
EventPattern:
source:
- aws.ecr
detail-type:
- AWS API Call via CloudTrail
detail:
eventSource:
- ecr.amazonaws.com
eventName:
- prefix: TagResource
- prefix: UntagResource
Name: port-aws-exporter-sync-ecr-tags-trails
State: ENABLED
Targets:
- Id: PortAWSExporterEventsQueue
Arn:
Fn::ImportValue:
Fn::Sub: ${PortAWSExporterStackName}-EventsQueueARN
InputTransformer:
InputPathsMap:
awsRegion: $.detail.awsRegion
eventName: $.detail.eventName
resourceArn: $.detail.requestParameters.resourceArn
InputTemplate: |-
{
"resource_type": "AWS::ECR::Repository",
"region": "\"<awsRegion>\"",
"identifier": "\"<resourceArn>\" | split(\"/\") | .[-1]",
"action": "\"upsert\""
}
6 changes: 6 additions & 0 deletions aws/ecr_repository/policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
"ecr:DescribeRepositories",
"ecr:GetLifecyclePolicy",
"ecr:GetRepositoryPolicy",
"ecr:ListTagsForResource"
]
109 changes: 109 additions & 0 deletions aws/elasticache_cluster/blueprint.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
terraform {
required_providers {
port-labs = {
source = "port-labs/port-labs"
version = "0.10.4"
}
}
}

resource "port-labs_blueprint" "elasticache_cluster" {
title = "Elasticache Cluster"
icon = "AWS"
identifier = "elasticache_cluster"

properties {
identifier = "status"
type = "string"
title = "Status"
}

properties {
identifier = "engine"
type = "string"
title = "Engine"
}

properties {
identifier = "engineVersion"
type = "string"
title = "Engine Version"
}

properties {
identifier = "preferredAvailabilityZone"
type = "string"
title = "Preferred Availability Zone"
}

properties {
identifier = "createdDate"
type = "string"
format = "date-time"
title = "Created Date"
}

properties {
identifier = "arn"
type = "string"
title = "ARN"
}

properties {
identifier = "transitEncryptionEnabled"
type = "boolean"
title = "Transit Encryption Enabled"
}

properties {
identifier = "atRestEncryptionEnabled"
type = "boolean"
title = "At Rest Encryption Enabled"
}

properties {
identifier = "nodeType"
type = "string"
title = "Node Type"
}

properties {
identifier = "link"
type = "string"
title = "Link"
format = "url"
}

properties {
identifier = "subnetGroupName"
type = "string"
title = "Subnet Group Name"
}

properties {
identifier = "numNodes"
type = "number"
title = "Number of Nodes"
}

properties {
identifier = "securityGroups"
type = "array"
title = "Security Groups"
}

properties {
identifier = "tags"
type = "array"
title = "Tags"
}

relations {
target = "region"
title = "Region"
identifier = "region"
many = false
required = false
}

}
33 changes: 33 additions & 0 deletions aws/elasticache_cluster/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"kind":"AWS::ElastiCache::CacheCluster",
"port":{
"entity":{
"mappings":[
{
"identifier":".CacheClusterId",
"title":".CacheClusterId",
"blueprint":"elasticache_cluster",
"properties":{
"engine": ".Engine",
"engineVersion": ".EngineVersion",
"preferredAvailabilityZone": ".PreferredAvailabilityZone",
"createdDate": ".CacheClusterCreateTime",
"arn": ".ARN",
"transitEncryptionEnabled": ".TransitEncryptionEnabled",
"atRestEncryptionEnabled": ".AtRestEncryptionEnabled",
"link": "\"https://console.aws.amazon.com/go/view?arn=\" + .ARN",
"nodeType": ".CacheNodeType",
"status": ".CacheClusterStatus",
"tags": ".Tags",
"numNodes": ".NumCacheNodes",
"securityGroups": ".CacheSecurityGroups",
"subnetGroupName": ".CacheSubnetGroupName"
},
"relations":{
"region":".ARN | split(\":\") | .[3]"
}
}
]
}
}
}
Loading

0 comments on commit e9a2630

Please sign in to comment.