diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6eac3126d001fb0019814be4f6cf60e18e010ce1..9f5fffb56e4659e8b8b01eeb92a98edb77e74fcc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -15,6 +15,7 @@ before_script: - export TF_VAR_INSTANCES_COUNT=${TF_VAR_INSTANCES_COUNT} - export TF_VAR_USER_PASSWORD=${TF_VAR_USER_PASSWORD} - export TF_VAR_LETSENCRYPT_EMAIL=${TF_VAR_LETSENCRYPT_EMAIL} + - export TF_VAR_PROJECT_DOMAIN=${TF_VAR_PROJECT_DOMAIN} - export TF_VAR_ENVIRONMENT=${ENVIRONMENT} stages: diff --git a/README.md b/README.md index 823bd9040f779538236915740f518b7b05d70dbb..1ded645d6f41a29ce80804738759ece7a4adde12 100644 --- a/README.md +++ b/README.md @@ -38,12 +38,14 @@ After deployment, each resource can be accessed though HTTPS depending on their - Username: abc - Password: <Gitlab Stored> -## Cloud-init - file creation +## How to setup configuration file for services + +### cloud-init : file creation In this example, you will find how to create a file to a defined path with cloud-init. Content inside `%` are meant to be replaced with sed command to be able to use environment variables or user-data. -**cloud-init :** +**example:** ```yaml write_files: - content: | @@ -76,6 +78,25 @@ sed -i "s/%atrium_letsencrypt_email%/$(scw-userdata atrium_letsencrypt_email)/g" sed -i "s/%atrium_count_index%/$(scw-userdata atrium_count_index)/g" /root/atrium.yaml ``` +## Downloading file + +The example show how to curl a configuration file from repository to a defined path with cloud-init. + +**example :** +```yaml +runcmd: +# +# cloud-init execute cmd before HOME and USER are set. +# + - "export HOME=/root" + - "export USER=root" +# +# Install Atrium +# + - "curl https://forge.grandlyon.com/systemes-dinformation/alpha/projects/labo-rust/-/raw/develop/instance-scripts/config-files/atrium.yaml -o root/atrium.yaml" + - "curl https://forge.grandlyon.com/systemes-dinformation/alpha/projects/labo-rust/-/raw/develop/instance-scripts/config-files/atrium.sh | bash" +``` + ## Use Gitlab variables in instances ### Example diff --git a/instance-scripts/config-files/atrium.yaml b/instance-scripts/config-files/atrium.yaml index 56c601f19834015ecac6c53e177e9ceb93d87e45..4aff5a306e5775df7ea1162aa0e30f10f2c78a5b 100644 --- a/instance-scripts/config-files/atrium.yaml +++ b/instance-scripts/config-files/atrium.yaml @@ -1,5 +1,5 @@ # The content of this file is recreated by cloud init. -hostname: %atrium_hostname%.daag.alpha.grandlyon.com +hostname: %atrium_hostname%.%project_domain% debug_mode: false letsencrypt_email: %atrium_letsencrypt_email% tls_mode: Auto diff --git a/instance-scripts/scripts/atrium.sh b/instance-scripts/scripts/atrium.sh index a99ed7ee8e6d93d239b8d29126d4788512b3ef57..53ccdcc08ef8697d4c94048d93ded5549fbd1638 100644 --- a/instance-scripts/scripts/atrium.sh +++ b/instance-scripts/scripts/atrium.sh @@ -6,6 +6,7 @@ mkdir -p /root/atrium/data && mkdir -p /root/atrium/letsencrypt_cache sed -i "s/%atrium_hostname%/$(scw-userdata atrium_hostname)/g" /root/atrium.yaml +sed -i "s/%project_domain%/$(scw-userdata project_domain)/g" /root/atrium.yaml sed -i "s/%atrium_letsencrypt_email%/$(scw-userdata atrium_letsencrypt_email)/g" /root/atrium.yaml sed -i "s/%atrium_count_index%/$(scw-userdata atrium_count_index)/g" /root/atrium.yaml mv /root/atrium.yaml /root/atrium/atrium.yaml diff --git a/terraform/main.tf b/terraform/main.tf index 70d8fdf6ba28f55ec1953353419dbcc09118148e..ed0bee7f1aa8707ce939478ce3f6582cb13e5720 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -65,6 +65,7 @@ resource "scaleway_instance_server" "user_instance_server" { security_group_id = scaleway_instance_security_group.www.id user_data = { + project_domain = var.PROJECT_DOMAIN atrium_count_index = count.index atrium_hostname = scaleway_domain_record.subdomain_record[count.index].name atrium_letsencrypt_email = var.LETSENCRYPT_EMAIL diff --git a/terraform/variables-gitlab.tf b/terraform/variables-gitlab.tf index f324f2306af0a3ef5639d2efdecc7618a462e6ec..b8ac5e8094ce7917a34cdfd93069c9c5af6fd5bf 100644 --- a/terraform/variables-gitlab.tf +++ b/terraform/variables-gitlab.tf @@ -18,6 +18,12 @@ variable "SCW_SECRET_KEY" { description = "Scaleway secret key" } +variable "PROJECT_DOMAIN" { + type = string + sensitive = true + description = "External domain from Scaleway" +} + variable "LETSENCRYPT_EMAIL" { type = string sensitive = true