如何在每次配置文件内容发生更改时创建新版本的 AWS Appconfig 配置文件

问题描述 投票:0回答:1

我想通过 Terraform 管理 AWS appconfig。但我面临的问题是,terraform 在每次配置更改时都会销毁/创建配置托管配置的资源,从而产生相同的版本。这对于任何使用 Appconfig 的人来说都是没用的。

这个想法是每次文件内容发生更改时创建一个更新的版本,并通过其他工作流程进行部署。

我正在尝试使用的示例代码。

provider "aws" {
  region  = "ap-south-1"
  profile = "default"
}

# Create the AppConfig application
resource "aws_appconfig_application" "homepage" {
  name        = "homepage"
  description = "Homepage application configuration"
}

# Create the configuration profiles
# application.yml
resource "aws_appconfig_configuration_profile" "application" {
  application_id = aws_appconfig_application.homepage.id
  name           = "application"
  description    = "Application configuration profile"
  location_uri   = "hosted"
}

# http.yml
resource "aws_appconfig_configuration_profile" "http" {
  application_id = aws_appconfig_application.homepage.id
  name           = "http"
  description    = "HTTP configuration profile"
  location_uri   = "hosted"
}

# Create the environment
resource "aws_appconfig_environment" "uat" {
  application_id = aws_appconfig_application.homepage.id
  name           = "uat"
  description    = "UAT environment"
}

# Create the hosted configuration versions (assuming content is in local files)
resource "aws_appconfig_hosted_configuration_version" "application" {
  application_id           = aws_appconfig_application.homepage.id
  configuration_profile_id = aws_appconfig_configuration_profile.application.configuration_profile_id
  content                  = file("${path.module}/configs/application.yml")
  content_type             = "application/x-yaml"
  description              = "Application configuration version"
}

resource "aws_appconfig_hosted_configuration_version" "http" {
  application_id           = aws_appconfig_application.homepage.id
  configuration_profile_id = aws_appconfig_configuration_profile.http.configuration_profile_id
  content                  = file("${path.module}/configs/http.yml")
  content_type             = "application/x-yaml"
  description              = "HTTP configuration version"
}
amazon-web-services terraform devops aws-app-config
1个回答
0
投票

您必须向 terraform 代码添加 Hosted_configuration_version 以及部署,如下所示(我的用例略有不同,但应该可以理解):

resource "aws_appconfig_hosted_configuration_version" "click-relay-initial" {
  application_id           = aws_appconfig_application.click-relay.id
  configuration_profile_id = aws_appconfig_configuration_profile.click-relay.configuration_profile_id
  description              = "Initial version"
  content_type             = "text/plain"


  content = yamlencode({
    foo            = "bar"
  })
}

resource "aws_appconfig_hosted_configuration_version" "click-relay-v2" {
  application_id           = aws_appconfig_application.click-relay.id
  configuration_profile_id = aws_appconfig_configuration_profile.click-relay.configuration_profile_id
  description              = "Changed foo"
  content_type             = "text/plain"


  content = yamlencode({
    foo            = "world"
  })
}

resource "aws_appconfig_deployment" "click-relay-initial" {
  application_id           = aws_appconfig_application.click-relay.id
  configuration_profile_id = aws_appconfig_configuration_profile.click-relay.configuration_profile_id
  configuration_version    = aws_appconfig_hosted_configuration_version.click-relay-initial.version_number
  deployment_strategy_id   = aws_appconfig_deployment_strategy.click-relay.id
  description              = "Ad-hoc deployment"
  environment_id           = aws_appconfig_environment.click-relay.environment_id
}

resource "aws_appconfig_deployment" "click-relay-v2" {
  application_id           = aws_appconfig_application.click-relay.id
  configuration_profile_id = aws_appconfig_configuration_profile.click-relay.configuration_profile_id
  configuration_version    = aws_appconfig_hosted_configuration_version.click-relay-v2.version_number
  deployment_strategy_id   = aws_appconfig_deployment_strategy.click-relay.id
  description              = "Ad-hoc deployment"
  environment_id           = aws_appconfig_environment.click-relay.environment_id
}

这添加了一个新版本。

© www.soinside.com 2019 - 2024. All rights reserved.