Skip to content

Commit

Permalink
Implement 'aws_ssm' connection type #26
Browse files Browse the repository at this point in the history
  • Loading branch information
dominik-przybyl-wttech committed Jan 19, 2024
1 parent 6c418eb commit 681999e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
6 changes: 6 additions & 0 deletions examples/aws_ssm/aem.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ resource "aem_instance" "single" {
}

system {
service_config = file("systemd.conf")
data_dir = local.aem_single_compose_dir
bootstrap = {
inline = [
Expand All @@ -20,6 +21,11 @@ resource "aem_instance" "single" {
"sudo mount ${local.aem_single_data_device} ${local.aem_single_data_dir}",
"sudo chown -R ${local.ssm_user} ${local.aem_single_data_dir}",
"echo '${local.aem_single_data_device} ${local.aem_single_data_dir} ext4 defaults 0 0' | sudo tee -a /etc/fstab",
// installing AWS CLI
"sudo yum install -y unzip",
"curl 'https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip' -o 'awscliv2.zip'",
"unzip -q awscliv2.zip",
"sudo ./aws/install --update",
]
}
}
Expand Down
7 changes: 6 additions & 1 deletion examples/aws_ssm/aws.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
resource "aws_instance" "aem_single" {
ami = "ami-025a6a5beb74db87b" // Amazon Linux 2023 AMI
ami = "ami-043e06a423cbdca17" // RHEL 8
instance_type = "m5.xlarge"
iam_instance_profile = aws_iam_instance_profile.aem_ec2.name
tags = local.tags
user_data = trimspace(<<EOF
#!/bin/bash
sudo dnf install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm
EOF
)
}

resource "aws_ebs_volume" "aem_single_data" {
Expand Down
20 changes: 20 additions & 0 deletions examples/aws_ssm/systemd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[Unit]
Description=AEM Instances
Requires=network.target multi-user.target
After=cloud-final.service

[Service]
Type=forking
User=[[.USER]]

ExecStart=sudo sh -c ". /etc/profile && cd [[.DATA_DIR]] && sh aemw instance start"
ExecStop=sudo sh -c ". /etc/profile && cd [[.DATA_DIR]] && sh aemw instance stop"
ExecReload=sudo sh -c ". /etc/profile && cd [[.DATA_DIR]] && sh aemw instance restart"
KillMode=process
RemainAfterExit=yes
TimeoutStartSec=1810
TimeoutStopSec=190
LimitNOFILE=20000

[Install]
WantedBy=cloud-init.target
6 changes: 3 additions & 3 deletions internal/provider/instance/systemd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ After=cloud-final.service
Type=forking
User=[[.USER]]

ExecStart=sudo sh -c ". /etc/profile && cd [[.DATA_DIR]] && sh aemw instance start"
ExecStop=sudo sh -c ". /etc/profile && cd [[.DATA_DIR]] && sh aemw instance stop"
ExecReload=sudo sh -c ". /etc/profile && cd [[.DATA_DIR]] && sh aemw instance restart"
ExecStart=sh -c ". /etc/profile && cd [[.DATA_DIR]] && sh aemw instance start"
ExecStop=sh -c ". /etc/profile && cd [[.DATA_DIR]] && sh aemw instance stop"
ExecReload=sh -c ". /etc/profile && cd [[.DATA_DIR]] && sh aemw instance restart"
KillMode=process
RemainAfterExit=yes
TimeoutStartSec=1810
Expand Down
5 changes: 1 addition & 4 deletions internal/provider/instance_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (ic *InstanceClient) installComposeCLI() error {
}
if !exists {
tflog.Info(ic.ctx, "Downloading AEM Compose CLI wrapper")
out, err := ic.cl.RunShellCommand("curl -s 'https://raw.githubusercontent.com/wttech/aemc/main/pkg/project/common/aemw' -o 'aemw' && chmod +x 'aemw'", ic.dataDir())
out, err := ic.cl.RunShellCommand("curl -s 'https://raw.githubusercontent.com/wttech/aemc/main/pkg/project/common/aemw' -o 'aemw'", ic.dataDir())
tflog.Info(ic.ctx, string(out))
if err != nil {
return fmt.Errorf("cannot download AEM Compose CLI wrapper: %w", err)
Expand Down Expand Up @@ -126,9 +126,6 @@ func (ic *InstanceClient) configureService() error {
if err := ic.cl.FileWrite(serviceFile, serviceTemplated); err != nil {
return fmt.Errorf("unable to write AEM system service definition '%s': %w", serviceFile, err)
}
if err := ic.cl.FileMakeExecutable(serviceFile); err != nil {
return fmt.Errorf("unable to make executable AEM system service definition '%s': %w", serviceFile, err)
}

if err := ic.runServiceAction("enable"); err != nil {
return err
Expand Down

0 comments on commit 681999e

Please sign in to comment.