Skip to content

Commit

Permalink
Merge pull request #178 from utilitywarehouse/as-git-mirror
Browse files Browse the repository at this point in the history
migrate to git-mirror to support different revision / module
  • Loading branch information
asiyani authored Mar 21, 2024
2 parents fa19519 + 6fbf3f4 commit 2ac8365
Show file tree
Hide file tree
Showing 27 changed files with 554 additions and 1,194 deletions.
34 changes: 19 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ kind: Module
metadata:
name: hello
spec:
repoName: terraform-applier
repoURL: git@github.com:utilitywarehouse/terraform-applier.git
repoRef: master
path: dev/hello
schedule: "00 */1 * * *"
planOnly: false
Expand Down Expand Up @@ -143,26 +144,29 @@ it will not do `apply` even if drift is detected.
Controller will force shutdown on current stage run if it takes more time then `TERMINATION_GRACE_PERIOD` set on controller.
### Git Sync
Terraform-applier has built in git sync functionality, it will periodically pull files down from a repository and make it available for modules.
it supports multiple repositories, use following config to add repositories. config is map of repository name and repo config.
modules must use this repository name in CRD as `repoName` to reference a repository. git-sync only supports 1 branch and revision per repository.
all repositories will be cloned to given `repos-root-path` path.
Terraform-applier uses [git-mirror](https://github.com/utilitywarehouse/git-mirror) package to sync git repositories.
This package supports mirroring multiple repositories and all available references.
Because of this terraform-applier can also support different revisions on same repo. it can be set in module CRD by `repoRef` field.
Use following config to add repositories. supported urls formats are
'git@host.xz:org/repo.git','ssh://git@host.xz/org/repo.git' or 'https://host.xz/org/repo.git'
```yaml
repositories:
terraform-applier:
remote: git@github.com:utilitywarehouse/terraform-applier.git
branch: master
revision: HEAD
depth: 0
another-repo:
remote: git@github.com/org/another-repo.git
git_mirror:
defaults:
interval: 1m # defaults to 30s
git_gc: always # defaults to always
auth:
ssh_key_path: /etc/git-secret/ssh # defaults to --git-ssh-key-file flag
ssh_known_hosts_path: /etc/git-secret/known_hosts # defaults to --git-ssh-known-hosts
repositories:
- remote: git@github.com:utilitywarehouse/terraform-applier.git
- remote: git@github.com:utilitywarehouse/other-repo.git
```

### Controller config

- `--repos-root-path (REPOS_ROOT_PATH)` - (default: `/src`) Absolute path to the directory containing all repositories of the modules. The immediate subdirectories of this directory should contain the module repo directories and directory name should match repoName referenced in module.
- `--repos-root-path (REPOS_ROOT_PATH)` - (default: `/src`) Absolute path to the directory containing all repositories of the modules.
This dir will be cleared on start.
- `--config (TF_APPLIER_CONFIG)` - (default: `/config/config.yaml`) Path to the tf applier config file containing repository config.
- `--min-interval-between-runs (MIN_INTERVAL_BETWEEN_RUNS)` - (default: `60`) The minimum interval in seconds, user can set between 2 consecutive runs. This value defines the frequency of runs.
- `--termination-grace-period (TERMINATION_GRACE_PERIOD)` - (default: `60`) Termination grace period is the ime given to
Expand Down
11 changes: 11 additions & 0 deletions api/v1beta1/module_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,19 @@ type ModuleSpec struct {
// Important: Run "make" to regenerate code after modifying this file

// Name of the repository containing Terraform module directory.
// +optional
RepoName string `json:"repoName"`

// URL to the repository containing Terraform module source code.
// +optional
RepoURL string `json:"repoURL"`

// The RepoRef specifies the revision of the repository for the module source code.
// this can be tag or branch. If not specified, this defaults to "HEAD" (repo's default branch)
// +optional
// +kubebuilder:default=HEAD
RepoRef string `json:"repoRef,omitempty"`

// Path to the directory containing Terraform Root Module (.tf) files.
Path string `json:"path"`

Expand Down
4 changes: 2 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package main
import (
"os"

"github.com/utilitywarehouse/terraform-applier/git"
"github.com/utilitywarehouse/git-mirror/pkg/mirror"
"gopkg.in/yaml.v2"
)

type Config struct {
Repositories map[string]git.RepositoryConfig `yaml:"repositories"`
GitMirror mirror.RepoPoolConfig `yaml:"git_mirror"`
}

func parseConfigFile(path string) (*Config, error) {
Expand Down
16 changes: 10 additions & 6 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
repositories:
terraform-applier:
remote: git@github.com:utilitywarehouse/terraform-applier.git
branch: master
revision: HEAD
depth: 0
git_mirror:
defaults:
root: /src
interval: 30s
git_gc: always
auth:
ssh_key_path: /etc/git-secret/ssh
ssh_known_hosts_path: /etc/git-secret/known_hosts
repositories:
- remote: git@github.com:utilitywarehouse/terraform-applier.git
Loading

0 comments on commit 2ac8365

Please sign in to comment.