Skip to content

Commit

Permalink
Schema fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
krystian-panek-vmltech committed Aug 27, 2023
1 parent ca8f770 commit ca2827d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 27 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@ resource "aws_instance" "aem_author" {
resource "aem_instance" "author" {
depends_on = [aws_instance.aem_author]
config {
compose {
root_dir = "/mnt/aemc"
version = "1.4.1"
lib_dir = "lib" # files copied once over SCP before creating instance
file = "aem.yml" # https://github.com/wttech/aemc/blob/0ca8bdeb17be0457ce4bea43621d8abe08948431/pkg/project/app_classic/aem/default/etc/aem.yml
config_file = "aem.yml" # https://github.com/wttech/aemc/blob/0ca8bdeb17be0457ce4bea43621d8abe08948431/pkg/project/app_classic/aem/default/etc/aem.yml
instance_id = "local_author"
}
connection {
client {
type = "aws_ssm"
params = {
instance_id: aws_instance.aem_author.id
instance_id = aws_instance.aem_author.id
}
/*
type = "ssh"
Expand Down
5 changes: 4 additions & 1 deletion develop.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

RED='\033[0;31m'
NC='\033[0m'

TF_DIR=$1
if [ -z "$TF_DIR" ]
then
Expand All @@ -12,7 +15,7 @@ go install .
BUILD_STATUS="$?"
if [ "$BUILD_STATUS" -ne 0 ]
then
echo "Build error (exit code $BUILD_STATUS)"
echo "${RED}Build error (exit code $BUILD_STATUS)${NC}"
exit 1
fi

Expand Down
6 changes: 2 additions & 4 deletions examples/minimal/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,14 @@ resource "aem_instance" "author" {
host = aws_instance.aem_author.public_ip
port = 22
user = "ec2-user"
private_key = local.ssh_private_key // TODO hide it
private_key = local.ssh_private_key // TODO hide it in TF console outputs
}
}
compose {
data_dir = "/data/aemc"
version = "1.4.1"
lib_dir = "lib"
config_file = "aem.yml"
instance_id = "local_author"
}
machine {
data_dir = "/data/aemc"
}
}
30 changes: 12 additions & 18 deletions internal/provider/instance_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ type InstanceResourceModel struct {
Type types.String `tfsdk:"type"`
Settings types.Map `tfsdk:"settings"`
} `tfsdk:"client"`
Machine struct {
DataDir types.String `tfsdk:"data_dir"`
} `tfsdk:"machine"`
Compose struct {
DataDir types.String `tfsdk:"data_dir"`
Version types.String `tfsdk:"version"`
ConfigFile types.String `tfsdk:"config_file"`
LibDir types.String `tfsdk:"lib_dir"`
Expand All @@ -59,40 +57,36 @@ func (r *InstanceResource) Schema(ctx context.Context, req resource.SchemaReques
},
},
},
"machine": schema.SingleNestedBlock{
"compose": schema.SingleNestedBlock{
Attributes: map[string]schema.Attribute{
"data_dir": schema.StringAttribute{
MarkdownDescription: "Root path which AEM instance(s) will be stored",
MarkdownDescription: "Remote path in which AEM Compose data will be stored",
Computed: true,
Optional: true,
Default: stringdefault.StaticString("/data/aemc"),
Default: stringdefault.StaticString("/mnt/aemc"),
},
},
},
"compose": schema.SingleNestedBlock{
Attributes: map[string]schema.Attribute{
"version": schema.StringAttribute{
MarkdownDescription: "Version of AEM Compose CLI to use",
MarkdownDescription: "Version of AEM Compose tool to use on remote AEM machine",
Computed: true,
Optional: true,
Default: stringdefault.StaticString("1.4.1"),
},
"instance_id": schema.StringAttribute{
MarkdownDescription: "ID of the AEM instance to use (one of the instances defined in the configuration file)",
Optional: true,
},
"config_file": schema.StringAttribute{
MarkdownDescription: "Path to the AEM configuration file",
MarkdownDescription: "Local path to the AEM configuration file",
Computed: true,
Optional: true,
Default: stringdefault.StaticString("aem.yml"),
},
"lib_dir": schema.StringAttribute{
MarkdownDescription: "Path to the AEM library directory",
MarkdownDescription: "Local path to directory from which AEM library files will be copied to the remote AEM machine",
Computed: true,
Optional: true,
Default: stringdefault.StaticString("lib"),
},
"instance_id": schema.StringAttribute{
MarkdownDescription: "ID of the AEM instance to use (one of the instances defined in the configuration file)",
Optional: true,
},
},
},
},
Expand Down Expand Up @@ -144,7 +138,7 @@ func (r *InstanceResource) Create(ctx context.Context, req resource.CreateReques

tflog.Trace(ctx, "creating AEM instance resource")

if err := conn.CopyFile(data.Compose.ConfigFile.String(), fmt.Sprintf("%s/aem/default/etc/aem.yml", data.Machine.DataDir.String())); err != nil {
if err := conn.CopyFile(data.Compose.ConfigFile.String(), fmt.Sprintf("%s/aem/default/etc/aem.yml", data.Compose.DataDir.String())); err != nil {
resp.Diagnostics.AddError("AEM instance error", fmt.Sprintf("Unable to copy AEM configuration file, got error: %s", err))
return
}
Expand Down

0 comments on commit ca2827d

Please sign in to comment.