Skip to content

Commit

Permalink
Merge pull request #618 from kayac/feature/secretsmanager_arn
Browse files Browse the repository at this point in the history
add secretsmanager plugin
  • Loading branch information
fujiwara authored Dec 1, 2023
2 parents 47a8d6e + b6b1341 commit 3b66704
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
"text/template"

"github.com/aws/aws-sdk-go-v2/service/secretsmanager"
"github.com/fujiwara/cfn-lookup/cfn"
"github.com/fujiwara/tfstate-lookup/tfstate"

Expand All @@ -28,6 +29,8 @@ func (p ConfigPlugin) Setup(ctx context.Context, c *Config) error {
return setupPluginCFn(ctx, p, c)
case "ssm":
return setupPluginSSM(ctx, p, c)
case "secretsmanager":
return setupPluginSecretsManager(ctx, p, c)
default:
return fmt.Errorf("plugin %s is not available", p.Name)
}
Expand Down Expand Up @@ -90,3 +93,18 @@ func setupPluginSSM(ctx context.Context, p ConfigPlugin, c *Config) error {
}
return p.AppendFuncMap(c, funcs)
}

func setupPluginSecretsManager(ctx context.Context, p ConfigPlugin, c *Config) error {
funcs := make(template.FuncMap)
smsvc := secretsmanager.NewFromConfig(c.awsv2Config)
funcs[p.FuncPrefix+"secretsmanager_arn"] = func(id string) (string, error) {
res, err := smsvc.DescribeSecret(ctx, &secretsmanager.DescribeSecretInput{
SecretId: &id,
})
if err != nil {
return "", err
}
return *res.ARN, nil
}
return p.AppendFuncMap(c, funcs)
}
4 changes: 4 additions & 0 deletions tests/ci/ecs-task-def.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
{
"name": "JSON_FOO",
"valueFrom": "arn:aws:secretsmanager:ap-northeast-1:{{must_env `AWS_ACCOUNT_ID`}}:secret:ecspresso-test/json-soBS7X:foo::"
},
{
"name": "JSON_VIA_SSM",
"valueFrom": "{{ secretsmanager_arn `ecspresso-test/json` }}"
}
],
"command": [
Expand Down
2 changes: 2 additions & 0 deletions tests/ci/ecspresso.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ service: "{{ must_env `SERVICE` }}"
service_definition: ecs-service-def.json
task_definition: ecs-task-def.json
timeout: 10m0s
plugins:
- name: secretsmanager

0 comments on commit 3b66704

Please sign in to comment.