Skip to content

Commit

Permalink
Merge pull request #31 from wttech/26-implement-aws_ssm-connection-type
Browse files Browse the repository at this point in the history
26 implement aws ssm connection type
  • Loading branch information
krystian-panek-vmltech authored Jan 29, 2024
2 parents 3458365 + 5f60ea8 commit 1c91c2f
Show file tree
Hide file tree
Showing 17 changed files with 340 additions and 100 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ For example:
- `sh develop.sh examples/aws_ssh apply -auto-approve`
- `sh develop.sh examples/aws_ssh destroy -auto-approve`

- `sh develop.sh examples/aws_ssm plan`
- `sh develop.sh examples/aws_ssm apply -auto-approve`
- `sh develop.sh examples/aws_ssm destroy -auto-approve`

## Debugging the Provider

1. Run command `go run . -debug` from IDEA in debug mode and copy the value of `TF_REATTACH_PROVIDERS` from the output.
Expand Down
2 changes: 2 additions & 0 deletions docs/resources/instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ Required:

Optional:

- `action_timeout` (String) Used when trying to connect to the AEM instance machine (often right after creating it). Need to be enough long because various types of connections (like AWS SSM or SSH) may need some time to boot up the agent.
- `credentials` (Map of String, Sensitive) Credentials for the connection type
- `state_timeout` (String) Used when reading the AEM instance state when determining the plan.


<a id="nestedblock--compose"></a>
Expand Down
36 changes: 35 additions & 1 deletion examples/aws_ssh/aem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,15 @@ instance:
timeout: 10m
# Max time in which socket connection to instance should be established
reachable:
skip: false
timeout: 3s
# Bundle state tracking
bundle_stable:
skip: false
symbolic_names_ignored: []
# OSGi events tracking
event_stable:
skip: false
# Topics indicating that instance is not stable
topics_unstable:
- "org/osgi/framework/ServiceEvent/*"
Expand All @@ -91,16 +94,32 @@ instance:
- "org.osgi.service.component.runtime.ServiceComponentRuntime"
- "java.util.ResourceBundle"
received_max_age: 5s
# OSGi components state tracking
component_stable:
skip: false
pids:
include: ['com.day.crx.packaging.*', 'org.apache.sling.installer.*']
exclude: ['org.apache.sling.installer.hc.*', 'org.apache.sling.installer.core.impl.console.*']
match:
"disabled": []
"no config": []
"unsatisfied (reference)": []
"satisfied": []
# Sling Installer tracking
installer:
skip: false
# JMX state checking
state: true
# Pause Installation nodes checking
pause: true
# Specific endpoints / paths (like login page)
path_ready:
timeout: 10s

login_page:
skip: false
path: "/libs/granite/core/content/login.html"
status_code: 200
contained_text: QUICKSTART_HOMEPAGE

# Managed locally (set up automatically)
local:
Expand Down Expand Up @@ -138,6 +157,7 @@ instance:
package:
# Force re-uploading/installing of snapshot AEM packages (just built / unreleased)
snapshot_patterns: [ "**/*-SNAPSHOT.zip" ]
snapshot_ignored: false
# Use checksums to avoid re-deployments when snapshot AEM packages are unchanged
snapshot_deploy_skipping: true
# Disable following workflow launchers for a package deployment time only
Expand All @@ -151,6 +171,16 @@ instance:
console: false
# Fail on case 'installed with errors'
strict: true
# Number of changes after which the commit to the repository is performed
install_save_threshold: 1024
# Allows to relax dependency handling if needed
install_dependency_handling: required
# Controls how 'rep:policy' nodes are handled during import
install_ac_handling: ''

# 'SSL By Default'
ssl:
setup_timeout: 30s

# OSGi Framework
osgi:
Expand All @@ -166,6 +196,10 @@ instance:
crypto:
key_bundle_symbolic_name: com.adobe.granite.crypto.file

# Replication
replication:
bundle_symbolic_name: com.day.cq.cq-replication

# Workflow Manager
workflow:
launcher:
Expand Down
4 changes: 2 additions & 2 deletions examples/aws_ssh/aws.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ resource "aws_iam_instance_profile" "aem_ec2" {
}

resource "aws_iam_role" "aem_ec2" {
name = "${local.workspace}_aem_ec2"
name = "${local.workspace}_aem_ec2"
assume_role_policy = trimspace(<<EOF
{
"Version": "2012-10-17",
Expand All @@ -49,7 +49,7 @@ resource "aws_iam_role" "aem_ec2" {
}
EOF
)
tags = local.tags
tags = local.tags
}

resource "aws_iam_role_policy_attachment" "s3" {
Expand Down
14 changes: 8 additions & 6 deletions examples/aws_ssm/aem.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ resource "aem_instance" "single" {
depends_on = [aws_instance.aem_single, aws_volume_attachment.aem_single_data]

client {
type = "aws_ssm"
type = "aws-ssm"
settings = {
instance_id = aws_instance.aem_single.id
region = "eu-central-1" // TODO infer from AWS provider config
}
}

Expand All @@ -17,21 +16,17 @@ resource "aem_instance" "single" {
"sudo mkfs -t ext4 ${local.aem_single_data_device}",
"sudo mkdir -p ${local.aem_single_data_dir}",
"sudo mount ${local.aem_single_data_device} ${local.aem_single_data_dir}",
"sudo chown -R ${local.ssh_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: https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
"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",
// installing AWS SSM agent: https://docs.aws.amazon.com/systems-manager/latest/userguide/agent-install-rhel-8-9.html
"sudo dnf install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm",
]
}
}

compose {
config = file("aem.yml") // use templating here if needed: https://developer.hashicorp.com/terraform/language/functions/templatefile
create = {
inline = [
"mkdir -p '${local.aem_single_compose_dir}/aem/home/lib'",
Expand All @@ -40,6 +35,13 @@ resource "aem_instance" "single" {
"sh aemw instance create",
]
}
configure = {
inline = [
"sh aemw osgi config save --pid 'org.apache.sling.jcr.davex.impl.servlets.SlingDavExServlet' --input-string 'alias: /crx/server'",
"sh aemw repl agent setup -A --location 'author' --name 'publish' --input-string '{enabled: true, transportUri: \"http://localhost:4503/bin/receive?sling:authRequestLogin=1\", transportUser: admin, transportPassword: admin, userId: admin}'",
"sh aemw package deploy --file 'aem/home/lib/aem-service-pkg-6.5.*.0.zip'",
]
}
}
}

Expand Down
9 changes: 7 additions & 2 deletions examples/aws_ssm/aws.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ resource "aws_instance" "aem_single" {
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 All @@ -25,7 +30,7 @@ resource "aws_iam_instance_profile" "aem_ec2" {
}

resource "aws_iam_role" "aem_ec2" {
name = "${local.workspace}_aem_ec2"
name = "${local.workspace}_aem_ec2"
assume_role_policy = trimspace(<<EOF
{
"Version": "2012-10-17",
Expand All @@ -37,7 +42,7 @@ resource "aws_iam_role" "aem_ec2" {
}
EOF
)
tags = local.tags
tags = local.tags
}

resource "aws_iam_role_policy_attachment" "ssm" {
Expand Down
3 changes: 0 additions & 3 deletions examples/aws_ssm/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ locals {
env_type = "aem-single"
host = "aem_single"

ssh_user = "ec2-user"
ssh_private_key = abspath("ec2-key.cer")

tags = {
Workspace = "aemc"
Env = "tf-minimal"
Expand Down
39 changes: 27 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ module github.com/wttech/terraform-provider-aem
go 1.19

require (
github.com/aws/aws-sdk-go-v2 v1.24.1
github.com/aws/aws-sdk-go-v2/config v1.26.6
github.com/aws/aws-sdk-go-v2/service/ssm v1.44.7
github.com/hashicorp/terraform-plugin-docs v0.16.0
github.com/hashicorp/terraform-plugin-framework v1.4.2
github.com/hashicorp/terraform-plugin-go v0.19.0
github.com/hashicorp/terraform-plugin-framework v1.5.0
github.com/hashicorp/terraform-plugin-go v0.20.0
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/melbahja/goph v1.4.0
github.com/spf13/cast v1.5.1
golang.org/x/crypto v0.15.0
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa
github.com/spf13/cast v1.6.0
golang.org/x/crypto v0.18.0
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a
gopkg.in/yaml.v3 v3.0.1
)

Expand All @@ -21,15 +24,26 @@ require (
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.16.16 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.11 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.10 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.10 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.7.3 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.4 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.10 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.18.7 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.7 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.26.7 // indirect
github.com/aws/smithy-go v1.19.0 // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-hclog v1.6.2 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.6.0 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
Expand All @@ -42,6 +56,7 @@ require (
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/huandu/xstrings v1.4.0 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/kr/fs v0.1.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
Expand All @@ -59,10 +74,10 @@ require (
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/zclconf/go-cty v1.13.2 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240125205218-1f4bbc51befe // indirect
google.golang.org/grpc v1.61.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
)
Loading

0 comments on commit 1c91c2f

Please sign in to comment.