添加存储库分支,并使用Terraform在AWS Ampify上配置构建



我一直在尝试使用Terraform在AWS Amplify上托管一个web应用程序。我使用了以下代码:

# Ressource 1: AWS Amplify
resource "aws_amplify_app" "wildrydes-site" {
name       = "wildrydes-site"
repository = "https://github.com/userx/wildrydes-site"
# GitHub personal access token
access_token = "xxxxxxxxxxx"

# The default rewrites and redirects added by the Amplify Console.
custom_rule {
source = "/<*>"
status = "404"
target = "/index.html"
}
#Auto Branch Creation
enable_auto_branch_creation = true
# The default patterns added by the Amplify Console.
auto_branch_creation_patterns = [
"*",
"*/**",
]
auto_branch_creation_config {
# Enable auto build for the created branch.
enable_auto_build = true
}

资源实际上已经创建,但我必须手动连接Git存储库中的源代码,并添加存储库分支。有人知道我错过了什么吗?谢谢你的帮助。

经过多次尝试,这对我来说终于奏效了。不过,可能需要剖析原因。

terraform {
required_providers {
aws = {
source  = "hashicorp/aws"
version = "~> 3.27"
}
}
required_version = ">= 0.14.9"
}
provider "aws" {
profile = "default"
region  = "us-west-2"
}
resource "aws_amplify_app" "example" {
name         = "blah"
repository   = "repo here"
access token = "..."

environment_variables = {
ENV = "test"
}
# The default rewrites and redirects added by the Amplify Console.
custom_rule {
source = "/<*>"
status = "404"
target = "/index.html"
}
#Auto Branch Creation
enable_auto_branch_creation = true
# The default patterns added by the Amplify Console.
auto_branch_creation_patterns = [
"*",
"*/**",
]
auto_branch_creation_config {
# Enable auto build for the created branch.
enable_auto_build = true
}
}
resource "aws_amplify_branch" "master" {
app_id      = aws_amplify_app.example.id
branch_name = "main"
stage = "PRODUCTION"
}

他添加了

resource "aws_amplify_branch" "master" {
app_id      = aws_amplify_app.example.id
branch_name = "main"
stage = "PRODUCTION"
}

这将放大中的Production branch设置为main

最新更新