使用 AWS Terraform 代码管道定义中的 S3 存储桶 ARN 而不是存储桶名称。

huangapple go评论56阅读模式
英文:

using s3 bucket arn instead of bucket name in aws terraform code pipeline definition

问题

"BucketName" = "airflow-dev-s3" # <- 是否可以传入 ARN 代替?
英文:

I want to know if there is a way to use s3 bucket arn instead of bucket name in the following aws code pipeline definition.
I have this imported with terraform and I want to reference the s3 bucket that is being created in another MWAA module.
The problem is, there is no output on the MWAA module for bucket name and it is only returning the bucket arn. I am using cloudposse to create the MWAA environment.

Here is the code for code pipeline definition:

resource "aws_codepipeline" "codepipeline" {
    name     = "airflow-pipeline-dev"
    role_arn = "<role arn>"
    tags     = {}
    tags_all = {}

    artifact_store {
        location = "codepipeline-us-east-1"
        type     = "S3"
    }

    stage {
        name = "Source"

        action {
            .....
        }
    }
    stage {
        name = "Build"

        action {
            ....
        }
    }
    stage {
        name = "Deploy"

        action {
            category         = "Deploy"
            configuration    = {
                "BucketName" = "airflow-dev-s3" # <- pass in arn instead?
                "Extract"    = "true"
            }
            input_artifacts  = [
                "BuildArtifact",
            ]
            name             = "Deploy"
            output_artifacts = []
            owner            = "AWS"
            provider         = "S3"
            region           = "us-east-1"
            run_order        = 1
            version          = "1"
        }
    }
}

I have other module for mwaa and I can only output bucket arn from there!

答案1

得分: 1

如果无法修改其他模块以输出存储桶名称,您可以从存储桶 ARN 中提取存储桶名称。ARN 将采用以下形式:

arn:aws:s3:::<bucket_name>

因此只需使用:分割 ARN 并取结果的最后(第六)部分:

locals {
  bucketname = element(split(":", var.bucket_arn), 5)
}
英文:

If you can't modify the other module to output the bucket name, you can extract the bucket name from the bucket ARN. The ARN will have the form

arn:aws:s3:::<bucket_name>

so just split the ARN on : and take the last (sixth) part of the result:

locals {
  bucketname = element(split(":", var.bucket_arn), 5) 
}

Refs:

huangapple
  • 本文由 发表于 2023年4月20日 04:59:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76058771.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定