我在许多提供者是 AWS 的 Terraform 项目中看到了一个可重复的配置: 出站(出口)规则的配置以允许所有出站流量。
据我了解,这是AWS 用户指南中提到的AWS 中的默认行为:
默认情况下,安全组包含允许所有出站流量的出站规则。您可以删除规则并添加仅允许特定出站流量的出站规则。如果您的安全组没有出站规则,则不允许来自您的实例的出站流量。
安全组的常见 Terraform 设置示例 - 我的问题的重点是出口块:
resource "aws_security_group" "my_sg" {
name = "my_sg"
description = "Some description"
vpc_id = "${aws_vpc.my_vpc.id}"
tags {
Name = "my_sg_tag"
}
#Not redundant - Because a new security group has no inbound rules.
ingress {
from_port = "80"
to_port = "80"
protocol = "TCP"
cidr_blocks = ["0.0.0.0/0"]
}
#Isn't this redundant?
egress {
from_port = 0
to_port = 0
protocol = "-1" …Run Code Online (Sandbox Code Playgroud) 我正在使用基础设施即代码在 CloudFormation 中实施 GSI。我想要做的就是使用这个表来记录主 DynamoTable 中的条目数。这是主要故事的样子:
Resources:
CaseRecords:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:custom.tableName}
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: userId
AttributeType: S
- AttributeName: caseRecordId
AttributeType: S
KeySchema:
- AttributeName: userId
KeyType: HASH
- AttributeName: caseRecordId
KeyType: RANGE
Run Code Online (Sandbox Code Playgroud)
我不需要原始表中的键,我想要的只是为新 GSI 创建一个新的 HASH 键,它会告诉我我正在跟踪的计数来自哪个表,即上面的表。
以下是我迄今为止尝试实施 GSI 的方式:
# Implement a GSI to handle item count totals
GlobalSecondaryIndexes:
- IndexName: gsiCaseCountTable
KeySchema:
- AttributeName: table-name
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
Run Code Online (Sandbox Code Playgroud)
但是,我得到的错误如下:
An error occurred: CaseRecords - Property Projection cannot be empty.. …
yaml aws-cloudformation amazon-dynamodb infrastructure-as-code
在我当前的 terraform 配置中,我使用静态 JSON 文件并使用 file 函数导入到 terraform 以创建 AWS IAM 策略。
地形代码:
resource "aws_iam_policy" "example" {
policy = "${file("policy.json")}"
}
Run Code Online (Sandbox Code Playgroud)
JSON 文件 (policy.json) 中的 AWS IAM 策略定义:
{
"Version": "2012-10-17",
"Id": "key-consolepolicy-2",
"Statement": [
{
"Sid": "Enable IAM User Permissions",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::111122223333:root"
},
"Action": "kms:*",
"Resource": "*"
},
{
"Sid": "Allow use of the key",
"Effect": "Allow",
"Principal": {
"AWS": [
"arn:aws:iam::777788889999:root"
]
},
"Action": [
"kms:Decrypt"
],
"Resource": "*"
},
{
"Sid": "Allow use …Run Code Online (Sandbox Code Playgroud) json amazon-web-services amazon-iam terraform infrastructure-as-code
我正在建立一个基础设施来支持一个 WebApp。我的存储库之一拥有所有网络基础设施(VPC、子网、NAT、堡垒等)。WebApp 具有 Route 53 + ALB + AutoScalling Group + EC2 实例。所有这些都在 Cloudformation 模板中编码。我的问题是 WebApp Cloudformation 模板是否应该与应用程序存储在同一个存储库中?是否有关于如何分离基础架构和应用程序代码的最佳实践?
amazon-web-services aws-cloudformation terraform infrastructure-as-code
我是大型 AWS 部署的新手,其中大部分内容是通过 CloudFormation 部署的(有些是通过 Terraform 部署的)。但总有一些情况是手动部署的,而不是通过代码。是否有可靠的方法可以快速确定部署中已存在的资源(例如 EC2 实例)是通过 IaC 还是手动部署?目前,特定于 CloudFormation 的答案就足够了。
手动浏览数百个 CloudFormation 堆栈并查找资源并不是一种选择。
amazon-web-services aws-cloudformation infrastructure-as-code
我知道我可以使用基础设施作为代码来设置 Cloud Firestore 和 GCP Cloud Functions,但我很感兴趣它会显示在 Firebase 控制台上。我也找不到任何使用 IaaC 部署 Firebase 身份验证和实时数据库的方法。
firebase google-cloud-platform google-cloud-functions google-cloud-firestore infrastructure-as-code
我已使用此模块在 AWS VPC 中创建安全组。如何在单独的文件中引用由此创建的资源?我正在同一存储库的单独目录中创建我们的堡垒实例。
我的堡垒配置如下所示,使用 Terraform EC2 模块,并且如果我对 vpc 安全组 ID 进行硬编码,则可以正常工作,但我希望它能够直接从创建安全组时获取它,因为这将来可能会发生变化..
terraform/aws/layers/bastion/main.tf
provider "aws" {
region = var.region
}
module "ec2-instance" {
source = "terraform-aws-modules/ec2-instance/aws"
name = "bastion"
instance_count. = 1
ami = var.image_id
instance_type = var.instance_type
vpc_security_group_ids = ["${}"]
subnet_id = var.subnet
iam_instance_profile = "aws-example-ec2-role"
tags = {
Layer = "Bastion"
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我创建安全组的方式: terraform/aws/global/vpc/bastion_sg.tf
module "bastion-sg" {
source = "terraform-aws-modules/security-group/aws"
name = "Bastion"
description = "Bastion example group"
vpc_id = "vpc-12345"
ingress_with_cidr_blocks = [
{ …Run Code Online (Sandbox Code Playgroud) amazon-ec2 amazon-web-services terraform aws-security-group infrastructure-as-code
我想这个问题在互联网上应该有很清楚的答案。但对于何时使用一种类型的堆栈以及何时使用另一种类型的堆栈,我没有找到足够的答案。
我可以仅使用常规堆栈完美地建模我的基础设施。此外,我可以仅使用嵌套堆栈和一个根常规堆栈来完美地建模我的基础设施。从项目角度来看 - 唯一的区别是堆栈类型名称。其他一切都一样。
例如,我正在使用 AWS CDK - 一个合成器,可以将 python 合成到 CloudFormation 模板。我可以使用 Stacks 做所有事情,并且可以简单地查找 Stack 并将其替换为 NestedStack。基础设施将被重新部署,但本质上没有任何改变。
amazon-web-services aws-cloudformation aws-cdk infrastructure-as-code nested-stack
我尝试在 Terraform 项目中使用 Azure/Azapi Provider,但在添加提供程序并运行之后terraform init,出现以下错误:
Error: Failed to query available provider packages\nCould not retrieve the list of available versions for provider hashicorp/azapi: provider registry registry.terraform.io does not have a provider named registry.terraform.io/hashicorp/azapi \nRun Code Online (Sandbox Code Playgroud)\n这就是我的providers.tf 的样子:
\nterraform {\n required_providers {\n azurerm = {\n source = "hashicorp/azurerm"\n version = "=3.16.0"\n }\n azapi = {\n source = "azure/azapi"\n version = "=0.4.0"\n }\n\n }\n\n required_version = "=1.2.6"\n}\n\nprovider "azurerm" {\n features {}\n}\n\nprovider "azapi" {\n}\nRun Code Online (Sandbox Code Playgroud)\n当我跑步时terraform providers,我可以看到提供程序在我的模块中有错误的注册表 …
作为 IaC 的一部分,函数应用程序(我们将其命名为FuncAppX)是使用 Terraform 进行部署的,其中包含一个函数。
我需要使用 Terraform 在函数应用程序中访问同一函数的Url 。我在这里分享相同的屏幕截图以供参考,其中很容易获得“ GetFunction Url ”,但使用 terraform ,我没有办法返回相同的屏幕截图,它需要作为输入传递给另一个函数应用程序。
terraform azure-functions terraform-provider-azure infrastructure-as-code
terraform ×6
amazon-ec2 ×1
amazon-iam ×1
aws-cdk ×1
azure ×1
firebase ×1
json ×1
nested-stack ×1
yaml ×1