Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Terrform custom registry generator & promotion script #457

Merged
merged 27 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2db6e56
Initial pass at the terrform promotion script. Still a WIP.
tcsc Mar 18, 2022
4db9193
Additional semver tests
tcsc Mar 21, 2022
a6c2bc3
Upload & Review fixups
tcsc Mar 21, 2022
3d082cb
Drone
tcsc Mar 22, 2022
c0ebff9
Sign drone
tcsc Mar 22, 2022
c84015d
More drone tweaks
tcsc Mar 22, 2022
f4f612b
drone tweaks
tcsc Mar 23, 2022
ad72f29
fix inviocation
tcsc Mar 23, 2022
ef065d3
AWS tweak
tcsc Mar 23, 2022
d92ddc5
promotion
tcsc Mar 23, 2022
660f90c
promotion
tcsc Mar 23, 2022
e489ef6
Restore full drone
tcsc Mar 23, 2022
c0f6435
Merge remote-tracking branch 'origin/master' into tcsc/terraform-prom…
tcsc Mar 23, 2022
7bb4452
Merge remote-tracking branch 'origin/master' into tcsc/terraform-prom…
tcsc Mar 28, 2022
115619d
Repack test
tcsc Mar 28, 2022
d78e511
Fix filename tests
tcsc Mar 28, 2022
473d3f8
Merge branch 'master' into tcsc/terraform-promotion-script
tcsc Mar 28, 2022
0c168a8
Update tooling/internal/terraform/registry/sha.go
tcsc Mar 30, 2022
55271c8
Review concerns
tcsc Mar 31, 2022
bef690a
Added concurrenvy warning to updateRegistry()
tcsc Mar 31, 2022
0a5d5e2
Drone updates
tcsc Mar 31, 2022
1c7d218
Merge branch 'master' into tcsc/terraform-promotion-script
tcsc Mar 31, 2022
8686394
Update parse.go
tcsc Mar 31, 2022
aa94aa0
Merge branch 'tcsc/terraform-promotion-script' of github.com:gravitat…
tcsc Mar 31, 2022
d57fac2
Adds role awareness to upload script
tcsc Apr 21, 2022
b2a75d7
Merge remote-tracking branch 'origin/master' into tcsc/terraform-prom…
tcsc Apr 21, 2022
f1c2b2a
Merge remote-tracking branch 'origin/master' into tcsc/terraform-prom…
tcsc Apr 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 96 additions & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,102 @@ volumes:
temp: {}

---
kind: pipeline
type: kubernetes
name: tag-stage-terraform-provider

trigger:
event:
- tag
ref:
include:
- refs/tags/terraform-provider-teleport-v*

depends_on:
- tag-build-terraform-linux
- tag-build-terraform-darwin

concurrency:
limit: 1

steps:
- name: Upload terraform provider to staging registry
image: golang:1.17.5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, we could parameterise the required Go version as it seems equal for the whole suite (if Drone allows it).

commands:
- cd tooling
- |
go run ./cmd/promote-terraform \
--tag ${DRONE_TAG} \
-p 4.0 -p 5.1 \
--namespace gravitational \
--name teleport

environment:
STAGING_REGION: us-east-2
STAGING_BUCKET:
from_secret: AWS_S3_BUCKET
STAGING_ACCESS_KEY_ID:
from_secret: AWS_ACCESS_KEY_ID
STAGING_SECRET_ACCESS_KEY:
from_secret: AWS_SECRET_ACCESS_KEY

PRODUCTION_REGION: us-east-2
PROD_BUCKET:
from_secret: STAGING_AWS_TERRAFORM_BUCKET
PROD_ACCESS_KEY_ID:
from_secret: STAGING_AWS_TERRAFORM_ACCESS_KEY_ID
PROD_SECRET_ACCESS_KEY:
from_secret: STAGING_AWS_TERRAFORM_SECRET_ACCESS_KEY

SIGNING_KEY:
from_secret: STAGING_TERRAFORM_REGISTRY_SIGNING_KEY
---
kind: pipeline
type: kubernetes
name: promote-terraform-provider

trigger:
event:
- promote
target:
- production
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like to add both production and a pipeline specific production-terraform as triggers on promotion steps. This allows rerunning only the production-terraform step if something goes wrong with it without needing to rerun the entire pipeline -- good for speed and also not re-uploading other artifacts unnecessarily.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent idea. Added an explicit staging build as well for this same reason


concurrency:
limit: 1

steps:
- name: Promote terraform provider to public registry
image: golang:1.17.5
commands:
- cd tooling
- |
go run ./cmd/promote-terraform \
--tag ${DRONE_TAG} \
-p 4.0 -p 5.1 \
--namespace gravitational \
--name teleport

environment:
STAGING_REGION: us-east-2
STAGING_BUCKET:
from_secret: AWS_S3_BUCKET
STAGING_ACCESS_KEY_ID:
from_secret: AWS_ACCESS_KEY_ID
STAGING_SECRET_ACCESS_KEY:
from_secret: AWS_SECRET_ACCESS_KEY

PRODUCTION_REGION: ap-southeast-2
tcsc marked this conversation as resolved.
Show resolved Hide resolved
PROD_BUCKET:
from_secret: PRODUCTION_AWS_TERRAFORM_BUCKET
PROD_ACCESS_KEY_ID:
from_secret: PRODUCTION_AWS_TERRAFORM_ACCESS_KEY_ID
PROD_SECRET_ACCESS_KEY:
from_secret: PRODUCTION_AWS_TERRAFORM_SECRET_ACCESS_KEY

SIGNING_KEY:
from_secret: PRODUCTION_TERRAFORM_REGISTRY_SIGNING_KEY
---
kind: signature
hmac: 9f4c1a36000b9b2637e790418a624a31c162e2bb248cc6718a1c28a82a8b10c4
hmac: 7c3217716b77812d57ebf5f3d6965dfef25aedcc6593bd50365903d65bd2b79f

...
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,14 @@ event-handler:

# Run all tests
.PHONY: test
test:
test: test-tooling
@echo Testing plugins against Teleport $(TELEPORT_GET_VERSION)
go test -race -count 1 ./...
go test -race -count 1 $(shell go list ./...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if my comment is applicable here, but looks like. Terraform provider tests need env var TF_ENV=true to be specified (Terraform framework requirement). Terraform must be available as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is change is to avoid go test picking up the tooling module here. For some reason, in my testing, ./... included the tooling package and failed, where $(shell go list ./...) correctly treated it as a separate module.

Just tested it again now an all seems fine.



.PHONY: test-tooling
test-tooling:
(cd tooling; go test -v -race ./...)

# Individual releases
.PHONY: release/access-slack
Expand Down
119 changes: 119 additions & 0 deletions tooling/cmd/promote-terraform/args.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package main

import (
"os"
"strings"

"github.com/gravitational/kingpin"
)

type bucketConfig struct {
region string
bucketName string
accessKeyID string
secretAccessKey string
}

type args struct {
providerTag string
workingDir string
registryURL string
staging bucketConfig
production bucketConfig
signingKeyText string
protocolVersions []string
providerNamespace string
providerName string
verbosity int
}

func parseCommandLine() *args {
app := kingpin.New("promote-terraform", "Adds files to a terraform registry")
result := &args{}

app.Flag("tag", "The version tag identifying version of provider to promote").
Required().
StringVar(&result.providerTag)

app.Flag("staging-bucket", "S3 Staging bucket url (where to fetch tarballs for promotion)").
Envar("STAGING_BUCKET").
Required().
StringVar(&result.staging.bucketName)

app.Flag("staging-region", "AWS region the staging bucket is in").
Envar("STAGING_REGION").
Default("us-west-2").
StringVar(&result.staging.region)

app.Flag("staging-access-key-id", "AWS access key id for staging bucket").
Envar("STAGING_ACCESS_KEY_ID").
Required().
StringVar(&result.staging.accessKeyID)

app.Flag("staging-secret-access-key", "AWS secret access key for staging bucket").
Envar("STAGING_SECRET_ACCESS_KEY").
Required().
StringVar(&result.staging.secretAccessKey)

app.Flag("prod-bucket", "S3 production bucket url (where to push the resulting registry)").
Envar("PROD_BUCKET").
StringVar(&result.production.bucketName)

app.Flag("prod-region", "AWS region the production bucket is in").
Envar("PRODUCTION_REGION").
Default("us-east-1").
StringVar(&result.production.region)

app.Flag("prod-access-key-id", "AWS access key id for production bucket").
Envar("PROD_ACCESS_KEY_ID").
Required().
StringVar(&result.production.accessKeyID)

app.Flag("prod-secret-access-key", "AWS secret access key for production bucket").
Envar("PROD_SECRET_ACCESS_KEY").
Required().
StringVar(&result.production.secretAccessKey)

app.Flag("working-dir", "Working directory to store generated files").
Short('d').
Default("./workspace").
StringVar(&result.workingDir)

app.Flag("signing-key", "GPG signing key in ASCII armor format").
Short('k').
Envar("SIGNING_KEY").
StringVar(&result.signingKeyText)

app.Flag("protocol", "Terraform protocol supported by files").
Short('p').
Default("4.0", "5.1").
StringsVar(&result.protocolVersions)

app.Flag("registry-url", "Address where registry objects will be served.").
Default("https://terraform.releases.teleport.dev/").
StringVar(&result.registryURL)

app.Flag("namespace", "Terraform provider namespace").
Default("gravitational").
StringVar(&result.providerNamespace)

app.Flag("name", "Terraform provider name").
Default("teleport").
StringVar(&result.providerName)

app.Flag("verbose", "Output more trace output").
Short('v').
CounterVar(&result.verbosity)

kingpin.MustParse(app.Parse(os.Args[1:]))

// Marshal the arguments into a canonical format here, so we don't have to
// second guess the format later on when we're in the thick of doing the
// actual work...

if !strings.HasSuffix(result.registryURL, "/") {
result.registryURL = result.registryURL + "/"
}

return result
}
Loading