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

Scaleway: Migrate root module to Spacelift #1401

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions terraform/scaleway/spacelift/backend-vars/main.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (C) Nicolas Lamirault <nicolas.lamirault@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

endpoint = "https://s3.fr-par.scw.cloud"
region = "fr-par"
bucket = "portefaix-sandbox-tfstates"
key = "spacelift/terraform.tfstate"
23 changes: 23 additions & 0 deletions terraform/scaleway/spacelift/backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright (C) Nicolas Lamirault <nicolas.lamirault@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

terraform {
backend "s3" {
skip_credentials_validation = true
skip_region_validation = true
skip_requesting_account_id = true
}
}
90 changes: 90 additions & 0 deletions terraform/scaleway/spacelift/contexts.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Copyright (C) Nicolas Lamirault <nicolas.lamirault@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

resource "spacelift_context" "this" {
for_each = toset(var.environments)

name = format("scaleway-%s", each.value)
space_id = spacelift_space.environment[each.value].id
description = "Created by Terraform"
labels = local.labels
}

resource "spacelift_environment_variable" "scw_access_key" {
for_each = var.stacks

name = "SCW_ACCESS_KEY"
context_id = spacelift_context.this[each.value.environment].id
value = var.scw_access_key
write_only = true
}

resource "spacelift_environment_variable" "scw_secret_key" {
for_each = var.stacks

name = "SCW_SECRET_KEY"
context_id = spacelift_context.this[each.value.environment].id
value = var.scw_secret_key
write_only = true
}

resource "spacelift_environment_variable" "scw_default_organization_id" {
for_each = var.stacks

name = "SCW_DEFAULT_ORGANIZATION_ID"
context_id = spacelift_context.this[each.value.environment].id
value = var.scw_default_organization_id
write_only = true
}

resource "spacelift_environment_variable" "scw_default_project_id" {
for_each = var.stacks

name = "SCW_DEFAULT_PROJECT_ID"
context_id = spacelift_context.this[each.value.environment].id
value = var.scw_default_project_id
write_only = true
}

resource "spacelift_environment_variable" "aws_acces_key_id" {
for_each = var.stacks

# context_id = spacelift_context.this.id
context_id = spacelift_context.this[each.value.environment].id
name = "AWS_ACCESS_KEY_ID"
value = var.aws_access_key_id
write_only = true
}

resource "spacelift_environment_variable" "aws_secret_access_key" {
for_each = var.stacks

# context_id = spacelift_context.this.id
context_id = spacelift_context.this[each.value.environment].id
name = "AWS_SECRET_ACCESS_KEY"
value = var.aws_secret_access_key
write_only = true
}

resource "spacelift_environment_variable" "aws_default_region" {
for_each = var.stacks

# context_id = spacelift_context.this.id
context_id = spacelift_context.this[each.value.environment].id
name = "AWS_SECRET_ACCESS_KEY"
value = var.aws_default_region
write_only = true
}
19 changes: 19 additions & 0 deletions terraform/scaleway/spacelift/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (C) Nicolas Lamirault <nicolas.lamirault@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

data "spacelift_space" "this" {
space_id = var.root_space_id
}
19 changes: 19 additions & 0 deletions terraform/scaleway/spacelift/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (C) Nicolas Lamirault <nicolas.lamirault@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

locals {
labels = ["scaleway"]
}
30 changes: 30 additions & 0 deletions terraform/scaleway/spacelift/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (C) Nicolas Lamirault <nicolas.lamirault@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

terraform {
required_version = ">= 1.0.0"

required_providers {
scaleway = {
source = "scaleway/scaleway"
version = "2.46.0"
}
spacelift = {
source = "spacelift-io/spacelift"
version = "1.16.1"
}
}
}
15 changes: 15 additions & 0 deletions terraform/scaleway/spacelift/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (C) Nicolas Lamirault <nicolas.lamirault@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
23 changes: 23 additions & 0 deletions terraform/scaleway/spacelift/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright (C) Nicolas Lamirault <nicolas.lamirault@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

provider "scaleway" {
region = var.region
zone = var.zone
}

provider "spacelift" {
}
31 changes: 31 additions & 0 deletions terraform/scaleway/spacelift/spaces.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (C) Nicolas Lamirault <nicolas.lamirault@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

resource "spacelift_space" "this" {
name = var.space
parent_space_id = data.spacelift_space.this.id
description = "Created by Terraform."
labels = concat(local.labels)
}

resource "spacelift_space" "environment" {
for_each = toset(var.environments)

name = format("%s-%s", var.space, each.value)
parent_space_id = spacelift_space.this.id
description = "Created by Terraform."
labels = concat(local.labels, [each.value])
}
41 changes: 41 additions & 0 deletions terraform/scaleway/spacelift/stacks.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (C) Nicolas Lamirault <nicolas.lamirault@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

resource "spacelift_stack" "this" {
for_each = var.stacks

administrative = true
autodeploy = false
branch = each.value.branch
description = "created by Terraform"
name = each.key
project_root = format("%s/%s", each.value.project_root, each.value.environment)
space_id = spacelift_space.environment[each.value.environment].id
protect_from_deletion = false
manage_state = true
terraform_external_state_access = true
terraform_workflow_tool = "OPEN_TOFU"
repository = var.repository
labels = concat(local.labels, each.value.labels, [each.value.environment])
}

resource "spacelift_context_attachment" "this" {
for_each = var.stacks

context_id = spacelift_context.this[each.value.environment].id
stack_id = spacelift_stack.this[each.key].id
priority = 0
}
64 changes: 64 additions & 0 deletions terraform/scaleway/spacelift/tfvars/main.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright (C) Nicolas Lamirault <nicolas.lamirault@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

#####################################################################""
# Provider

region = "fr-par"

zone = "fr-par-1"

##############################################################################
# Spacelift

repository = "portefaix-infrastructure"

space = "scaleway"

environments = ["sandbox"]

stacks = {
portefaix-scaleway-sandbox-vpc = {
project_root = "terraform/scaleway/vpc"
labels = ["core", "vpc"]
environment = "sandbox"
branch = "main"
},
portefaix-scaleway-sandbox-registry = {
project_root = "terraform/scaleway/registry"
labels = ["core", "kapsule"]
environment = "sandbox"
branch = "main"
},
portefaix-scaleway-sandbox-kapsule = {
project_root = "terraform/scaleway/kapsule"
labels = ["core", "kapsule"]
environment = "sandbox"
branch = "main"
},
portefaix-scaleway-sandbox-observability = {
project_root = "terraform/scaleway/observability"
labels = ["core", "stack"]
environment = "sandbox"
branch = "main"
},
portefaix-scaleway-sandbox-eso = {
project_root = "terraform/scaleway/eso"
labels = ["core", "stack"]
environment = "sandbox"
branch = "main"
},
}
Loading
Loading