in google_cloud_automlops/provisioning/terraform.py [0:0]
def build(self):
"""Creates all files needed to provision system infrastructure in terraform.
Files created under AutoMLOps/
provision/
environment/
data.tf
iam.tf
main.tf
outputs.tf
provider.tf
variables.tf
variables.auto.tfvars
versions.tf
state_bucket/
main.tf
variables.tf
variables.auto.tfvars
scripts/
provision_resources.sh
"""
# create environment/data.tf
write_file(
filepath=f'{BASE_DIR}provision/environment/data.tf',
text=render_jinja(
template_path=import_files(TERRAFORM_TEMPLATES_PATH + '.environment') / 'data.tf.j2',
generated_license=GENERATED_LICENSE,
required_apis=self.required_apis,
required_iam_roles=IAM_ROLES_RUNNER_SA,
use_ci=self.use_ci
),
mode='w')
# create environment/iam.tf
write_file(
filepath=f'{BASE_DIR}provision/environment/iam.tf',
text=render_jinja(
template_path=import_files(TERRAFORM_TEMPLATES_PATH + '.environment') / 'iam.tf.j2',
generated_license=GENERATED_LICENSE
),
mode='w')
# create environment/main.tf
write_file(
filepath=f'{BASE_DIR}provision/environment/main.tf',
text=render_jinja(
template_path=import_files(TERRAFORM_TEMPLATES_PATH + '.environment') / 'main.tf.j2',
artifact_repo_type=self.artifact_repo_type,
base_dir=BASE_DIR,
deployment_framework=self.deployment_framework,
generated_license=GENERATED_LICENSE,
generated_parameter_values_path=GENERATED_PARAMETER_VALUES_PATH,
naming_prefix=self.naming_prefix,
pipeline_job_submission_service_type=self.pipeline_job_submission_service_type,
schedule_pattern=self.schedule_pattern,
source_repo_type=self.source_repo_type,
use_ci=self.use_ci,
vpc_connector=self.vpc_connector
),
mode='w')
# create environment/outputs.tf
write_file(
filepath=f'{BASE_DIR}provision/environment/outputs.tf',
text=render_jinja(
template_path=import_files(TERRAFORM_TEMPLATES_PATH + '.environment') / 'outputs.tf.j2',
artifact_repo_type=self.artifact_repo_type,
deployment_framework=self.deployment_framework,
generated_license=GENERATED_LICENSE,
pipeline_job_submission_service_type=self.pipeline_job_submission_service_type,
schedule_pattern=self.schedule_pattern,
source_repo_type=self.source_repo_type,
use_ci=self.use_ci
),
mode='w')
# create environment/provider.tf
write_file(
filepath=f'{BASE_DIR}provision/environment/provider.tf',
text=render_jinja(
template_path=import_files(TERRAFORM_TEMPLATES_PATH + '.environment') / 'provider.tf.j2',
generated_license=GENERATED_LICENSE
),
mode='w')
# create environment/variables.tf
write_file(
filepath=f'{BASE_DIR}provision/environment/variables.tf',
text=render_jinja(
template_path=import_files(TERRAFORM_TEMPLATES_PATH + '.environment') / 'variables.tf.j2',
generated_license=GENERATED_LICENSE
),
mode='w')
# create environment/variables.auto.tfvars
if self.deployment_framework == Deployer.CLOUDBUILD.value:
write_file(
filepath=f'{BASE_DIR}provision/environment/variables.auto.tfvars',
text=render_jinja(
template_path=import_files(TERRAFORM_TEMPLATES_PATH + '.environment') / 'variables.auto.tfvars.j2',
artifact_repo_location=self.artifact_repo_location,
artifact_repo_name=self.artifact_repo_name,
build_trigger_location=self.build_trigger_location,
build_trigger_name=self.build_trigger_name,
generated_license=GENERATED_LICENSE,
pipeline_job_runner_service_account=self.pipeline_job_runner_service_account,
pipeline_job_submission_service_location=self.pipeline_job_submission_service_location,
pipeline_job_submission_service_name=self.pipeline_job_submission_service_name,
project_id=self.project_id,
provision_credentials_key=self.provision_credentials_key,
pubsub_topic_name=self.pubsub_topic_name,
schedule_location=self.schedule_location,
schedule_name=self.schedule_name,
schedule_pattern=self.schedule_pattern,
source_repo_branch=self.source_repo_branch,
source_repo_name=self.source_repo_name,
storage_bucket_location=self.storage_bucket_location,
storage_bucket_name=self.storage_bucket_name,
vpc_connector=self.vpc_connector
),
mode='w')
#TODO: implement workload identity as optional
if self.deployment_framework == Deployer.GITHUB_ACTIONS.value:
write_file(
filepath=f'{BASE_DIR}provision/environment/variables.auto.tfvars',
text=render_jinja(
template_path=import_files(TERRAFORM_TEMPLATES_PATH + '.environment') / 'variables.auto.tfvars.j2',
artifact_repo_location=self.artifact_repo_location,
artifact_repo_name=self.artifact_repo_name,
build_trigger_location=self.build_trigger_location,
build_trigger_name=self.build_trigger_name,
generated_license=GENERATED_LICENSE,
pipeline_job_runner_service_account=self.pipeline_job_runner_service_account,
pipeline_job_submission_service_location=self.pipeline_job_submission_service_location,
pipeline_job_submission_service_name=self.pipeline_job_submission_service_name,
project_id=self.project_id,
provision_credentials_key=self.provision_credentials_key,
pubsub_topic_name=self.pubsub_topic_name,
schedule_location=self.schedule_location,
schedule_name=self.schedule_name,
schedule_pattern=self.schedule_pattern,
source_repo_branch=self.source_repo_branch,
source_repo_name=self.source_repo_name,
storage_bucket_location=self.storage_bucket_location,
storage_bucket_name=self.storage_bucket_name,
vpc_connector=self.vpc_connector
),
mode='w')
# create environment/versions.tf
write_file(
filepath=f'{BASE_DIR}provision/environment/versions.tf',
text=render_jinja(
template_path=import_files(TERRAFORM_TEMPLATES_PATH + '.environment') / 'versions.tf.j2',
generated_license=GENERATED_LICENSE,
storage_bucket_name=self.storage_bucket_name
),
mode='w')
# create provision_resources.sh
write_and_chmod(
filepath=GENERATED_RESOURCES_SH_FILE,
text=render_jinja(
template_path=import_files(TERRAFORM_TEMPLATES_PATH) / 'provision_resources.sh.j2',
base_dir=BASE_DIR,
generated_license=GENERATED_LICENSE
))
# create state_bucket/main.tf
write_file(
filepath=f'{BASE_DIR}provision/state_bucket/main.tf',
text=render_jinja(
template_path=import_files(TERRAFORM_TEMPLATES_PATH + '.state_bucket') / 'main.tf.j2',
generated_license=GENERATED_LICENSE
),
mode='w')
# create state_bucket/variables.tf
write_file(
filepath=f'{BASE_DIR}provision/state_bucket/variables.tf',
text=render_jinja(
template_path=import_files(TERRAFORM_TEMPLATES_PATH + '.state_bucket') / 'variables.tf.j2',
generated_license=GENERATED_LICENSE
),
mode='w')
# create state_bucket/variables.auto.tfvars
write_file(
filepath=f'{BASE_DIR}provision/state_bucket/variables.auto.tfvars',
text=render_jinja(
template_path=import_files(TERRAFORM_TEMPLATES_PATH + '.state_bucket') / 'variables.auto.tfvars.j2',
project_id=self.project_id,
storage_bucket_location=self.storage_bucket_location,
storage_bucket_name=self.storage_bucket_name
),
mode='w')