混合 Terraform 和無服務器框架 (Mixing Terraform and Serverless Framework)


問題描述

混合 Terraform 和無服務器框架 (Mixing Terraform and Serverless Framework)

這更像是一個懸而未決的問題,我只是希望得到任何意見和建議。我想到了 AWS,但它可能也與其他雲提供商相關。

我想提供 IaaC 解決方案,該解決方案將易於維護並涵蓋現代無服務器架構的所有要求。Terraform 是定義基礎設施的絕佳工具,擁有眾多官方資源和社區的穩定支持。我真的很喜歡它的語法和模塊的整個概念。但是,使用 Lambdas 非常糟糕。它還提出了另一個問題:是否應該使用與基礎架構更改相同的流程來部署代碼更改?在哪裡劃清代碼和基礎設施之間的界限?

另一方面,無服務器框架允許超級輕鬆地開發和部署 Lambda。在資源的使用方面,它有強烈的意見,但它具有許多值得的開箱即用的功能。它不應該真正用於定義整個基礎架構。

我目前的方法是使用 Terraform 定義任何共享資源,並使用 Serverless 定義任何與域相關的資源。這裡我有另一個與我之前的問題相關的問題:部署依賴。簡單場景:Lambda.1 將用戶添加到以 Lambda.2 作為觸發器的 Cognito(共享資源)。我必須創建一個自定義解決方案來管理部署順序(必須首先部署 Lambda.2,等等)。它'


參考解法

方法 1:

It is totally possible to mix the two and I have had to do so a few times. How this looks actually ends up being simpler than it seems.

First off, if you think about whatever you do with the Serverless Framework as developing microservices (without the associated infrastructure management burden), that takes it one step in the right direction. Then, what you can do is decide that everything that is required to make that microservice work internally is defined within that microservice as a part of the services configuration in the serverless.yml, whether that be DynamoDB tables, Auth0 integrations, Kinesis streams, SQS, SNS, IAM permissions allocated to functions, etc. Keep that all defined as a part of that microservice. Terraform not required.

Now think about what that and other microservices might need to interact with more broadly. They aren't critical for that services internal operation but are critical for integration into the rest of the organisations infrastructure. This includes things like deployment IAM roles used by the Serverless Framework services to deploy into CloudFormation, Relational Databases that have to be shared amongst multiple services and resources, networking elements (VPC's, Security Groups, etc), monolithic clusters like ElasticSearch and Redis ... all of these elements are great candidates for definition outside of the Serverless Framework and work really well with Terraform.

Any resource would be able to connect to these Terraform defined resource as needed, unlike that hard association such as Lambda functions triggered off of an API Gateway endpoint.

Hope that helps

(by Jakub NurskiGareth McCumskey)

參考文件

  1. Mixing Terraform and Serverless Framework (CC BY‑SA 2.5/3.0/4.0)

#terraform #serverless #amazon-web-services #serverless-framework






相關問題

如何在 terraform 中運行 kubectl apply 命令 (How To Run kubectl apply commands in terraform)

如何將生命週期規則發送到 terraform 中的 s3 模塊 (How to send lifecycle_rules to a s3 module in terraform)

將存儲桶策略附加到 s3 存儲桶時,Terraform 拋出存儲桶區域錯誤 (Terraform throwing bucket region error when attaching bucket policy to s3 bucket)

如何在 Terraform 中創建標量數組/列表? (How do you create scalar arrays/lists in Terraform?)

混合 Terraform 和無服務器框架 (Mixing Terraform and Serverless Framework)

我需要在 Fargate 中設置 aws_autoscaling_group 嗎? (Do I need to setup aws_autoscaling_group in fargate?)

Terraform:將變量列表傳遞給容器環境變量 (Terraform: pass variable list to container environment variables)

問題迭代“aws_wafv2_regex_pattern_set”terraform wafv2 (issue iteration over "aws_wafv2_regex_pattern_set" terraform wafv2)

Terraform 狀態 rm 命令 (Terraform state rm command)

如何使用 CMD 在 docker 容器中運行 terraform apply --auto-approve (How to run terraform apply --auto-approve in docker container using CMD)

使用 GCP 令牌、terraform 和 vault 創建項目時出現權限錯誤 (Permisson error creating project with GCP token, terraform and vault)

terraform.apply InvalidParameterException:以下提供的實例類型不存在:[m4.large] (terraform.apply InvalidParameterException: The following supplied instance types do not exist: [m4.large])







留言討論