add tf1.0 example
This commit is contained in:
parent
894a8764ee
commit
1ad655df87
4 changed files with 87 additions and 11 deletions
4
doc/example/20_terrform_1_0/backend.prod.int.properties
Normal file
4
doc/example/20_terrform_1_0/backend.prod.int.properties
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
bucket = "my-configuration"
|
||||||
|
key = "my-module"
|
||||||
|
kms_key_id = "arn:aws:kms:my-kms-alias"
|
||||||
|
region = "my-region"
|
55
doc/example/20_terrform_1_0/build.py
Normal file
55
doc/example/20_terrform_1_0/build.py
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
from os import environ
|
||||||
|
from pybuilder.core import task, init
|
||||||
|
from ddadevops import *
|
||||||
|
|
||||||
|
name = 'my-project'
|
||||||
|
MODULE = 'my-module'
|
||||||
|
PROJECT_ROOT_PATH = '../../..'
|
||||||
|
|
||||||
|
class MyBuild(AwsBackendPropertiesMixin, DevopsTerraformBuild):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@init
|
||||||
|
def initialize(project):
|
||||||
|
project.build_depends_on('ddadevops>=0.13.2')
|
||||||
|
stage = environ['STAGE']
|
||||||
|
print('Doing stage: ', stage)
|
||||||
|
config = create_devops_terraform_build_config(stage,
|
||||||
|
PROJECT_ROOT_PATH,
|
||||||
|
MODULE,
|
||||||
|
{},
|
||||||
|
use_workspace=False,
|
||||||
|
terraform_version=1.0)
|
||||||
|
config = add_aws_backend_properties_mixin_config(config, 'prod')
|
||||||
|
build = MyBuild(project, config)
|
||||||
|
build.initialize_build_dir()
|
||||||
|
|
||||||
|
|
||||||
|
@task
|
||||||
|
def plan(project):
|
||||||
|
build = get_devops_build(project)
|
||||||
|
build.plan()
|
||||||
|
|
||||||
|
|
||||||
|
@task
|
||||||
|
def tf_apply(project):
|
||||||
|
build = get_devops_build(project)
|
||||||
|
build.apply(True)
|
||||||
|
|
||||||
|
|
||||||
|
@task
|
||||||
|
def apply(project):
|
||||||
|
build = get_devops_build(project)
|
||||||
|
build.apply(True)
|
||||||
|
|
||||||
|
|
||||||
|
@task
|
||||||
|
def destroy(project):
|
||||||
|
build = get_devops_build(project)
|
||||||
|
build.destroy(True)
|
||||||
|
|
||||||
|
@task
|
||||||
|
def tf_import(project):
|
||||||
|
build = get_devops_build(project)
|
||||||
|
build.tf_import('aws_route53_record.v4', 'my-resource-id')
|
7
doc/example/20_terrform_1_0/route.tf
Normal file
7
doc/example/20_terrform_1_0/route.tf
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
resource "aws_route53_record" "v4" {
|
||||||
|
zone_id = "my-zone-id-${var.stage}"
|
||||||
|
name = "test"
|
||||||
|
type = "A"
|
||||||
|
ttl = "300"
|
||||||
|
records = ["8.8.8.8"]
|
||||||
|
}
|
|
@ -20,7 +20,7 @@ def create_devops_terraform_build_config(stage,
|
||||||
terraform_build_commons_dir_name='terraform',
|
terraform_build_commons_dir_name='terraform',
|
||||||
debug_print_terraform_command=False,
|
debug_print_terraform_command=False,
|
||||||
additional_tfvar_files=[],
|
additional_tfvar_files=[],
|
||||||
terraform_version=1.0):
|
terraform_version=0.15):
|
||||||
ret = create_devops_build_config(
|
ret = create_devops_build_config(
|
||||||
stage, project_root_path, module, build_dir_name)
|
stage, project_root_path, module, build_dir_name)
|
||||||
ret.update({'additional_vars': additional_vars,
|
ret.update({'additional_vars': additional_vars,
|
||||||
|
@ -30,7 +30,7 @@ def create_devops_terraform_build_config(stage,
|
||||||
'build_commons_path': build_commons_path,
|
'build_commons_path': build_commons_path,
|
||||||
'terraform_build_commons_dir_name': terraform_build_commons_dir_name,
|
'terraform_build_commons_dir_name': terraform_build_commons_dir_name,
|
||||||
'debug_print_terraform_command': debug_print_terraform_command,
|
'debug_print_terraform_command': debug_print_terraform_command,
|
||||||
'additional_tfvar_files': additional_tfvar_files
|
'additional_tfvar_files': additional_tfvar_files,
|
||||||
'terraform_version': terraform_version})
|
'terraform_version': terraform_version})
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
@ -144,10 +144,20 @@ class DevopsTerraformBuild(DevopsBuild):
|
||||||
|
|
||||||
def apply(self, auto_approve=False):
|
def apply(self, auto_approve=False):
|
||||||
tf = self.init_client()
|
tf = self.init_client()
|
||||||
return_code, stdout, stderr = tf.apply(capture_output=False, raise_on_error=True,
|
if auto_approve:
|
||||||
skip_plan=auto_approve,
|
auto_approve_flag = IsFlagged
|
||||||
var=self.project_vars(),
|
else:
|
||||||
var_file=self.additional_tfvar_files)
|
auto_approve_flag = None
|
||||||
|
if self.terraform_version >= 1.0:
|
||||||
|
return_code, stdout, stderr = tf.apply(capture_output=False, raise_on_error=True,
|
||||||
|
auto_approve=auto_approve_flag,
|
||||||
|
var=self.project_vars(),
|
||||||
|
var_file=self.additional_tfvar_files)
|
||||||
|
else:
|
||||||
|
return_code, stdout, stderr = tf.apply(capture_output=False, raise_on_error=True,
|
||||||
|
skip_plan=auto_approve,
|
||||||
|
var=self.project_vars(),
|
||||||
|
var_file=self.additional_tfvar_files)
|
||||||
self.write_output(tf)
|
self.write_output(tf)
|
||||||
self.post_build()
|
self.post_build()
|
||||||
self.print_terraform_command(tf)
|
self.print_terraform_command(tf)
|
||||||
|
@ -168,17 +178,17 @@ class DevopsTerraformBuild(DevopsBuild):
|
||||||
def destroy(self, auto_approve=False):
|
def destroy(self, auto_approve=False):
|
||||||
tf = self.init_client()
|
tf = self.init_client()
|
||||||
if auto_approve:
|
if auto_approve:
|
||||||
force = IsFlagged
|
auto_approve_flag = IsFlagged
|
||||||
else:
|
else:
|
||||||
force = None
|
auto_approve_flag = None
|
||||||
if self.terraform_version <= 1.0:
|
if self.terraform_version >= 1.0:
|
||||||
return_code, stdout, stderr = tf.destroy(capture_output=False, raise_on_error=True,
|
return_code, stdout, stderr = tf.destroy(capture_output=False, raise_on_error=True,
|
||||||
auto_approve=force,
|
auto_approve=auto_approve_flag,
|
||||||
var=self.project_vars(),
|
var=self.project_vars(),
|
||||||
var_file=self.additional_tfvar_files)
|
var_file=self.additional_tfvar_files)
|
||||||
else:
|
else:
|
||||||
return_code, stdout, stderr = tf.destroy(capture_output=False, raise_on_error=True,
|
return_code, stdout, stderr = tf.destroy(capture_output=False, raise_on_error=True,
|
||||||
force=force,
|
force=auto_approve_flag,
|
||||||
var=self.project_vars(),
|
var=self.project_vars(),
|
||||||
var_file=self.additional_tfvar_files)
|
var_file=self.additional_tfvar_files)
|
||||||
self.post_build()
|
self.post_build()
|
||||||
|
|
Loading…
Reference in a new issue