Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
kubernetes-infra-example
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cloud
kubernetes
kubernetes-infra-example
Commits
6e972896
Verified
Commit
6e972896
authored
1 year ago
by
Ing. Klára Moravcová
Browse files
Options
Downloads
Patches
Plain Diff
Init script improvement.
parent
1a2293cf
Branches
Branches containing commit
Tags
v10.2.0
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
terraform/init.sh
+19
-20
19 additions, 20 deletions
terraform/init.sh
with
19 additions
and
20 deletions
terraform/init.sh
+
19
−
20
View file @
6e972896
#!/bin/bash
#!/bin/bash
PROJECT_NAME
=
$(
openstack application credential show
${
OS_APPLICATION_CREDENTIAL_ID
}
-f
value
-c
name
)
PROJECT_NAME
=
$(
openstack application credential show
${
OS_APPLICATION_CREDENTIAL_ID
}
-f
value
-c
name
)
PROJECT_ID
=
$(
openstack application credential show
${
OS_APPLICATION_CREDENTIAL_ID
}
-f
value
-c
project_id
)
INFRA_NAME
=
$(
grep
-oP
'infra_name\s*=\s*"\K[^"]+'
main.tf |
awk
'{print $1}'
)
INFRA_NAME
=
$(
grep
-oP
'infra_name\s*=\s*"\K[^"]+'
main.tf |
awk
'{print $1}'
)
# Check if the container already exists
CONTAINER_NAME
=
"
$PROJECT_NAME
-
$INFRA_NAME
-tf-backend"
if
openstack container show
"
$
PROJECT_NAME
-
$INFRA_NAME
-tf-backend
"
>
/dev/null 2>&1
;
then
if
openstack container show
"
$
CONTAINER_NAME
"
>
/dev/null 2>&1
;
then
echo
"Container already exists, skipping creation."
echo
"Container already exists, skipping creation."
else
else
# Container doesn't exist, create it
# Container doesn't exist, create it
openstack container create
"
$
PROJECT_NAME
-
$INFRA_NAME
-tf-backend
"
openstack container create
"
$
CONTAINER_NAME
"
echo
"Container created."
echo
"Container created."
fi
fi
# Check if EC2 credentials already exist
# Check if EC2 credentials already exist
existing_credentials
=
$(
openstack ec2 credentials list
-f
value |
grep
-c
'^'
)
existing_credentials
=
$(
openstack ec2 credentials list
-f
value
-c
"Project ID"
|
grep
${
PROJECT_ID
}
|
grep
-c
'^'
)
if
[
"
$existing_credentials
"
-gt
0
]
;
then
if
[
"
$existing_credentials
"
-gt
0
]
;
then
access
=
$(
openstack ec2 credentials list
-f
value |
head
-n
1
|
awk
'{print $1}'
)
access
=
$(
openstack ec2 credentials list
-f
value |
grep
${
PROJECT_ID
}
|
awk
'{print $1}'
)
secret
=
$(
openstack ec2 credentials list
-f
value |
head
-n
1
|
awk
'{print $2}'
)
secret
=
$(
openstack ec2 credentials list
-f
value |
grep
${
PROJECT_ID
}
|
awk
'{print $2}'
)
echo
"EC2 credentials already exist, skipping creation."
echo
"EC2 credentials already exist, skipping creation."
else
else
# Create new EC2 credentials
# Create new EC2 credentials
...
@@ -21,26 +22,23 @@ else
...
@@ -21,26 +22,23 @@ else
access
=
$(
echo
"
$CREDENTIALS
"
|
grep
-o
'access="[^"]*"'
|
cut
-d
'"'
-f2
)
access
=
$(
echo
"
$CREDENTIALS
"
|
grep
-o
'access="[^"]*"'
|
cut
-d
'"'
-f2
)
secret
=
$(
echo
"
$CREDENTIALS
"
|
grep
-o
'secret="[^"]*"'
|
cut
-d
'"'
-f2
)
secret
=
$(
echo
"
$CREDENTIALS
"
|
grep
-o
'secret="[^"]*"'
|
cut
-d
'"'
-f2
)
echo
"EC2 credentials created."
echo
"EC2 credentials created."
fi
fi
if
[
-f
".tf-s3-creds"
]
;
then
cat
>
.tf-s3-creds
<<
EOL
echo
"Credential file already exists, skipping creation."
[default]
else
aws_access_key_id=
${
access
}
cat
>
.tf-s3-creds
<<
EOL
aws_secret_access_key=
${
secret
}
[default]
aws_access_key_id=
${
access
}
aws_secret_access_key=
${
secret
}
EOL
EOL
echo
"Credential file created."
echo
"Credential file created."
fi
cat
>
backend.tf
<<
EOL
cat
>
backend.tf
<<
EOL
terraform {
terraform {
backend "s3" {
backend "s3" {
endpoints = { s3 = "
https://object-store.cloud.muni.cz/
"}
endpoints = { s3 = "
$(
openstack version show
-c
Endpoint
-f
value |
grep
object-store |
sed
's/\/swift\/v1\///'
)
"}
shared_credentials_files = ["./.tf-s3-creds"]
shared_credentials_files = ["./.tf-s3-creds"]
bucket = "
$
PROJECT_NAME
-
$INFRA_NAME
-tf-backend
"
bucket = "
$
CONTAINER_NAME
"
use_path_style = true
use_path_style = true
key = "terraform.tfstate"
key = "terraform.tfstate"
region = "brno1"
workspace_key_prefix = "
$(
openstack container show
$CONTAINER_NAME
-c
account
-f
value
)
"
region = "
$(
openstack region list
-c
Region
-f
value
)
"
skip_credentials_validation = true
skip_credentials_validation = true
skip_region_validation = true
skip_region_validation = true
skip_requesting_account_id = true
skip_requesting_account_id = true
...
@@ -48,4 +46,5 @@ cat > backend.tf << EOL
...
@@ -48,4 +46,5 @@ cat > backend.tf << EOL
skip_s3_checksum = true
skip_s3_checksum = true
}
}
}
}
EOL
EOL
\ No newline at end of file
echo
"Backend file created."
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment