Skip to content

Commit

Permalink
Merge pull request #12 from rhythmictech/ENG-1006
Browse files Browse the repository at this point in the history
Eng 1006 changes
  • Loading branch information
dgoodellrhy authored Aug 31, 2020
2 parents 1bc2747 + 5012411 commit bd067a8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ This module bridges the gap allowing Terraform to create EC2 Image Builder compo
| component\_version | Version of the component | `string` | n/a | yes |
| name | name to use for component | `string` | n/a | yes |
| playbook\_repo | git url for repo where ansible code lives | `string` | n/a | yes |
| additional\_packages | Space separate list of additional packages that may be needed for your ansible | `string` | `""` | no |
| change\_description | description of changes since last version | `string` | `null` | no |
| cloudformation\_timeout | How long to wait (in minutes) for CFN to apply before giving up | `number` | `10` | no |
| data\_uri | Use this to override the component document with one at a particualar URL endpoint | `string` | `null` | no |
Expand Down
7 changes: 6 additions & 1 deletion component.yml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ phases:
inputs:
commands:
# Install Ansible dependencies
- sudo yum install -y python python3 python-pip python3-pip git
- sudo yum install -y python python3 python-pip python3-pip git ${additional_pkgs}
# Enable Ansible repository
- sudo amazon-linux-extras enable ansible2
# Install Ansible
Expand Down Expand Up @@ -49,6 +49,11 @@ phases:
%{~ if playbook_dir != null ~}
- cd ${playbook_dir}
%{~ endif ~}
%{~ if ssh_key_name != null ~}
- ssh-keyscan -p ${repo_port} ${repo_host} >> ~/.ssh/known_hosts
- eval "$(ssh-agent -s)"
- ssh-add ~/.ssh/git_rsa
%{~ endif ~}
# Install playbook dependencies
- ansible-galaxy install -f -r requirements.yml || true
# Wait for cloud-init
Expand Down
19 changes: 10 additions & 9 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ locals {
has_ssh_key = var.ssh_key_secret_arn != null || var.ssh_key_secret_name != null

data = templatefile("${path.module}/component.yml.tpl", {
description = var.description
name = var.name
playbook_dir = var.playbook_dir
playbook_file = var.playbook_file
playbook_repo = var.playbook_repo
repo_host = try(local.repo_parts.host, null)
repo_port = coalesce(local.repo_parts.port, 22)
ssh_key_name = try(data.aws_secretsmanager_secret.ssh_key[0].name, null)
additional_pkgs = var.additional_packages
description = var.description
name = var.name
playbook_dir = var.playbook_dir
playbook_file = var.playbook_file
playbook_repo = var.playbook_repo
repo_host = try(local.repo_parts.host, null)
repo_port = coalesce(local.repo_parts.port, 22)
ssh_key_name = try(data.aws_secretsmanager_secret.ssh_key[0].name, null)
})

repo_parts = try(
regex(
"^(?P<protocol>\\w+)://(?:(?P<user>\\w+)@)?(?P<host>[\\w\\._-]+)(?::(?P<port>\\d+))?/(?P<git_user>[\\w_-]+)/(?P<repo>[\\w_-]+).git$",
"^(?P<protocol>\\w+)://(?:(?P<user>\\w+)@)?(?P<host>[\\w\\._-]+)(?::(?P<port>\\d+))?/(?P<git_user>[\\w_-]+)/(?P<repo>[\\w_-]+).git(?:\\s*\\-b\\s*[\\w_-]+)?$",
var.playbook_repo
),
null
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
variable "additional_packages" {
default = ""
description = "Space separate list of additional packages that may be needed for your ansible"
type = string
}

variable "change_description" {
default = null
description = "description of changes since last version"
Expand Down

0 comments on commit bd067a8

Please sign in to comment.