Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: initial version #3

Merged
merged 12 commits into from
Nov 11, 2024
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

# Output from other tools that might be used alongside Terraform/OpenTofu
*.tfvars.json
backend.tf.json
gberenice marked this conversation as resolved.
Show resolved Hide resolved

# Taskit files
.taskit/
Expand All @@ -39,4 +38,4 @@ backend.tf.json
**/*.temp
**/*.bak
**/*.*swp
**/.DS_Store
**/.DS_Store
197 changes: 189 additions & 8 deletions README.md

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
data "external" "list_root_modules" {
count = var.enable_all_root_modules ? 1 : 0
program = [
"bash", "-c",
"ls -d ${path.root}/${var.root_modules_path}/*/ | xargs -n 1 basename | jq -R . | jq -s '{\"root_modules\": join(\",\")}' | jq -s '.[0]'"
]
}
gberenice marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions examples/complete/components/random-pet/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resource "random_pet" "template" {
length = var.length
}
5 changes: 5 additions & 0 deletions examples/complete/components/random-pet/stacks/common.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
stack_settings:
manage_state: true
description: This stack generates random pet names
gberenice marked this conversation as resolved.
Show resolved Hide resolved
tfvars:
enabled: false
4 changes: 4 additions & 0 deletions examples/complete/components/random-pet/stacks/example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
stack_settings:
manage_state: true
tfvars:
enabled: true
gberenice marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
length = 10
4 changes: 4 additions & 0 deletions examples/complete/components/random-pet/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "length" {
description = "The length of the random name"
type = number
}
10 changes: 10 additions & 0 deletions examples/complete/components/random-pet/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = "~> 1.0"

required_providers {
random = {
source = "hashicorp/random"
version = "~> 3.0"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"terraform": {
"backend": {
"s3": {
"workspace_key_prefix": "terraform-spacelift-automation",
"acl": "bucket-owner-full-control",
"bucket": "mp-automation-tfstate",
"dynamodb_table": "mp-automation-tfstate-lock",
"encrypt": true,
"key": "terraform.tfstate",
"region": "us-east-1",
"assume_role": {
"role_arn": "arn:aws:iam::755965222190:role/mp-automation-tfstate"
}
}
}
}
}
12 changes: 12 additions & 0 deletions examples/complete/components/spacelift-automation/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module "automation" {
source = "../../../../"
Comment on lines +1 to +2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused about why we need the root module at examples/complete and this root module. Are they not the same? Do we need the one at the root of complete/ or is it a one or the other thing? Mind sharing your thoughts here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first, I had the root module at examples/complete. It was used to create a simple example to spin up random-pet stack. Then we discussed that it would be useful to show that spacelift-automation can manage itself, so I added its configuration to the expected path - ./examples/complete/components/spacelift-automation/. That's why we have them both 😕

I agree that it's excessive, but we need to cut the examples/complete root module in this case. Does it make sense?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gberenice I think it makes sense if we put a README in examples/complete that provides info on "Go to examples/complete/spacelift-automation to run that root module, it will manage itself like so...". We can do that correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Gowiem removed the root module and added the README.md 👍


github_enterprise = var.github_enterprise
repository = var.repository
branch = var.branch

root_modules_path = var.root_modules_path
enable_all_root_modules = var.enable_all_root_modules

aws_integration_id = var.aws_integration_id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider grouping related variables

The variables could be organized better by grouping related configurations together using spacing and comments. This improves readability and maintenance.

Consider this organization:

 module "automation" {
   source = "../../../../"

+  # GitHub Configuration
   github_enterprise = var.github_enterprise
   repository        = var.repository
   branch            = var.branch

+  # Module Configuration
   root_modules_path       = var.root_modules_path
   enable_all_root_modules = var.enable_all_root_modules

+  # Integration Configuration
   aws_integration_id = var.aws_integration_id
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
github_enterprise = var.github_enterprise
repository = var.repository
branch = var.branch
root_modules_path = var.root_modules_path
enable_all_root_modules = var.enable_all_root_modules
aws_integration_id = var.aws_integration_id
# GitHub Configuration
github_enterprise = var.github_enterprise
repository = var.repository
branch = var.branch
# Module Configuration
root_modules_path = var.root_modules_path
enable_all_root_modules = var.enable_all_root_modules
# Integration Configuration
aws_integration_id = var.aws_integration_id

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
stack_settings:
administrative: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
stack_settings:
description: This Automation stack is used for Masterpoint's testing purposes
tfvars:
enabled: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider adding more configuration examples.

Since this is an example stack that others might reference when implementing their own configurations, it would be valuable to showcase more available configuration options mentioned in the README (e.g., administrative settings, worker pool configurations, integration settings).

Consider adding more configuration examples:

stack_settings:
  description: This Automation stack demonstrates Spacelift configuration capabilities and is used for Masterpoint's integration testing
  administrative:
    autoApply: false
    branch: main
  worker_pool: "default"
  labels:
    - environment:example
    - team:infrastructure
tfvars:
  enabled: true
  aws_integration:
    space_name: "example-space"
    role_arn: "arn:aws:iam::123456789012:role/example-role"

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
github_enterprise = {
namespace = "masterpointio"
}
repository = "terraform-spacelift-automation"
branch = "feature/initial-version" # TODO: remove this
root_modules_path = "../../../../examples/complete/components"
enable_all_root_modules = true
aws_integration_id = "01J30JBKQTCD72ATZCRWHYST3C"
35 changes: 35 additions & 0 deletions examples/complete/components/spacelift-automation/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
variable "aws_integration_id" {
type = string
description = "ID of the AWS integration to attach."
}

variable "branch" {
type = string
description = "Specify which branch to use within the infrastructure repository."
default = "main"
}

variable "enable_all_root_modules" {
type = bool
description = "When set to true, all subdirectories in root_modules_path will be treated as root modules."
default = false
}

variable "github_enterprise" {
type = object({
namespace = string
id = optional(string)
})
description = "The GitHub VCS settings"
}

variable "repository" {
type = string
description = "The name of your infrastructure repo"
}

variable "root_modules_path" {
type = string
description = "The path, relative to the root of the repository, where the root module can be found."
default = "root-modules"
}
14 changes: 14 additions & 0 deletions examples/complete/components/spacelift-automation/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
terraform {
required_version = "~> 1.0"

required_providers {
spacelift = {
source = "spacelift-io/spacelift"
version = "~> 1.14"
}
external = {
source = "hashicorp/external"
version = "~> 2.0"
}
}
}
Loading