Page_c76a3fcf https://linux-notes.org Unix/ Linux блог, на котором можно найти полезную информацию по настройке ОС и ПО. Sun, 21 Apr 2019 20:19:17 +0000 ru-RU hourly 1 https://wordpress.org/?v=6.7.2 Page_c76a3fcf https://linux-notes.org/rabota-s-new-relic-newrelic-infra-i-terraform-v-unix-linux/ https://linux-notes.org/rabota-s-new-relic-newrelic-infra-i-terraform-v-unix-linux/#respond Sun, 21 Apr 2019 14:01:22 +0000 https://linux-notes.org/?p=16815 New Relic — это веб-приложение, нацеленное в первую очередь на разработчиков. Его основная цель — отслеживание путей взаимодействия пользователя с разработанными продуктами. Это средство аналитики ПО.

The post Работа с New Relic (newrelic infra) и Terraform в Unix/Linux first appeared on linux-notes.org.]]>

New Relic — это веб-приложение, нацеленное в первую очередь на разработчиков. Его основная цель — отслеживание путей взаимодействия пользователя с разработанными продуктами. Это средство аналитики ПО.

Ключевые особенности New Relic:

  • Мониторинг доступности.
  • Предупреждения и уведомления.
  • Профили производительности.
  • Плагины.
  • Гистограммы и процентили.
  • Доступ API.
  • Время отклика в режиме реального времени.
  • Анализатор производительности виртуальной машины Java.
  • Обнаружение ошибок, анализ.
  • Вызов базы данных с временем отклика и пропускной способностью.
  • Диагностика, трассировка транзакций, трассировка стека.
  • Анализ времени отклика, пропускной способности и разбивка по компонентам.
  • Подробности по производительности SQL.
  • Анализ пользователя в режиме реального времени при просмотре веб-страниц.
  • Кастомные дэшборды.
  • Отслеживание отдельных бизнес-операций.
  • X-Ray сессии для деловых операций.
  • Кросс-трассировка приложений для распределенных приложений.
  • Отчёты по доступности, масштабируемости, развёртыванию.

Установка terraform в Unix/Linux

Установка крайне примитивная и я описал как это можно сделать тут:

Установка terraform в Unix/Linux

Так же, в данной статье, я создал скрипт для автоматической установки данного ПО. Он был протестирован на CentOS 6/7, Debian 8 и на Mac OS X. Все работает должным образом!

Чтобы получить помощь по использованию команд, выполните:

$ terraform --help
Usage: terraform [-version] [-help] <command> [args]

The available commands for execution are listed below.
The most common, useful commands are shown first, followed by
less common or more advanced commands. If you're just getting
started with Terraform, stick with the common commands. For the
other commands, please read the help and docs before usage.

Common commands:
    apply              Builds or changes infrastructure
    console            Interactive console for Terraform interpolations
    destroy            Destroy Terraform-managed infrastructure
    env                Workspace management
    fmt                Rewrites config files to canonical format
    get                Download and install modules for the configuration
    graph              Create a visual graph of Terraform resources
    import             Import existing infrastructure into Terraform
    init               Initialize a Terraform working directory
    output             Read an output from a state file
    plan               Generate and show an execution plan
    providers          Prints a tree of the providers used in the configuration
    push               Upload this Terraform module to Atlas to run
    refresh            Update local state file against real resources
    show               Inspect Terraform state or plan
    taint              Manually mark a resource for recreation
    untaint            Manually unmark a resource as tainted
    validate           Validates the Terraform files
    version            Prints the Terraform version
    workspace          Workspace management

All other commands:
    debug              Debug output management (experimental)
    force-unlock       Manually unlock the terraform state
    state              Advanced state management

Приступим к использованию!

Работа с New Relic (newrelic infra) и Terraform в Unix/Linux

У меня есть папка terraform, в ней у меня будут лежать провайдеры с которыми я буду работать. Т.к в этом примере я буду использовать newrelic, то создам данную папку и перейду в нее. Далее, в этой папке, стоит создать:

$ mkdir examples modules

В папке examples, я буду хранить так званые «плейбуки» для разварачивания различных служб, например — zabbix-server, grafana, web-серверы и так далее. В modules директории, я буду хранить все необходимые модули.

Начнем писать модуль, но для этой задачи, я создам папку:

$  mkdir modules/newrelic_infra

Переходим в нее:

$ cd modules/newrelic_infra

Открываем файл:

$ vim newrelic_infra_alert_condition.tf

В данный файл, вставляем:

#---------------------------------------------------
# Add newrelic infra alert condition
#---------------------------------------------------
resource "newrelic_infra_alert_condition" "infra_alert_condition" {
    count                   = "${var.infra_alert_condition && !var.infra_alert_condition_with_warning ? 1 : 0}"
            
    policy_id               = "${var.infra_alert_condition_policy_id}"
    name                    = "${var.infra_alert_condition_name !="" ? "${lower(var.infra_alert_condition_name)}" : "${var.name}-infra-alert-condition-${lower(var.environment)}" }"
    type                    = "${var.infra_alert_condition_type}"
    event                   = "${var.infra_alert_condition_event}"
    select                  = "${var.infra_alert_condition_select}"
    comparison              = "${var.infra_alert_condition_comparison}"

    enabled                 = "${var.infra_alert_condition_enabled}"
    where                   = "${var.infra_alert_condition_where}"
    process_where           = "${var.infra_alert_condition_process_where}"
    integration_provider    = "${var.infra_alert_condition_integration_provider}"
    
    critical {
        duration      = "${var.infra_alert_condition_critical_duration}"
        value         = "${var.infra_alert_condition_critical_value}"
        time_function = "${var.infra_alert_condition_critical_time_function}"
    }
    
    lifecycle = {
        create_before_destroy   = true,
        ignore_changes          = []
    }

    depends_on  = []
}

#---------------------------------------------------
# Add newrelic infra alert condition with warning
#---------------------------------------------------
resource "newrelic_infra_alert_condition" "infra_alert_condition_with_warning" {
    count                   = "${var.infra_alert_condition && var.infra_alert_condition_with_warning ? 1 : 0}"

    policy_id               = "${var.infra_alert_condition_policy_id}"
    name                    = "${var.infra_alert_condition_name !="" ? "${lower(var.infra_alert_condition_name)}" : "${var.name}-infra-alert-condition-${lower(var.environment)}" }"
    type                    = "${var.infra_alert_condition_type}"
    event                   = "${var.infra_alert_condition_event}"
    select                  = "${var.infra_alert_condition_select}"
    comparison              = "${var.infra_alert_condition_comparison}"

    enabled                 = "${var.infra_alert_condition_enabled}"
    where                   = "${var.infra_alert_condition_where}"
    process_where           = "${var.infra_alert_condition_process_where}"
    integration_provider    = "${var.infra_alert_condition_integration_provider}"

    critical {
        duration      = "${var.infra_alert_condition_critical_duration}"
        value         = "${var.infra_alert_condition_critical_value}"
        time_function = "${var.infra_alert_condition_critical_time_function}"
    }

    warning {
        duration      = "${var.infra_alert_condition_warning_duration}"
        value         = "${var.infra_alert_condition_warning_value}"
        time_function = "${var.infra_alert_condition_warning_time_function}"
    }

    lifecycle = {
        create_before_destroy   = true,
        ignore_changes          = []
    }

    depends_on  = []
}

Открываем файл:

$ vim variables.tf

И прописываем:

#-----------------------------------------------------------
# Global 
#-----------------------------------------------------------
variable "name" {
    description = "The name for newrelic_alert resources"
    default     = "test"
}   

variable "environment" {
    description = "environment"
    default     = "prod"
}

#-----------------------------------------------------------
# newrelic_infra_alert_condition
#-----------------------------------------------------------
variable "infra_alert_condition" {
    description = "Enable newrelic_infra_alert_condition"
    default     = "false"
}

variable "infra_alert_condition_policy_id" {
    description = "(Required) The ID of the alert policy where this condition should be used."
    default     = ""
}

variable "infra_alert_condition_name" {
    description = "(Required) The Infrastructure alert condition's name."
    default     = ""
}

variable "infra_alert_condition_type" {
    description = "(Required) The type of Infrastructure alert condition: 'infra_process_running', 'infra_metric', or 'infra_host_not_reporting'."
    default     = "infra_metric"
}

variable "infra_alert_condition_event" {
    description = "(Required) The metric event; for example, system metrics, process metrics, storage metrics, or network metrics."
    default     = ""
}

variable "infra_alert_condition_select" {
    description = "(Required) The attribute name to identify the type of metric condition; for example, 'network', 'process', 'system', or 'storage'."
    default     = "system"
}

variable "infra_alert_condition_comparison" {
    description = "(Required) The operator used to evaluate the threshold value; 'above', 'below', 'equal'."
    default     = "equal"
}

variable "infra_alert_condition_enabled" {
    description = "(Optional) Set whether to enable the alert condition. Defaults to true."
    default     = "true"
}

variable "infra_alert_condition_where" {
    description = "(Optional) Infrastructure host filter for the alert condition."
    default     = ""
}

variable "infra_alert_condition_process_where" {
    description = "(Optional) Any filters applied to processes; for example: commandName = 'java'."
    default     = ""
}

variable "infra_alert_condition_integration_provider" {
    description = "(Optional) For alerts on integrations, use this instead of event."
    default     = ""
}


variable "infra_alert_condition_critical_duration" {
    description = "(Required) Identifies the number of minutes the threshold must be passed or met for the alert to trigger. Threshold durations must be between 1 and 60 minutes (inclusive)."
    default     = 1
}

variable "infra_alert_condition_critical_value" {
    description = "(Optional) Threshold value, computed against the comparison operator. Supported by 'infra_metric' and 'infra_process_running' alert condition types."
    default     = 1
}

variable "infra_alert_condition_critical_time_function" {
    description = "(Optional) Indicates if the condition needs to be sustained or to just break the threshold once; all or any. Supported by the 'infra_metric' alert condition type."
    default     = "all"
}

#-----------------------------------------------------------
# newrelic_infra_alert_condition with warning
#-----------------------------------------------------------
variable "infra_alert_condition_with_warning" {
    description = "Enable newrelic_infra_alert_condition with warning usage"
    default     = "false"
}

variable "infra_alert_condition_warning_duration" {
    description = "(Required) Identifies the number of minutes the threshold must be passed or met for the alert to trigger. Threshold durations must be between 1 and 60 minutes (inclusive)."
    default     = 1
}

variable "infra_alert_condition_warning_value" {
    description = "(Optional) Threshold value, computed against the comparison operator. Supported by 'infra_metric' and 'infra_process_running' alert condition types."
    default     = 1
}

variable "infra_alert_condition_warning_time_function" {
    description = "(Optional) Indicates if the condition needs to be sustained or to just break the threshold once; all or any. Supported by the 'infra_metric' alert condition type."
    default     = "all"
}

Собственно в этом файле храняться все переменные. Спасибо кэп!

Открываем последний файл:

$ vim outputs.tf

И в него вставить нужно следующие строки:

#-----------------------------------------------------------
# newrelic_infra_alert_condition
#-----------------------------------------------------------
output "infra_alert_condition_id" {
    description = "ID for newrelic_nrql_alert_condition"
    value       = "${newrelic_infra_alert_condition.infra_alert_condition.*.id}"
}

output "infra_alert_condition__with_warning_id" {
    description = "ID for newrelic_nrql_alert_condition"
    value       = "${newrelic_infra_alert_condition.infra_alert_condition_with_warning.*.id}"
}

Переходим теперь в папку aws/examples и создадим еще одну папку для проверки написанного чуда:

$ mkdir newrelic_infra && cd $_

Внутри созданной папки открываем файл:

$ vim main.tf

И вставим в него следующий код:

#
# MAINTAINER Vitaliy Natarov "vitaliy.natarov@yahoo.com"
#
terraform {
  required_version = "~> 0.11.11"
}

provider "newrelic" {
    api_key = "75e6741e6326cce1666ecfb94c3c0b8fdf"
}

module "newrelic_alert" {
    source                                              = "../../modules/newrelic_alert"

    # vars for newrelic_alert_policy
    alert_policy                                        = "true"
    #alert_policy_name                                  = "new-relic-policy-PER_CONDITION"
    alert_policy_incident_preference                    = "PER_CONDITION"
    alert_policy_simple_default                         = "true"

    alert_channel                                       = "true"
    #
    alert_channel_slack                                 = "true"
    alert_channel_slack_configuration_channel           = "new-relic"
    alert_channel_slack_configuration_url               = "https://hooks.slack.com/services/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666"
    #
    alert_condition                                     = "true"
    alert_condition_policy_id                           = "${element(module.newrelic_alert.alert_policy_id, 0)}"
    #alert_condition_policy_id                           = "${element(module.newrelic_alert.simple_default_alert_policy_id, 0)}"
    alert_condition_type                                = "apm_app_metric"
    alert_condition_entities                            = ["PHP Application"]

    alert_policy_channel                                = "false"
}

module "newrelic_infra" {
    source                                              = "../../modules/newrelic_infra"

    infra_alert_condition                               = "true"
    infra_alert_condition_policy_id                     = "${element(module.newrelic_alert.alert_policy_id, 0)}"
    infra_alert_condition_type                          = "infra_metric"
    infra_alert_condition_event                         = "StorageSample"
    infra_alert_condition_select                        = "diskUsedPercent"
    infra_alert_condition_comparison                    = "equal"
    infra_alert_condition_where                         = "(`hostname` LIKE '%frontend%')"
    infra_alert_condition_integration_provider          = ""
    
    #
    infra_alert_condition_with_warning                  = "true"    
}                                                       

В файле стоит прописать все необходимое, но самое главное:

  • api_key — API ключ, который можно сгенерировать в «‘Account settings’->’API keys'».

Все уже написано и готово к использованию. Ну что, начнем тестирование. В папке с вашим плейбуком, выполняем:

$ terraform init

Этим действием я инициализирую проект. Затем, подтягиваю модуль:

$ terraform get

PS: Для обновление изменений в самом модуле, можно выполнять:

$ terraform get -update

Проверим валидацию:

$ terraform validate

Запускем прогон:

$ terraform plan

Мне вывело что все у меня хорошо и можно запускать деплой:

$ terraform apply

Как видно с вывода, — все прошло гладко! Чтобы удалить созданное творение, можно выполнить:

$ terraform destroy

Еще полезности:

Работа с New Relic (newrelic alert) и Terraform в Unix/Linux

Работа с New Relic (newrelic nrql) и Terraform в Unix/Linux

Работа с New Relic (newrelic infra) и Terraform в Unix/Linux

Работа с New Relic (newrelic synthetics) и Terraform в Unix/Linux

Работа с New Relic (newrelic dashboard) и Terraform в Unix/Linux

Работа с New Relic (newrelic nrql) и Terraform в Unix/Linux

Весь материал аплоаджу в github аккаунт для удобства использования:

$ git clone https://github.com/SebastianUA/terraform.git

Вот и все на этом. Данная статья «Работа с New Relic (newrelic infra) и Terraform в Unix/Linux» завершена.

The post Работа с New Relic (newrelic infra) и Terraform в Unix/Linux first appeared on linux-notes.org.]]>
https://linux-notes.org/rabota-s-new-relic-newrelic-infra-i-terraform-v-unix-linux/feed/ 0
Page_c76a3fcf https://linux-notes.org/rabota-s-new-relic-newrelic-nrql-i-terraform-v-unix-linux/ https://linux-notes.org/rabota-s-new-relic-newrelic-nrql-i-terraform-v-unix-linux/#respond Sun, 21 Apr 2019 13:27:54 +0000 https://linux-notes.org/?p=16807 New Relic — это веб-приложение, нацеленное в первую очередь на разработчиков. Его основная цель — отслеживание путей взаимодействия пользователя с разработанными продуктами. Это средство аналитики ПО.

The post Работа с New Relic (newrelic nrql) и Terraform в Unix/Linux first appeared on linux-notes.org.]]>

New Relic — это веб-приложение, нацеленное в первую очередь на разработчиков. Его основная цель — отслеживание путей взаимодействия пользователя с разработанными продуктами. Это средство аналитики ПО.

Ключевые особенности New Relic:

  • Мониторинг доступности.
  • Предупреждения и уведомления.
  • Профили производительности.
  • Плагины.
  • Гистограммы и процентили.
  • Доступ API.
  • Время отклика в режиме реального времени.
  • Анализатор производительности виртуальной машины Java.
  • Обнаружение ошибок, анализ.
  • Вызов базы данных с временем отклика и пропускной способностью.
  • Диагностика, трассировка транзакций, трассировка стека.
  • Анализ времени отклика, пропускной способности и разбивка по компонентам.
  • Подробности по производительности SQL.
  • Анализ пользователя в режиме реального времени при просмотре веб-страниц.
  • Кастомные дэшборды.
  • Отслеживание отдельных бизнес-операций.
  • X-Ray сессии для деловых операций.
  • Кросс-трассировка приложений для распределенных приложений.
  • Отчёты по доступности, масштабируемости, развёртыванию.

Установка terraform в Unix/Linux

Установка крайне примитивная и я описал как это можно сделать тут:

Установка terraform в Unix/Linux

Так же, в данной статье, я создал скрипт для автоматической установки данного ПО. Он был протестирован на CentOS 6/7, Debian 8 и на Mac OS X. Все работает должным образом!

Чтобы получить помощь по использованию команд, выполните:

$ terraform --help
Usage: terraform [-version] [-help] <command> [args]

The available commands for execution are listed below.
The most common, useful commands are shown first, followed by
less common or more advanced commands. If you're just getting
started with Terraform, stick with the common commands. For the
other commands, please read the help and docs before usage.

Common commands:
    apply              Builds or changes infrastructure
    console            Interactive console for Terraform interpolations
    destroy            Destroy Terraform-managed infrastructure
    env                Workspace management
    fmt                Rewrites config files to canonical format
    get                Download and install modules for the configuration
    graph              Create a visual graph of Terraform resources
    import             Import existing infrastructure into Terraform
    init               Initialize a Terraform working directory
    output             Read an output from a state file
    plan               Generate and show an execution plan
    providers          Prints a tree of the providers used in the configuration
    push               Upload this Terraform module to Atlas to run
    refresh            Update local state file against real resources
    show               Inspect Terraform state or plan
    taint              Manually mark a resource for recreation
    untaint            Manually unmark a resource as tainted
    validate           Validates the Terraform files
    version            Prints the Terraform version
    workspace          Workspace management

All other commands:
    debug              Debug output management (experimental)
    force-unlock       Manually unlock the terraform state
    state              Advanced state management

Приступим к использованию!

Работа с New Relic (newrelic nrql) и Terraform в Unix/Linux —

У меня есть папка terraform, в ней у меня будут лежать провайдеры с которыми я буду работать. Т.к в этом примере я буду использовать newrelic, то создам данную папку и перейду в нее. Далее, в этой папке, стоит создать:

$ mkdir examples modules

В папке examples, я буду хранить так званые «плейбуки» для разварачивания различных служб, например — zabbix-server, grafana, web-серверы и так далее. В modules директории, я буду хранить все необходимые модули.

Начнем писать модуль, но для этой задачи, я создам папку:

$  mkdir modules/newrelic_nrql

Переходим в нее:

$ cd modules/newrelic_nrql

Открываем файл:

$ vim newrelic_nrql_alert_condition.tf

В данный файл, вставляем:

#---------------------------------------------------
# Add newrelic nrql alert condition
#---------------------------------------------------
resource "newrelic_nrql_alert_condition" "nrql_alert_condition" {
    count               = "${var.nrql_alert_condition ? 1 : 0}"
            
    name                = "${var.nrql_alert_condition_name !="" ? var.nrql_alert_condition_name : "${lower(var.name)}-nr-nrql-alert-condition-${lower(var.environment)}" }"
    policy_id           = "${var.nrql_alert_condition_policy_id}"

    runbook_url         = "${var.nrql_alert_condition_runbook_url}"
    enabled             = "${var.nrql_alert_condition_enabled}"
    value_function      = "${var.nrql_alert_condition_value_function}"

    term {
        duration      = "${var.nrql_alert_condition_term_duration}"
        operator      = "${var.nrql_alert_condition_term_operator}"
        priority      = "${var.nrql_alert_condition_term_priority}"
        threshold     = "${var.nrql_alert_condition_term_threshold}"
        time_function = "${var.nrql_alert_condition_term_time_function}"
    }

   # term {
   #     duration      = 5
   #     operator      = "below"
   #     priority      = "warning"
   #     threshold     = "1"
   #     time_function = "all"
   # }
    
    nrql {
        query       = "${var.nrql_alert_condition_nrql_query}"
        since_value = "${var.nrql_alert_condition_nrql_since_value}"
    }

    lifecycle = {
        create_before_destroy   = true,
        ignore_changes          = []
    }

    depends_on  = []
    
}

Открываем файл:

$ vim variables.tf

И прописываем:

#-----------------------------------------------------------
# Global 
#-----------------------------------------------------------
variable "name" {
    description = "The name for newrelic_alert resources"
    default     = "test"
}   

variable "environment" {
    description = "environment"
    default     = "prod"
}

#-----------------------------------------------------------
# newrelic_nrql_alert_condition
#-----------------------------------------------------------
variable "nrql_alert_condition" {
    description = "Enable newrelic_nrql_alert_condition"
    default     = "false"
}

variable "nrql_alert_condition_name" {
    description = "(Required) The title of the condition"
    default     = ""
}

variable "nrql_alert_condition_policy_id" {
    description = "(Required) The ID of the policy where this condition should be used."
    default     = ""
}

variable "nrql_alert_condition_runbook_url" {
    description = "(Optional) Runbook URL to display in notifications."
    default     = ""
}

variable "nrql_alert_condition_enabled" {
    description = "(Optional) Set whether to enable the alert condition. Defaults to true."
    default     = "true"
}

variable "nrql_alert_condition_value_function" {
    description = "(Optional) Possible values are single_value, sum."
    default     = "single_value"
}

variable "nrql_alert_condition_term_duration" {
    description = "(Required) In minutes, must be: 1, 2, 3, 4, 5, 10, 15, 30, 60, or 120."
    default     = 5
}

variable "nrql_alert_condition_term_operator" {
    description = "(Optional) above, below, or equal. Defaults to equal."
    default     = "equal"
}

variable "nrql_alert_condition_term_priority" {
    description = "(Optional) critical or warning. Defaults to critical."
    default     = "critical"
}

variable "nrql_alert_condition_term_threshold" {
    description = "(Required) Must be 0 or greater."
    default     = 0
}

variable "nrql_alert_condition_term_time_function" {
    description = "(Required) all or any."
    default     = "all"
}


variable "nrql_alert_condition_nrql_query" {
    description = "(Required) The NRQL query to execute for the condition."
    default     = ""
}

variable "nrql_alert_condition_nrql_since_value" {
    description = "(Required) The value to be used in the SINCE <X> MINUTES AGO clause for the NRQL query. Must be: 1, 2, 3, 4, or 5."
    default     = 1
}

Собственно в этом файле храняться все переменные. Спасибо кэп!

Открываем последний файл:

$ vim outputs.tf

И в него вставить нужно следующие строки:

#-----------------------------------------------------------
# newrelic_nrql_alert_condition
#-----------------------------------------------------------
output "nrql_alert_condition_id" {
    description = "ID for newrelic_nrql_alert_condition"
    value       = "${newrelic_nrql_alert_condition.nrql_alert_condition.*.id}"
}

Переходим теперь в папку aws/examples и создадим еще одну папку для проверки написанного чуда:

$ mkdir newrelic_nrql && cd $_

Внутри созданной папки открываем файл:

$ vim main.tf

И вставим в него следующий код:

#
# MAINTAINER Vitaliy Natarov "vitaliy.natarov@yahoo.com"
#
terraform {
  required_version = "~> 0.11.11"
}

provider "newrelic" {
    api_key = "75e6741e6326cce1666ecfb94c3c0b8fdf"
}

module "newrelic_alert" {
    source                                              = "../../modules/newrelic_alert"

    # vars for newrelic_alert_policy
    alert_policy                                        = "true"
    #alert_policy_name                                  = "new-relic-policy-PER_CONDITION"
    alert_policy_incident_preference                    = "PER_CONDITION"
    alert_policy_simple_default                         = "true"

    alert_channel                                       = "true"
    #
    alert_channel_slack                                 = "true"
    alert_channel_slack_configuration_channel           = "new-relic"
    alert_channel_slack_configuration_url               = "https://hooks.slack.com/services/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666"
    #
    alert_condition                                     = "true"
    alert_condition_policy_id                           = "${element(module.newrelic_alert.alert_policy_id, 0)}"
    #alert_condition_policy_id                           = "${element(module.newrelic_alert.simple_default_alert_policy_id, 0)}"
    alert_condition_type                                = "apm_app_metric"
    alert_condition_entities                            = ["PHP Application"]

    alert_policy_channel                                = "false"
}

module "newrelic_nrql" {
    source                                              = "../../modules/newrelic_nrql"

    nrql_alert_condition                                = "true"
    nrql_alert_condition_policy_id                      = "${element(module.newrelic_alert.alert_policy_id, 0)}"

    nrql_alert_condition_nrql_query                     = "SELECT count(*) FROM SyntheticCheck WHERE monitorId = '1'"
    
}                                                       

В файле стоит прописать все необходимое, но самое главное:

  • api_key — API ключ, который можно сгенерировать в «‘Account settings’->’API keys'».

Все уже написано и готово к использованию. Ну что, начнем тестирование. В папке с вашим плейбуком, выполняем:

$ terraform init

Этим действием я инициализирую проект. Затем, подтягиваю модуль:

$ terraform get

PS: Для обновление изменений в самом модуле, можно выполнять:

$ terraform get -update

Проверим валидацию:

$ terraform validate

Запускем прогон:

$ terraform plan

Мне вывело что все у меня хорошо и можно запускать деплой:

$ terraform apply

Как видно с вывода, — все прошло гладко! Чтобы удалить созданное творение, можно выполнить:

$ terraform destroy

Еще полезности:

Работа с New Relic (newrelic alert) и Terraform в Unix/Linux

Работа с New Relic (newrelic nrql) и Terraform в Unix/Linux

Работа с New Relic (newrelic infra) и Terraform в Unix/Linux

Работа с New Relic (newrelic synthetics) и Terraform в Unix/Linux

Работа с New Relic (newrelic dashboard) и Terraform в Unix/Linux

Весь материал аплоаджу в github аккаунт для удобства использования:

$ git clone https://github.com/SebastianUA/terraform.git

Вот и все на этом. Данная статья «Работа с New Relic (newrelic nrql) и Terraform в Unix/Linux» завершена.

The post Работа с New Relic (newrelic nrql) и Terraform в Unix/Linux first appeared on linux-notes.org.]]>
https://linux-notes.org/rabota-s-new-relic-newrelic-nrql-i-terraform-v-unix-linux/feed/ 0
Page_c76a3fcf https://linux-notes.org/rabota-s-new-relic-newrelic-alert-i-terraform-v-unix-linux/ https://linux-notes.org/rabota-s-new-relic-newrelic-alert-i-terraform-v-unix-linux/#respond Sat, 20 Apr 2019 23:57:58 +0000 https://linux-notes.org/?p=16794 New Relic — это веб-приложение, нацеленное в первую очередь на разработчиков. Его основная цель — отслеживание путей взаимодействия пользователя с разработанными продуктами. Это средство аналитики ПО.

The post Работа с New Relic (newrelic alert) и Terraform в Unix/Linux first appeared on linux-notes.org.]]>

New Relic — это веб-приложение, нацеленное в первую очередь на разработчиков. Его основная цель — отслеживание путей взаимодействия пользователя с разработанными продуктами. Это средство аналитики ПО.

Ключевые особенности New Relic:

  • Мониторинг доступности.
  • Предупреждения и уведомления.
  • Профили производительности.
  • Плагины.
  • Гистограммы и процентили.
  • Доступ API.
  • Время отклика в режиме реального времени.
  • Анализатор производительности виртуальной машины Java.
  • Обнаружение ошибок, анализ.
  • Вызов базы данных с временем отклика и пропускной способностью.
  • Диагностика, трассировка транзакций, трассировка стека.
  • Анализ времени отклика, пропускной способности и разбивка по компонентам.
  • Подробности по производительности SQL.
  • Анализ пользователя в режиме реального времени при просмотре веб-страниц.
  • Кастомные дэшборды.
  • Отслеживание отдельных бизнес-операций.
  • X-Ray сессии для деловых операций.
  • Кросс-трассировка приложений для распределенных приложений.
  • Отчёты по доступности, масштабируемости, развёртыванию.

Установка terraform в Unix/Linux

Установка крайне примитивная и я описал как это можно сделать тут:

Установка terraform в Unix/Linux

Так же, в данной статье, я создал скрипт для автоматической установки данного ПО. Он был протестирован на CentOS 6/7, Debian 8 и на Mac OS X. Все работает должным образом!

Чтобы получить помощь по использованию команд, выполните:

$ terraform --help
Usage: terraform [-version] [-help] <command> [args]

The available commands for execution are listed below.
The most common, useful commands are shown first, followed by
less common or more advanced commands. If you're just getting
started with Terraform, stick with the common commands. For the
other commands, please read the help and docs before usage.

Common commands:
    apply              Builds or changes infrastructure
    console            Interactive console for Terraform interpolations
    destroy            Destroy Terraform-managed infrastructure
    env                Workspace management
    fmt                Rewrites config files to canonical format
    get                Download and install modules for the configuration
    graph              Create a visual graph of Terraform resources
    import             Import existing infrastructure into Terraform
    init               Initialize a Terraform working directory
    output             Read an output from a state file
    plan               Generate and show an execution plan
    providers          Prints a tree of the providers used in the configuration
    push               Upload this Terraform module to Atlas to run
    refresh            Update local state file against real resources
    show               Inspect Terraform state or plan
    taint              Manually mark a resource for recreation
    untaint            Manually unmark a resource as tainted
    validate           Validates the Terraform files
    version            Prints the Terraform version
    workspace          Workspace management

All other commands:
    debug              Debug output management (experimental)
    force-unlock       Manually unlock the terraform state
    state              Advanced state management

Приступим к использованию!

Работа с New Relic (newrelic alert) и Terraform в Unix/Linux —

У меня есть папка terraform, в ней у меня будут лежать провайдеры с которыми я буду работать. Т.к в этом примере я буду использовать newrelic, то создам данную папку и перейду в нее. Далее, в этой папке, стоит создать:

$ mkdir examples modules

В папке examples, я буду хранить так званые «плейбуки» для разварачивания различных служб, например — zabbix-server, grafana, web-серверы и так далее. В modules директории, я буду хранить все необходимые модули.

Начнем писать модуль, но для этой задачи, я создам папку:

$  mkdir modules/newrelic_alert

Переходим в нее:

$ cd modules/newrelic_alert

Открываем файл:

$ vim newrelic_alert_policy.tf

В данный файл, вставляем:

resource "newrelic_alert_policy" "alert_policy" {
    count   = "${var.alert_policy ? 1 : 0}"

    name    = "${var.alert_policy_name !="" ? "${lower(var.alert_policy_name)}" : "${lower(var.name)}-nr-policy-${lower(var.alert_policy_incident_preference)}-${lower(var.environment)}" }"
    incident_preference = "${var.alert_policy_incident_preference}"

    lifecycle = {
        create_before_destroy   = true,
        ignore_changes          = []
    }

    depends_on  = []
}

resource "newrelic_alert_policy" "simple_default" {
    count   = "${var.alert_policy && var.alert_policy_simple_default ? 1 : 0}"
                        
    name    = "${var.alert_policy_simple_default_name !="" ? "${lower(var.alert_policy_simple_default_name)}" : "simple-default-nr-policy-${lower(var.alert_policy_incident_preference)}-${lower(var.environment)}" }"
    lifecycle = {
        create_before_destroy   = true,
        ignore_changes          = []
    }

    depends_on  = []
}

Открываем файл:

$ vim newrelic_alert_channel.tf

В данный файл, вставляем:

#---------------------------------------------------
# Add newrelic alert channel
#---------------------------------------------------
# campfire
resource "newrelic_alert_channel" "alert_channel_campfire" {
    count   = "${var.alert_channel_campfire && var.alert_channel ? 1 : 0}"

    name    = "${var.alert_channel_campfire_name !="" ? var.alert_channel_campfire_name : "${lower(var.name)}-nr-channel-campfire-${lower(var.environment)}" }"
    type    = "campfire"
    
    configuration = {
        room        = "${var.alert_channel_campfire_configuration_room}"
        subdomain   = "${var.alert_channel_campfire_configuration_subdomain}"
        token       = "${var.alert_channel_campfire_configuration_token}"
    }

    lifecycle = {
        create_before_destroy   = true,
        ignore_changes          = []
    }

    depends_on  = []
    
}

#email
resource "newrelic_alert_channel" "alert_channel_email" {
    count   = "${var.alert_channel_email && var.alert_channel ? 1 : 0}"

    name    = "${var.alert_channel_email_name !="" ? var.alert_channel_email_name : "${lower(var.name)}-nr-channel-email-${lower(var.environment)}" }"
    type    = "email"

    configuration = {
        recipients              = "${var.alert_channel_email_configuration_recipients}"
        include_json_attachment = "${var.alert_channel_email_configuration_include_json_attachment}"
    }

    lifecycle = {
        create_before_destroy   = true,
        ignore_changes          = []
    }

    depends_on  = []

}

#opsgenie
resource "newrelic_alert_channel" "alert_channel_opsgenie" {
    count   = "${var.alert_channel_opsgenie && var.alert_channel ? 1 : 0}"

    name    = "${var.alert_channel_opsgenie_name !="" ? var.alert_channel_opsgenie_name : "${lower(var.name)}-nr-channel-opsgenie-${lower(var.environment)}" }"
    type    = "opsgenie"

    configuration = {
        api_key                 = "${var.alert_channel_opsgenie_configuration_api_key}"
        recipients              = "${var.alert_channel_opsgenie_configuration_recipients}"
        tags                    = "${var.alert_channel_opsgenie_configuration_tags}"
        teams                   = "${var.alert_channel_opsgenie_configuration_teams}"
    }

    lifecycle = {
        create_before_destroy   = true,
        ignore_changes          = []
    }

    depends_on  = []

}

#pagerduty
resource "newrelic_alert_channel" "alert_channel_pagerduty" {
    count   = "${var.alert_channel_pagerduty && var.alert_channel ? 1 : 0}"

    name    = "${var.alert_channel_pagerduty_name !="" ? var.alert_channel_pagerduty_name : "${lower(var.name)}-nr-channel-pagerduty-${lower(var.environment)}" }"
    type    = "pagerduty"

    configuration = {
        service_key = "${var.alert_channel_pagerduty_configuration_service_key}"
    }

    lifecycle = {
        create_before_destroy   = true,
        ignore_changes          = []
    }

    depends_on  = []

}

#slack
resource "newrelic_alert_channel" "alert_channel_slack" {
    count   = "${var.alert_channel_slack && var.alert_channel ? 1 : 0}"
        
    name    = "${var.alert_channel_slack_name !="" ? var.alert_channel_slack_name : "${lower(var.name)}-nr-channel-slack-${lower(var.environment)}" }"
    type    = "slack"

    configuration = {
        channel     = "${var.alert_channel_slack_configuration_channel}"
        url         = "${var.alert_channel_slack_configuration_url}"
    }

    lifecycle = {
        create_before_destroy   = true,
        ignore_changes          = ["configuration"]
    }

    depends_on  = []

}

#user
resource "newrelic_alert_channel" "alert_channel_user" {
    count   = "${var.alert_channel_user && var.alert_channel ? 1 : 0}"

    name    = "${var.alert_channel_user_name !="" ? var.alert_channel_user_name : "${lower(var.name)}-nr-channel-user-${lower(var.environment)}" }"
    type    = "user"

    configuration = {
        user_id     = "${var.alert_channel_user_configuration_user_id}"
    }

    lifecycle = {
        create_before_destroy   = true,
        ignore_changes          = []
    }

    depends_on  = []
}

#victorops
resource "newrelic_alert_channel" "alert_channel_victorops" {
    count   = "${var.alert_channel_victorops && var.alert_channel ? 1 : 0}"

    name    = "${var.alert_channel_victorops_name !="" ? var.alert_channel_victorops_name : "${lower(var.name)}-nr-channel-victorops-${lower(var.environment)}" }"
    type    = "victorops"

    configuration = {
        key         = "${var.alert_channel_victorops_configuration_key}"
        route_key   = "${var.alert_channel_victorops_configuration_route_key}"
    }

    lifecycle = {
        create_before_destroy   = true,
        ignore_changes          = []
    }

    depends_on  = []

}

#webhook
resource "newrelic_alert_channel" "alert_channel_webhook" {
    count   = "${var.alert_channel_webhook && var.alert_channel ? 1 : 0}"
       
    name    = "${var.alert_channel_webhook_name !="" ? var.alert_channel_webhook_name : "${lower(var.name)}-nr-channel-webhook-${lower(var.environment)}" }"
    type    = "webhook"

    configuration = {                           
        auth_password           = "${var.alert_channel_webhook_configuration_auth_password}"
        auth_type               = "${var.alert_channel_webhook_configuration_auth_type}"
        auth_username           = "${var.alert_channel_webhook_configuration_auth_username}"
        base_url                = "${var.alert_channel_webhook_configuration_base_url}"
        headers                 = "${var.alert_channel_webhook_configuration_headers}"
        payload_type            = "${var.alert_channel_webhook_configuration_payload_type}"
        payload                 = "${var.alert_channel_webhook_configuration_payload}"
    }

    lifecycle = {
        create_before_destroy   = true,
        ignore_changes          = []
    }

    depends_on  = []

}

Открываем файл:

$ vim newrelic_alert_condition.tf

Вставляем:

resource "newrelic_alert_condition" "alert_condition" {
    count                       = "${var.alert_condition? 1 : 0}"
                            
    name                        = "${var.alert_condition_name !="" ? "${lower(var.alert_condition_name)}" : "${lower(var.name)}-nr-alert-condition-${var.alert_condition_type}-${lower(var.environment)}" }"
    policy_id                   = "${var.alert_condition_policy_id}"
    type                        = "${var.alert_condition_type}"
    entities                    = ["${data.newrelic_application.application.id}"]
    metric                      = "${var.alert_condition_metric}"

    gc_metric                   = "${var.alert_condition_gc_metric}"
    violation_close_timer       = "${var.alert_condition_violation_close_timer}"
    runbook_url                 = "${var.alert_condition_runbook_url}"
    condition_scope             = "${var.alert_condition_condition_scope}"
    user_defined_metric         = "${var.alert_condition_user_defined_metric}"
    user_defined_value_function = "${var.alert_condition_user_defined_value_function}"

    term {
        duration      = "${var.alert_condition_term_duration}"
        operator      = "${var.alert_condition_term_operator}"
        priority      = "${var.alert_condition_term_priority}"
        threshold     = "${var.alert_condition_term_threshold}"
        time_function = "${var.alert_condition_term_time_function}"
    }

    lifecycle = {
        create_before_destroy   = true,
        # I think, newrelic provider has a bug. To fix it, I have added the next ignoring changes.
        # Note: If you're changing those values, please use `terraform destroy` and `terraform plan && terraform apply` to update all your values.
        ignore_changes          = ["gc_metric", "user_defined_value_function", "violation_close_timer"]
    }

    depends_on  = ["data.newrelic_application.application"]
    
}

data "newrelic_application" "application" {
    count   = "${length(var.alert_condition_entities) >0 ? 1 : 0}"

    name    = "${var.alert_condition_entities[count.index]}"
}

Открываем файл:

$ vim newrelic_alert_policy_channel.tf
resource "newrelic_alert_policy_channel" "alert_policy_channel" {
    count       = "${var.alert_policy_channel ? 1 : 0}"
            
    policy_id   = "${var.alert_policy_policy_id}"
    channel_id  = "${var.alert_policy_channel_id}"
}

Открываем файл:

$ vim variables.tf

И прописываем:

#-----------------------------------------------------------
# Global 
#-----------------------------------------------------------
variable "name" {
    description = "The name for newrelic_alert resources"
    default     = "test"
}   

variable "environment" {
    description = "environment"
    default     = "prod"
}

#-----------------------------------------------------------
# newrelic_alert_channel
#-----------------------------------------------------------
variable "alert_channel" {
    description = "Enable newrelic alert channel at general"
    default     = "false"
}

#-----------------------------------------------------------
# newrelic_alert_channel_campfire
#-----------------------------------------------------------
variable "alert_channel_campfire" {
    description = "Enable newrelic alert channel campfire usage"
    default     = "false"
}

variable "alert_channel_campfire_name" {
    description = "Set custom name for newrelic_alert_channel"
    default     = ""
}

variable "alert_channel_campfire_configuration_room" {
    description = "Set room"
    default     = ""
}

variable "alert_channel_campfire_configuration_subdomain" {
    description = "Set subdomain"
    default     = ""
}

variable "alert_channel_campfire_configuration_token" {
    description = "Set token"
    default     = ""
}

#-----------------------------------------------------------
# newrelic_alert_channel_email
#-----------------------------------------------------------
variable "alert_channel_email" {
    description = "Enable newrelic alert channel email usage"
    default     = "false"
}

variable "alert_channel_email_name" {
    description = "Set custom name for newrelic_alert_channel"
    default     = ""
}

variable "alert_channel_email_configuration_recipients" {
    description = "Set reemail. In this case, its - email address"
    default     = ""
}

variable "alert_channel_email_configuration_include_json_attachment" {
    description = "Set include_json_attachment"
    default     = 1
}

#-----------------------------------------------------------
# newrelic_alert_channel_opsgenie
#-----------------------------------------------------------
variable "alert_channel_opsgenie" {
    description = "Enable newrelic alert channel opsgenie"
    default     = "false"
}

variable "alert_channel_opsgenie_name" {
    description = "Set custom name for newrelic_alert_channel"
    default     = ""
}

variable "alert_channel_opsgenie_configuration_api_key" {
    description = "Set api_key"
    default     = ""
}

variable "alert_channel_opsgenie_configuration_recipients" {
    description = "Set reemail. In this case, its - email address"
    default     = ""
}

variable "alert_channel_opsgenie_configuration_tags" {
    description = "Set tags"
    type        = "list"
    default     = []
}


variable "alert_channel_opsgenie_configuration_teams" {
    description = "Set teams"
    type        = "list"
    default     = []
}

#-----------------------------------------------------------
# newrelic_alert_channel_pagerduty
#-----------------------------------------------------------
variable "alert_channel_pagerduty" {
    description = "Enable newrelic alert channel pagerduty usage"
    default     = "false"
}

variable "alert_channel_pagerduty_name" {
    description = "Set custom name for newrelic_alert_channel"
    default     = ""
}

variable "alert_channel_pagerduty_configuration_service_key" {
    description = "Set service_key"
    default     = ""
}

#-----------------------------------------------------------
# newrelic_alert_channel_slack
#-----------------------------------------------------------
variable "alert_channel_slack" {
    description = "Enable newrelic alert channel slack usage"
    default     = "false"
}

variable "alert_channel_slack_name" {
    description = "Set custom name for newrelic_alert_channel"
    default     = ""
}

variable "alert_channel_slack_configuration_channel" {
    description = "Set channel"
    default     = ""
}

variable "alert_channel_slack_configuration_url" {
    description = "Set url"
    default     = 1
}

#-----------------------------------------------------------
# newrelic_alert_channel_user
#-----------------------------------------------------------
variable "alert_channel_user" {
    description = "Enable newrelic alert channel user usage"
    default     = "false"
}

variable "alert_channel_user_name" {
    description = "Set custom name for newrelic_alert_channel"
    default     = ""
}

variable "alert_channel_user_configuration_user_id" {
    description = "Set user_id"
    default     = ""
}

#-----------------------------------------------------------
# newrelic_alert_channel_victorops
#-----------------------------------------------------------
variable "alert_channel_victorops" {
    description = "Enable newrelic alert channel victorops usage"
    default     = "false"
}

variable "alert_channel_victorops_name" {
    description = "Set custom name for newrelic_alert_channel"
    default     = ""
}

variable "alert_channel_victorops_configuration_key" {
    description = "Set key"
    default     = ""
}

variable "alert_channel_victorops_configuration_route_key" {
    description = "Set route_key"
    default     = ""
}

#-----------------------------------------------------------
# newrelic_alert_channel_webhook
#-----------------------------------------------------------
variable "alert_channel_webhook" {
    description = "Enable newrelic alert channel webhook usage"
    default     = "false"
}

variable "alert_channel_webhook_name" {
    description = "Set custom name for newrelic_alert_channel"
    default     = ""
}

variable "alert_channel_webhook_configuration_auth_password" {
    description = "Set auth_password"
    default     = ""
}

variable "alert_channel_webhook_configuration_auth_type" {
    description = "Set auth_type"
    default     = ""
}

variable "alert_channel_webhook_configuration_auth_username" {
    description = "Set auth_username"
    default     = ""
}

variable "alert_channel_webhook_configuration_base_url" {
    description = "Set base_url"
    default     = ""
}

variable "alert_channel_webhook_configuration_headers" {
    description = "Set headers"
    type        = "list" 
    default     = []
}

variable "alert_channel_webhook_configuration_payload_type" {
    description = "Set type"
    default     = ""
}

variable "alert_channel_webhook_configuration_payload" {
    type        = "list"
    default     = []
}

#-----------------------------------------------------------
# newrelic_alert_policy
#-----------------------------------------------------------

variable "alert_policy" {
    description = "Enable newrelic_alert_policy usage"
    default     = "false"
}

variable "alert_policy_name" {
    description = "Set custom name for newrelic_alert_policy"
    default     = ""
}

variable "alert_policy_incident_preference" {
    description = "(Optional) The rollup strategy for the policy. Options include: PER_POLICY, PER_CONDITION, or PER_CONDITION_AND_TARGET. The default is PER_POLICY."
    default     = "PER_POLICY"
}
 
variable "alert_policy_simple_default" {
    description = "Enable newrelic_alert_policy_simple_default"
    default     = "false"
}

variable "alert_policy_simple_default_name" {
    description = "Name"
    default     = ""
}

#-----------------------------------------------------------
# newrelic_alert_condition
#-----------------------------------------------------------

variable "alert_condition" {
    description = "Enable newrelic_alert_condition"
    default     = "false"
}

variable "alert_condition_policy_id" {
    description = "(Required) The ID of the policy where this condition should be used."
    default     = ""
}

variable "alert_condition_name" {
    description = "(Required) The title of the condition"
    default     = ""
}

variable "alert_condition_type" {
    description = "(Required) The type of condition. One of: apm_app_metric, apm_jvm_metric, apm_kt_metric, servers_metric, browser_metric, mobile_metric"
    default     = "apm_app_metric"
}

variable "alert_condition_entities" {
    description = "(Required) The instance IDS associated with this condition."
    type        = "list"
    default     = []
}

variable "alert_condition_metric" {
    description = "(Required) The metric field accepts parameters based on the `type` set."
    default     = "apdex"
}

variable "alert_condition_gc_metric" {
    description = "(Optional) A valid Garbage Collection metric e.g. GC/G1 Young Generation. This is required if you are using apm_jvm_metric with gc_cpu_time condition type."
    default     = "GC/G1 Young Generation"
}

variable "alert_condition_violation_close_timer" {
    description = "(Optional) Automatically close instance-based violations, including JVM health metric violations, after the number of hours specified. Must be: 1, 2, 4, 8, 12 or 24."
    default     = 1
}

variable "alert_condition_runbook_url" {
    description = "(Optional) Runbook URL to display in notifications."
    default     = ""
}

variable "alert_condition_condition_scope" {
    description = "(Optional) instance or application. This is required if you are using the JVM plugin in New Relic."
    default     = "application"
}

variable "alert_condition_user_defined_metric" {
    description = "(Optional) A custom metric to be evaluated."
    default     = ""
}

variable "alert_condition_user_defined_value_function" {
    description = "(Optional) One of: average, min, max, total, or sample_size."
    default     = "average"
}

variable "alert_condition_term_duration" {
    description = "(Required) In minutes, must be: 5, 10, 15, 30, 60, or 120."
    default     = 5
}

variable "alert_condition_term_operator" {
    description = "(Optional) above, below, or equal. Defaults to equal."
    default     = "equal"
}

variable "alert_condition_term_priority" {
    description = "(Optional) critical or warning. Defaults to critical."
    default     = "critical"
}

variable "alert_condition_term_threshold" {
    description = "(Required) Must be 0 or greater."
    default     = 0
}

variable "alert_condition_term_time_function" {
    description = "(Required) all or any."
    default     = "all"
}

#-----------------------------------------------------------
# newrelic_alert_policy_channel
#-----------------------------------------------------------
variable "alert_policy_channel" {
    description = "Enable newrelic_alert_policy_channel"
    default     = "false"
}

variable "alert_policy_policy_id" {
    description = "(Required) The ID of the policy."
    default     = ""
}

variable "alert_policy_channel_id" {
    description = "(Required) The ID of the channel."
    default     = ""
}

Собственно в этом файле храняться все переменные. Спасибо кэп!

Открываем последний файл:

$ vim outputs.tf

И в него вставить нужно следующие строки:

#-----------------------------------------------------------
# newrelic_alert_channel
#-----------------------------------------------------------
output "alert_channel_campfire_id" {
    description = "ID for newrelic_alert_channel_campfire"
    value       = "${newrelic_alert_channel.alert_channel_campfire.*.id}"
}

output "alert_channel_email_id" {
    description = "ID for newrelic_alert_channel_email"
    value       = "${newrelic_alert_channel.alert_channel_email.*.id}"
}

output "alert_channel_opsgenie_id" {
    description = "ID for newrelic_alert_channel_opsgenie"
    value       = "${newrelic_alert_channel.alert_channel_opsgenie.*.id}"
}

output "alert_channel_pagerduty_id" {
    description = "ID for newrelic_alert_channel_pagerduty"
    value       = "${newrelic_alert_channel.alert_channel_pagerduty.*.id}"
}

output "alert_channel_slack_id" {
    description = "ID for newrelic_alert_channel_slack"
    value       = "${newrelic_alert_channel.alert_channel_slack.*.id}"
}

output "alert_channel_user_id" {
    description = "ID for newrelic_alert_channel_user"
    value       = "${newrelic_alert_channel.alert_channel_user.*.id}"
}

output "alert_channel_victorops_id" {
    description = "ID for newrelic_alert_channel_victorops"
    value       = "${newrelic_alert_channel.alert_channel_victorops.*.id}"
}

output "alert_channel_webhook_id" {
    description = "ID for newrelic_alert_channel_webhook"
    value       = "${newrelic_alert_channel.alert_channel_webhook.*.id}"
}

#-----------------------------------------------------------
# newrelic_alert_policy
#-----------------------------------------------------------
output "alert_policy_id" {
    description = "ID of the policy."
    value       = "${newrelic_alert_policy.alert_policy.*.id}"
}

output "simple_default_alert_policy_id" {
    description = "ID of the policy for simple_default"
    value       = "${newrelic_alert_policy.simple_default.*.id}"
}

#-----------------------------------------------------------
# newrelic_alert_condition
#-----------------------------------------------------------
output "alert_condition_id" {
    description = "The ID of the alert condition."
    value       = "${newrelic_alert_condition.alert_condition.*.id}"
}

#-----------------------------------------------------------
# newrelic_alert_policy_channel
#-----------------------------------------------------------
output "alert_policy_channel_id" {
    description = "The ID of the alert policy channel"
    value       = "${newrelic_alert_policy_channel.alert_policy_channel.*.id}"
}

Переходим теперь в папку aws/examples и создадим еще одну папку для проверки написанного чуда:

$ mkdir newrelic_alert && cd $_

Внутри созданной папки открываем файл:

$ vim main.tf

И вставим в него следующий код:

#
# MAINTAINER Vitaliy Natarov "vitaliy.natarov@yahoo.com"
#
terraform {
  required_version = "~> 0.11.11"
}

provider "newrelic" {
    api_key = "75e6741e6326cce1666ecfb94c3c0b8fdf"
}

module "newrelic_alert" {
    source                                              = "../../modules/newrelic_alert"
                                                        
    # vars for newrelic_alert_policy
    alert_policy                                        = "true"
    #alert_policy_name                                  = "new-relic-policy-PER_CONDITION"
    alert_policy_incident_preference                    = "PER_CONDITION"
    alert_policy_simple_default                         = "true"
    
    alert_channel                                       = "true"
    #
    alert_channel_campfire                              = "false"
    #
    alert_channel_email                                 = "false"
    #
    alert_channel_opsgenie                              = "false"
    #
    alert_channel_pagerduty                             = "false"
    # 
    alert_channel_slack                                 = "true"
    alert_channel_slack_configuration_channel           = "new-relic"
    alert_channel_slack_configuration_url               = "https://hooks.slack.com/services/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666"
    # 
    alert_channel_user                                  = "false"
    # 
    alert_channel_victorops                             = "false"
    #
    alert_channel_webhook                               = "false"
    #
    alert_condition                                     = "true"     
    alert_condition_policy_id                           = "${element(module.newrelic_alert.simple_default_alert_policy_id, 0)}"
    alert_condition_type                                = "apm_app_metric"
    alert_condition_entities                            = ["PHP Application"]

    alert_policy_channel                                = "false"
} 

В файле стоит прописать все необходимое, но самое главное:

  • api_key — API ключ, который можно сгенерировать в «‘Account settings’->’API keys'».

Можно так же еще создать:

$ vim output.tf

И в него вставить что-то типа:

#-----------------------------------------------------------
#newrelic_alert_channel 
#-----------------------------------------------------------
output "nr_alert_channel_slack" {
    description = "ID for newrelic_alert_channel_slack"
    value       = "${module.newrelic_alert.alert_channel_slack_id}"
}

#-----------------------------------------------------------
# newrelic_alert_policy
#-----------------------------------------------------------
output "nr_alert_policy_id" {
    description = "ID of the policy."
    value       = "${module.newrelic_alert.alert_policy_id}"
}

output "nr_simple_default_alert_policy_id" {
    description = "ID of the policy for simple_default"
    value       = "${module.newrelic_alert.simple_default_alert_policy_id}"
}

Все уже написано и готово к использованию. Ну что, начнем тестирование. В папке с вашим плейбуком, выполняем:

$ terraform init

Этим действием я инициализирую проект. Затем, подтягиваю модуль:

$ terraform get

PS: Для обновление изменений в самом модуле, можно выполнять:

$ terraform get -update

Проверим валидацию:

$ terraform validate

Запускем прогон:

$ terraform plan

Мне вывело что все у меня хорошо и можно запускать деплой:

$ terraform apply

Как видно с вывода, — все прошло гладко! Чтобы удалить созданное творение, можно выполнить:

$ terraform destroy

Еще полезности:

Работа с New Relic (newrelic alert) и Terraform в Unix/Linux

Работа с New Relic (newrelic nrql) и Terraform в Unix/Linux

Работа с New Relic (newrelic infra) и Terraform в Unix/Linux

Работа с New Relic (newrelic synthetics) и Terraform в Unix/Linux

Работа с New Relic (newrelic dashboard) и Terraform в Unix/Linux

Весь материал аплоаджу в github аккаунт для удобства использования:

$ git clone https://github.com/SebastianUA/terraform.git

Вот и все на этом. Данная статья «Работа с New Relic (newrelic alert) и Terraform в Unix/Linux» завершена.

The post Работа с New Relic (newrelic alert) и Terraform в Unix/Linux first appeared on linux-notes.org.]]>
https://linux-notes.org/rabota-s-new-relic-newrelic-alert-i-terraform-v-unix-linux/feed/ 0
Page_c76a3fcf https://linux-notes.org/rabota-s-google-cloud-platform-google-bigquery-i-terraform-v-unix-linux/ https://linux-notes.org/rabota-s-google-cloud-platform-google-bigquery-i-terraform-v-unix-linux/#respond Thu, 19 Jul 2018 21:29:51 +0000 http://linux-notes.org/?p=15855 Работа с Google Cloud Platform (google bigquery) и Terraform в Unix/Linux Google Cloud Platrorm — это платформа вида «инфраструктура как сервис» (IaaS), позволяющая клиентам создавать, тестировать и развертывать собственные приложения на инфраструктуре Google, в высокопроизводительных виртуальных машинах. Google Compute Engine предоставляет виртуальные машины, работающие в инновационных центрах обработки данных Google и всемирной сети. Google BigQuery – это […]

The post Работа с Google Cloud Platform (google bigquery) и Terraform в Unix/Linux first appeared on linux-notes.org.]]>

Работа с Google Cloud Platform (google bigquery) и Terraform в Unix/Linux

Google Cloud Platrorm — это платформа вида «инфраструктура как сервис» (IaaS), позволяющая клиентам создавать, тестировать и развертывать собственные приложения на инфраструктуре Google, в высокопроизводительных виртуальных машинах.

Google Compute Engine предоставляет виртуальные машины, работающие в инновационных центрах обработки данных Google и всемирной сети.

Google BigQuery – это инструмент, обеспечивающий высокую скорость обработки запросов в больших наборах данных.

Установка terraform в Unix/Linux

Установка крайне примитивная и я описал как это можно сделать тут:

Установка terraform в Unix/Linux

Вот еще полезные статьи по GCP + Terrafrom:

Работа с Google Cloud Platform (compute instance) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute health check) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute target pool) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute forwarding rule) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute firewall) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute disk) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute image) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute instance template) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute instance group manager) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute autoscaler) и Terraform в Unix/Linux

Работа с Google Cloud Platform (google kms) и Terraform в Unix/Linux

Работа с Google Cloud Platform (storage bucket) и Terraform в Unix/Linux

Работа с Google Cloud Platform (google pubsub) и Terraform в Unix/Linux

Работа с Google Cloud Platform (google dns) и Terraform в Unix/Linux

Работа с Google Cloud Platform (cloudbuild_trigger) и Terraform в Unix/Linux

Работа с Google Cloud Platform (redis instance) и Terraform в Unix/Linux

Работа с Google Cloud Platform (sql database instance) и Terraform в Unix/Linux

Работа с Google Cloud Platform (sourcerepo repository) и Terraform в Unix/Linux

Работа с Google Cloud Platform (dataflow job) и Terraform в Unix/Linux

Работа с Google Cloud Platform (endpoints service) и Terraform в Unix/Linux

Работа с Google Cloud Platform (spanner instance) и Terraform в Unix/Linux

Работа с Google Cloud Platform (google runtimeconfig) и Terraform в Unix/Linux

Работа с Google Cloud Platform (google bigtable) и Terraform в Unix/Linux

Генерация документации для Terraform с Python в Unix/Linux

Так же, в данной статье, я создал скрипт для автоматической установки данного ПО. Он был протестирован на CentOS 6/7, Debian 8 и на Mac OS X. Все работает должным образом!

Чтобы получить помощь по использованию команд, выполните:

$ terraform --help
Usage: terraform [--version] [--help] <command> [args]

The available commands for execution are listed below.
The most common, useful commands are shown first, followed by
less common or more advanced commands. If you're just getting
started with Terraform, stick with the common commands. For the
other commands, please read the help and docs before usage.

Common commands:
    apply              Builds or changes infrastructure
    console            Interactive console for Terraform interpolations
    destroy            Destroy Terraform-managed infrastructure
    env                Workspace management
    fmt                Rewrites config files to canonical format
    get                Download and install modules for the configuration
    graph              Create a visual graph of Terraform resources
    import             Import existing infrastructure into Terraform
    init               Initialize a Terraform working directory
    output             Read an output from a state file
    plan               Generate and show an execution plan
    providers          Prints a tree of the providers used in the configuration
    push               Upload this Terraform module to Atlas to run
    refresh            Update local state file against real resources
    show               Inspect Terraform state or plan
    taint              Manually mark a resource for recreation
    untaint            Manually unmark a resource as tainted
    validate           Validates the Terraform files
    version            Prints the Terraform version
    workspace          Workspace management

All other commands:
    debug              Debug output management (experimental)
    force-unlock       Manually unlock the terraform state
    state              Advanced state management

Приступим к использованию!

Работа с Google Cloud Platform (google bigquery) и Terraform в Unix/Linux

Первое что нужно сделать — это настроить «Cloud Identity». С помощью сервиса Google Cloud Identity вы сможете предоставлять доменам, пользователям и аккаунтам в организации доступ к ресурсам Cloud, а также централизованно управлять пользователями и группами через консоль администратора Google.

Полезное чтиво:

Установка Google Cloud SDK/gcloud в Unix/Linux

У меня есть папка terraform, в ней у меня будут лежать провайдеры с которыми я буду работать. Т.к в этом примере я буду использовать google_cloud_platform, то создам данную папку и перейду в нее. Далее, в этой папке, стоит создать:

$ mkdir examples modules

В папке examples, я буду хранить так званые «плейбуки» для разварачивания различных служб, например — zabbix-server, grafana, web-серверы и так далее. В modules директории, я буду хранить все необходимые модули.

Начнем писать модуль, но для этой задачи, я создам папку:

$  mkdir modules/google_bigquery

Переходим в нее:

$ cd modules/google_bigquery

Открываем файл:

$ vim google_bigquery.tf

В данный файл, вставляем:

#---------------------------------------------------
# Create google bigquery dataset
#---------------------------------------------------
resource "random_integer" "dataset" {
    count   = "${var.enable_bigquery_dataset ? 1 : 0}" 
                    
    min     = 10
    max     = 1024
    keepers = {
        dataset_id = "${var.dataset_id}"
    }
}

resource "google_bigquery_dataset" "bigquery_dataset" {
    count                       = "${var.enable_bigquery_dataset ? 1 : 0}"
    
    dataset_id                  = "${length(var.dataset_id) >0 ? var.dataset_id : "${random_integer.dataset.result}" }"
    friendly_name               = "${length(var.friendly_name) >0 ? var.friendly_name : "${lower(var.name)}-bq-dataset-${lower(var.environment)}" }"
    description                 = "${var.description}"
    project                     = "${var.project}"
    location                    = "${var.location}"
    default_table_expiration_ms = "${var.default_table_expiration_ms}"
    
    labels {
        name            = "${lower(var.name)}-bq-dataset-${lower(var.environment)}"
        dataset_id      = "${length(var.dataset_id) >0 ? var.dataset_id : "${random_integer.dataset.result}" }"
        environment     = "${lower(var.environment)}"
        orchestration   = "${lower(var.orchestration)}"
    }

    lifecycle {
        ignore_changes = ["dataset_id"]
        create_before_destroy = true
    }

    depends_on  = ["random_integer.dataset"] 
}

#---------------------------------------------------
# Create google bigquery table
#---------------------------------------------------
resource "random_integer" "table" {
    count   = "${var.enable_bigquery_table ? 1 : 0}"

    min     = 10
    max     = 1024
    keepers = {
        table_id = "${var.table_id}"
    }
}

resource "google_bigquery_table" "bigquery_table" {
    count           = "${var.enable_bigquery_table ? 1 : 0}"
    
    project         = "${var.project}"
    dataset_id      = "${var.dataset_id}"
    table_id        = "${length(var.table_id) >0 ? var.table_id : "${random_integer.table.result}" }"
    description     = "${var.table_description}"    
    
    expiration_time = "${var.expiration_time}"
    friendly_name   = "${length(var.table_friendly_name) >0 ? var.table_friendly_name : "${lower(var.name)}-bq-table-${lower(var.environment)}" }"
    
    time_partitioning {
        type            = "${var.time_partitioning_type}"
        expiration_ms   = "${var.time_partitioning_expiration_ms}"
        field           = "${var.time_partitioning_field}"
    } 

    #view {
    #    query           = "${var.view_query}"
    #    use_legacy_sql  = "${var.view_use_legacy_sql}"
    #}

    labels {
        name            = "${length(var.table_friendly_name) >0 ? var.table_friendly_name : "${lower(var.name)}-bq-table-${lower(var.environment)}" }"
        table_id        = "${length(var.table_id) >0 ? var.table_id : "${random_integer.table.result}" }"
        environment     = "${lower(var.environment)}"
        orchestration   = "${lower(var.orchestration)}"
    }

    schema = "${file("${path.module}/${var.schema_file}")}"

    lifecycle {
        ignore_changes = ["dataset_id"]
        create_before_destroy = true
    }

    depends_on  = ["random_integer.table"]
}

resource "random_integer" "table_view" {
    count   = "${var.enable_bigquery_table_view ? 1 : 0}"

    min     = 10
    max     = 1024
    keepers = {
        table_id = "${var.table_id}"
    }
}

resource "google_bigquery_table" "bigquery_table_view" {
    count           = "${var.enable_bigquery_table_view ? 1 : 0}"

    project         = "${var.project}"
    dataset_id      = "${var.dataset_id}"
    table_id        = "${length(var.table_id) >0 ? var.table_id : "${random_integer.table_view.result}" }"
    description     = "${var.table_description}"

    expiration_time = "${var.expiration_time}"
    friendly_name   = "${length(var.table_friendly_name) >0 ? var.table_friendly_name : "${lower(var.name)}-bq-table-${lower(var.environment)}" }"

    time_partitioning {
        type            = "${var.time_partitioning_type}"
        expiration_ms   = "${var.time_partitioning_expiration_ms}"
        field           = "${var.time_partitioning_field}"
    }

    view {
        query           = "${var.view_query}"
        use_legacy_sql  = "${var.view_use_legacy_sql}"
    }

    labels {
        name            = "${length(var.table_friendly_name) >0 ? var.table_friendly_name : "${lower(var.name)}-bq-table-${lower(var.environment)}" }"
        table_id        = "${length(var.table_id) >0 ? var.table_id : "${random_integer.table_view.result}" }"
        environment     = "${lower(var.environment)}"
        orchestration   = "${lower(var.orchestration)}"
    }

    schema = "${file("${path.module}/${var.schema_file}")}"

    lifecycle {
        ignore_changes = ["dataset_id"]
        create_before_destroy = true
    }

    depends_on  = ["random_integer.table_view"]
}

Открываем файл:

$ vim variables.tf

И прописываем:

variable "name" {
    description = "A unique name for the resource, required by GCE. Changing this forces a new resource to be created."
    default     = "TEST"
}

variable "zone" {
  description = "The zone that the machine should be created in"
  default     = "us-east1-b"    
} 

variable "environment" {
    description = "Environment for service"
    default     = "STAGE"
}

variable "orchestration" {
    description = "Type of orchestration"
    default     = "Terraform"
}

variable "enable_bigquery_dataset" {
    description = "Enable bigquery dataset usage"
    default     = "true"
}

variable "dataset_id" {
    description = "(Required) A unique ID for the resource. Changing this forces a new resource to be created."
    default     = ""
}

variable "friendly_name" {
    description = "(Optional) A descriptive name for the dataset."
    default     = ""
}

variable "description" {
    description = "(Optional) A user-friendly description of the dataset."
    default     = ""
}

variable "project" {
    description = "(Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used."
    default     = ""
}

variable "location" {
    description = "(Optional) The geographic location where the dataset should reside. See official docs. There are two types of locations, regional or multi-regional. A regional location is a specific geographic place, such as Tokyo, and a multi-regional location is a large geographic area, such as the United States, that contains at least two geographic places. Possible regional values include: asia-northeast1 Possible multi-regional values:EU and US. The default value is multi-regional location US. Changing this forces a new resource to be created."
    default     = "US"
}

variable "default_table_expiration_ms" {
    description = "(Optional) The default lifetime of all tables in the dataset, in milliseconds. The minimum value is 3600000 milliseconds (one hour). Once this property is set, all newly-created tables in the dataset will have an expirationTime property set to the creation time plus the value in this property, and changing the value will only affect new tables, not existing ones. When the expirationTime for a given table is reached, that table will be deleted automatically. If a table's expirationTime is modified or removed before the table expires, or if you provide an explicit expirationTime when creating a table, that value takes precedence over the default expiration time indicated by this property."
    default     = "3600000"
}

variable "enable_bigquery_table" {
    description = "Enable bigquery table usage"
    default     = "false"
}

variable "table_id" {
    description = "(Required) A unique ID for the resource. Changing this forces a new resource to be created."
    default     = ""
}

variable "table_description" {
    description = "(Optional) The field description."
    default     = ""
}

variable "expiration_time" {
    description = "(Optional) The time when this table expires, in milliseconds since the epoch. If not present, the table will persist indefinitely. Expired tables will be deleted and their storage reclaimed."
    default     = "0"
}

variable "table_friendly_name" {
    description = "(Optional) A descriptive name for the table."
    default     = ""
}

variable "time_partitioning_type" {
    description = "(Required) The only type supported is DAY, which will generate one partition per day based on data loading time."
    default     = "DAY"
}
    
variable "time_partitioning_expiration_ms" {
    description = "(Optional) Number of milliseconds for which to keep the storage for a partition."
    default     = "0"
}

variable "time_partitioning_field" {
    description = "(Optional) The field used to determine how to create a time-based partition. If time-based partitioning is enabled without this value, the table is partitioned based on the load time."
    default     = ""
}

variable "view_query" {
    description = "(Required) A query that BigQuery executes when the view is referenced."
    default     = ""
}

variable "view_use_legacy_sql" {
    description = "(Optional) Specifies whether to use BigQuery's legacy SQL for this view. The default value is true. If set to false, the view will use BigQuery's standard SQL."
    default     = ""
}

variable "enable_bigquery_table_view" {
    description = "Enable bigquery table view usage"
    default     = "false"
}

variable "schema_file" {
    description = "(Optional) A JSON schema for the table."
    default     = "files/schema.json"
}

Собственно в этом файле храняться все переменные. Спасибо кэп!

Открываем последний файл:

$ vim outputs.tf

И в него вставить нужно следующие строки:

#---------------------------------------------------------------------------
# Google bigquery dataset
#---------------------------------------------------------------------------
output "google_bigquery_dataset_dataset_id" {
    description = "dataset_id of google_bigquery_dataset"
    value       = "${google_bigquery_dataset.bigquery_dataset.*.dataset_id}"
}

output "google_bigquery_dataset_id" {
    description = "ID"
    value       = "${google_bigquery_dataset.bigquery_dataset.*.id}"
}

output "google_bigquery_dataset_etag" {
    description = "etag"
    value       = "${google_bigquery_dataset.bigquery_dataset.*.etag}"
}

output "google_bigquery_dataset_friendly_name" {
    description = "friendly_name"
    value       = "${google_bigquery_dataset.bigquery_dataset.*.friendly_name}"
}

output "google_bigquery_dataset_self_link" {
    description = "self_link"
    value       = "${google_bigquery_dataset.bigquery_dataset.*.self_link}"
}

output "google_bigquery_dataset_creation_time" {
    description = "creation_time"
    value       = "${google_bigquery_dataset.bigquery_dataset.*.creation_time}"
}

#---------------------------------------------------------------------------
# Google bigquery table
#---------------------------------------------------------------------------
output "google_bigquery_table_etag" {
    description = "etag"
    value       = "${google_bigquery_table.bigquery_table.*.etag}"
}

output "google_bigquery_table_self_link" {
    description = "self_link"
    value       = "${google_bigquery_table.bigquery_table.*.self_link}"
}

output "google_bigquery_table_table_id" {
    description = "table_id"
    value       = "${google_bigquery_table.bigquery_table.*.table_id}"
}

output "google_bigquery_table_view_etag" {
    description = "etag"
    value       = "${google_bigquery_table.bigquery_table_view.*.etag}"
}

output "google_bigquery_table_view_self_link" {
    description = "self_link"
    value       = "${google_bigquery_table.bigquery_table_view.*.self_link}"
}

output "google_bigquery_table_view_table_id" {
    description = "table_id"
    value       = "${google_bigquery_table.bigquery_table_view.*.table_id}"
}

Переходим теперь в папку google_cloud_platform/examples и создадим еще одну папку для проверки написанного чуда:

$ mkdir google_bigquery && cd $_

Внутри созданной папки открываем файл:

$ vim main.tf

Вставляем:

#
# MAINTAINER Vitaliy Natarov "vitaliy.natarov@yahoo.com"
#
terraform {
  required_version = "> 0.9.0"
}
provider "google" {
    credentials = "${file("/Users/captain/.config/gcloud/creds/terraform_creds.json")}"
    project     = "terraform-2018"
    region      = "us-east1"
}   
module "google_bigquery" {
    source                              = "../../modules/google_bigquery"
    name                                = "TEST"

    enable_bigquery_dataset             = true
    #
    #enable_bigquery_table               = true
    #dataset_id                          = "668"
    
}

Все уже написано и готово к использованию. Ну что, начнем тестирование. В папке с вашим плейбуком, выполняем:

$ terraform init

Этим действием я инициализирую проект. Затем, подтягиваю модуль:

$ terraform get

PS: Для обновление изменений в самом модуле, можно выполнять:

$ terraform get -update

Проверим валидацию:

$ terraform validate

Запускем прогон:

$ terraform plan

Мне вывело что все у меня хорошо и можно запускать деплой:

$ terraform apply

Как видно с вывода, — все прошло гладко! Чтобы удалить созданное творение, можно выполнить:

$ terraform destroy

Весь материал аплоаджу в github аккаунт для удобства использования:

$ git clone https://github.com/SebastianUA/terraform.git

Вот и все на этом. Данная статья «Работа с Google Cloud Platform (google bigquery) и Terraform в Unix/Linux» завершена.

The post Работа с Google Cloud Platform (google bigquery) и Terraform в Unix/Linux first appeared on linux-notes.org.]]>
https://linux-notes.org/rabota-s-google-cloud-platform-google-bigquery-i-terraform-v-unix-linux/feed/ 0
Page_c76a3fcf https://linux-notes.org/rabota-s-google-cloud-platform-google-bigtable-i-terraform-v-unix-linux/ https://linux-notes.org/rabota-s-google-cloud-platform-google-bigtable-i-terraform-v-unix-linux/#respond Wed, 18 Jul 2018 21:55:08 +0000 http://linux-notes.org/?p=15849 Работа с Google Cloud Platform (google bigtable) и Terraform в Unix/Linux Google Cloud Platrorm — это платформа вида «инфраструктура как сервис» (IaaS), позволяющая клиентам создавать, тестировать и развертывать собственные приложения на инфраструктуре Google, в высокопроизводительных виртуальных машинах. Google Compute Engine предоставляет виртуальные машины, работающие в инновационных центрах обработки данных Google и всемирной сети. BigTable — проприетарная […]

The post Работа с Google Cloud Platform (google bigtable) и Terraform в Unix/Linux first appeared on linux-notes.org.]]>

Работа с Google Cloud Platform (google bigtable) и Terraform в Unix/Linux

Google Cloud Platrorm — это платформа вида «инфраструктура как сервис» (IaaS), позволяющая клиентам создавать, тестировать и развертывать собственные приложения на инфраструктуре Google, в высокопроизводительных виртуальных машинах.

Google Compute Engine предоставляет виртуальные машины, работающие в инновационных центрах обработки данных Google и всемирной сети.

BigTable — проприетарная высокопроизводительная база данных, построенная на основе Google File System (GFS), Chubby Lock Service и некоторых других продуктах Google. В настоящий момент не распространяется и не используется за пределами Google, хотя Google предлагает использовать её как часть Google App Engine.

Установка terraform в Unix/Linux

Установка крайне примитивная и я описал как это можно сделать тут:

Установка terraform в Unix/Linux

Вот еще полезные статьи по GCP + Terrafrom:

Работа с Google Cloud Platform (compute instance) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute health check) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute target pool) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute forwarding rule) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute firewall) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute disk) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute image) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute instance template) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute instance group manager) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute autoscaler) и Terraform в Unix/Linux

Работа с Google Cloud Platform (google kms) и Terraform в Unix/Linux

Работа с Google Cloud Platform (storage bucket) и Terraform в Unix/Linux

Работа с Google Cloud Platform (google pubsub) и Terraform в Unix/Linux

Работа с Google Cloud Platform (google dns) и Terraform в Unix/Linux

Работа с Google Cloud Platform (cloudbuild_trigger) и Terraform в Unix/Linux

Работа с Google Cloud Platform (redis instance) и Terraform в Unix/Linux

Работа с Google Cloud Platform (sql database instance) и Terraform в Unix/Linux

Работа с Google Cloud Platform (sourcerepo repository) и Terraform в Unix/Linux

Работа с Google Cloud Platform (dataflow job) и Terraform в Unix/Linux

Работа с Google Cloud Platform (endpoints service) и Terraform в Unix/Linux

Работа с Google Cloud Platform (spanner instance) и Terraform в Unix/Linux

Работа с Google Cloud Platform (google runtimeconfig) и Terraform в Unix/Linux

Генерация документации для Terraform с Python в Unix/Linux

Так же, в данной статье, я создал скрипт для автоматической установки данного ПО. Он был протестирован на CentOS 6/7, Debian 8 и на Mac OS X. Все работает должным образом!

Чтобы получить помощь по использованию команд, выполните:

$ terraform --help
Usage: terraform [--version] [--help] <command> [args]

The available commands for execution are listed below.
The most common, useful commands are shown first, followed by
less common or more advanced commands. If you're just getting
started with Terraform, stick with the common commands. For the
other commands, please read the help and docs before usage.

Common commands:
    apply              Builds or changes infrastructure
    console            Interactive console for Terraform interpolations
    destroy            Destroy Terraform-managed infrastructure
    env                Workspace management
    fmt                Rewrites config files to canonical format
    get                Download and install modules for the configuration
    graph              Create a visual graph of Terraform resources
    import             Import existing infrastructure into Terraform
    init               Initialize a Terraform working directory
    output             Read an output from a state file
    plan               Generate and show an execution plan
    providers          Prints a tree of the providers used in the configuration
    push               Upload this Terraform module to Atlas to run
    refresh            Update local state file against real resources
    show               Inspect Terraform state or plan
    taint              Manually mark a resource for recreation
    untaint            Manually unmark a resource as tainted
    validate           Validates the Terraform files
    version            Prints the Terraform version
    workspace          Workspace management

All other commands:
    debug              Debug output management (experimental)
    force-unlock       Manually unlock the terraform state
    state              Advanced state management

Приступим к использованию!

Работа с Google Cloud Platform (google bigtable) и Terraform в Unix/Linux

Первое что нужно сделать — это настроить «Cloud Identity». С помощью сервиса Google Cloud Identity вы сможете предоставлять доменам, пользователям и аккаунтам в организации доступ к ресурсам Cloud, а также централизованно управлять пользователями и группами через консоль администратора Google.

Полезное чтиво:

Установка Google Cloud SDK/gcloud в Unix/Linux

У меня есть папка terraform, в ней у меня будут лежать провайдеры с которыми я буду работать. Т.к в этом примере я буду использовать google_cloud_platform, то создам данную папку и перейду в нее. Далее, в этой папке, стоит создать:

$ mkdir examples modules

В папке examples, я буду хранить так званые «плейбуки» для разварачивания различных служб, например — zabbix-server, grafana, web-серверы и так далее. В modules директории, я буду хранить все необходимые модули.

Начнем писать модуль, но для этой задачи, я создам папку:

$  mkdir modules/google_bigtable

Переходим в нее:

$ cd modules/google_bigtable

Открываем файл:

$ vim google_bigtable.tf

В данный файл, вставляем:

#---------------------------------------------------
# Create bigtable instance
#---------------------------------------------------
resource "google_bigtable_instance" "bigtable_instance" {
    count           = "${var.enable_bigtable_instance ? 1 :0}"

    name            = "${lower(var.name)}-bt-instance-${lower(var.environment)}"
    display_name    = "${var.display_name}"
    cluster_id      = "${length(var.cluster_id) >0 ? var.cluster_id : "${lower(var.name)}-bt-instance-${lower(var.environment)}" }"
    project         = "${var.project}"
    zone            = "${var.zone}"
    num_nodes       = "${var.num_nodes}"
    instance_type   = "${var.instance_type}"
    storage_type    = "${var.storage_type}"
    
    lifecycle {
        ignore_changes = []
        create_before_destroy = true
    }
}

#---------------------------------------------------
#Create bigtable table
#---------------------------------------------------
resource "google_bigtable_table" "bigtable_table" {
    count           = "${var.enable_bigtable_table ? 1 : 0}"
    
    name            = "${length(var.table_name) >0 ? var.table_name : "${lower(var.name)}-bt-table-${lower(var.environment)}" }"
    project         = "${var.project}"
    instance_name   = "${var.instance_name}"
    split_keys      = ["${var.split_keys}"]

    lifecycle {
        ignore_changes = []
        create_before_destroy = true
    }
}

Открываем файл:

$ vim variables.tf

И прописываем:

variable "name" {
    description = "A unique name for the resource, required by GCE. Changing this forces a new resource to be created."
    default     = "TEST"
}

variable "enable_bigtable_instance" {
  description = "Enable bigtable instance creating"
  default     = "true"    
} 

variable "environment" {
    description = "Environment for service"
    default     = "STAGE"
}

variable "cluster_id" {
    description = "(Required) The ID of the Cloud Bigtable cluster."
    default     = ""
}

variable "zone" {
    description = "(Required) The zone to create the Cloud Bigtable cluster in. Zones that support Bigtable instances are noted on the Cloud Bigtable locations page."
    default     = "us-east1-c"
}

variable "num_nodes" {
    description = "(Optional) The number of nodes in your Cloud Bigtable cluster. Minimum of 3 for a PRODUCTION instance. Cannot be set for a DEVELOPMENT instance."
    default     = "3"
}

variable "instance_type" {
    description = "(Optional) The instance type to create. One of 'DEVELOPMENT' or 'PRODUCTION'. Defaults to 'PRODUCTION'."
    default     = "PRODUCTION"
}

variable "storage_type" {
    description = "(Optional) The storage type to use. One of 'SSD' or 'HDD'. Defaults to 'SSD'."
    default     = "SSD"
}

variable "project" {
    description = "(Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used."
    default     = ""
}

variable "display_name" {
    description = "(Optional) The human-readable display name of the Bigtable instance. Defaults to the instance name."
    default     = ""
}

variable "enable_bigtable_table" {
    description = "Enable bigtable table usage"
    default     = "false"
}

variable "table_name" {
    description = "The name of the table."
    default     = ""
}

variable "instance_name" {
    description = "(Required) The name of the Bigtable instance."
    default     = ""
}

variable "split_keys" {
    description = "(Optional) A list of predefined keys to split the table on."
    default     = []
}

Собственно в этом файле храняться все переменные. Спасибо кэп!

Открываем последний файл:

$ vim outputs.tf

И в него вставить нужно следующие строки:

output "google_bigtable_instance_name" {
    description = "Name of google bigtable instance"
    value       = "${google_bigtable_instance.bigtable_instance.*.name}"
}

output "google_bigtable_instance_id" {
    description = "ID"
    value       = "${google_bigtable_instance.bigtable_instance.*.id}"
}

output "google_bigtable_table_name" {
    description = "Name of google_bigtable_table_name"
    value       = "${google_bigtable_table.bigtable_table.*.name}"
}

output "google_bigtable_table_id" {
    description = "ID"
    value       = "${google_bigtable_table.bigtable_table.*.id}"
}

Переходим теперь в папку google_cloud_platform/examples и создадим еще одну папку для проверки написанного чуда:

$ mkdir google_bigtable && cd $_

Внутри созданной папки открываем файл:

$ vim main.tf

Вставляем:

#
# MAINTAINER Vitaliy Natarov "vitaliy.natarov@yahoo.com"
#
terraform {
  required_version = "> 0.9.0"
}
provider "google" {
    credentials = "${file("/Users/captain/.config/gcloud/creds/terraform_creds.json")}"
    project     = "terraform-2018"
    region      = "us-east1"
}   
module "google_bigtable" {
    source                              = "../../modules/google_bigtable"
    name                                = "TEST"

    enable_bigtable_instance            = true
    # table
    #enable_bigtable_table               = true
    #instance_name                       = "test-bt-instance-stage"
    #split_keys                          = ["a", "b", "c"]
}           

module "google_bigtable_table" {
    source                              = "../../modules/google_bigtable"
    name                                = "TEST"

    enable_bigtable_instance            = false
    enable_bigtable_table               = true
    instance_name                       = "${element(module.google_bigtable.google_bigtable_instance_name, 0)}"
    split_keys                          = ["a", "b", "c"]

}

Все уже написано и готово к использованию. Ну что, начнем тестирование. В папке с вашим плейбуком, выполняем:

$ terraform init

Этим действием я инициализирую проект. Затем, подтягиваю модуль:

$ terraform get

PS: Для обновление изменений в самом модуле, можно выполнять:

$ terraform get -update

Проверим валидацию:

$ terraform validate

Запускем прогон:

$ terraform plan

Мне вывело что все у меня хорошо и можно запускать деплой:

$ terraform apply

Как видно с вывода, — все прошло гладко! Чтобы удалить созданное творение, можно выполнить:

$ terraform destroy

Весь материал аплоаджу в github аккаунт для удобства использования:

$ git clone https://github.com/SebastianUA/terraform.git

Вот и все на этом. Данная статья «Работа с Google Cloud Platform (google bigtable) и Terraform в Unix/Linux» завершена.

The post Работа с Google Cloud Platform (google bigtable) и Terraform в Unix/Linux first appeared on linux-notes.org.]]>
https://linux-notes.org/rabota-s-google-cloud-platform-google-bigtable-i-terraform-v-unix-linux/feed/ 0
Page_c76a3fcf https://linux-notes.org/rabota-s-google-cloud-platform-google-runtimeconfig-i-terraform-v-unix-linux/ https://linux-notes.org/rabota-s-google-cloud-platform-google-runtimeconfig-i-terraform-v-unix-linux/#respond Wed, 18 Jul 2018 17:46:49 +0000 http://linux-notes.org/?p=15838 Работа с Google Cloud Platform (google runtimeconfig) и Terraform в Unix/Linux Google Cloud Platrorm — это платформа вида «инфраструктура как сервис» (IaaS), позволяющая клиентам создавать, тестировать и развертывать собственные приложения на инфраструктуре Google, в высокопроизводительных виртуальных машинах. Google Compute Engine предоставляет виртуальные машины, работающие в инновационных центрах обработки данных Google и всемирной сети. Google runtimeconfig — […]

The post Работа с Google Cloud Platform (google runtimeconfig) и Terraform в Unix/Linux first appeared on linux-notes.org.]]>

Работа с Google Cloud Platform (google runtimeconfig) и Terraform в Unix/Linux

Google Cloud Platrorm — это платформа вида «инфраструктура как сервис» (IaaS), позволяющая клиентам создавать, тестировать и развертывать собственные приложения на инфраструктуре Google, в высокопроизводительных виртуальных машинах.

Google Compute Engine предоставляет виртуальные машины, работающие в инновационных центрах обработки данных Google и всемирной сети.

Google runtimeconfig — сервис который хранит в себе ключ\значение. Собственно вот такой k/v сторедж. Я пока еще не понял для чего его можно использовать. Возможно дальше станет более понятен резон при использовании других сервисов.

Установка terraform в Unix/Linux

Установка крайне примитивная и я описал как это можно сделать тут:

Установка terraform в Unix/Linux

Вот еще полезные статьи по GCP + Terrafrom:

Работа с Google Cloud Platform (compute instance) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute health check) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute target pool) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute forwarding rule) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute firewall) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute disk) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute image) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute instance template) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute instance group manager) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute autoscaler) и Terraform в Unix/Linux

Работа с Google Cloud Platform (google kms) и Terraform в Unix/Linux

Работа с Google Cloud Platform (storage bucket) и Terraform в Unix/Linux

Работа с Google Cloud Platform (google pubsub) и Terraform в Unix/Linux

Работа с Google Cloud Platform (google dns) и Terraform в Unix/Linux

Работа с Google Cloud Platform (cloudbuild_trigger) и Terraform в Unix/Linux

Работа с Google Cloud Platform (redis instance) и Terraform в Unix/Linux

Работа с Google Cloud Platform (sql database instance) и Terraform в Unix/Linux

Работа с Google Cloud Platform (sourcerepo repository) и Terraform в Unix/Linux

Работа с Google Cloud Platform (dataflow job) и Terraform в Unix/Linux

Работа с Google Cloud Platform (endpoints service) и Terraform в Unix/Linux

Работа с Google Cloud Platform (spanner instance) и Terraform в Unix/Linux

Генерация документации для Terraform с Python в Unix/Linux

Так же, в данной статье, я создал скрипт для автоматической установки данного ПО. Он был протестирован на CentOS 6/7, Debian 8 и на Mac OS X. Все работает должным образом!

Чтобы получить помощь по использованию команд, выполните:

$ terraform --help
Usage: terraform [--version] [--help] <command> [args]

The available commands for execution are listed below.
The most common, useful commands are shown first, followed by
less common or more advanced commands. If you're just getting
started with Terraform, stick with the common commands. For the
other commands, please read the help and docs before usage.

Common commands:
    apply              Builds or changes infrastructure
    console            Interactive console for Terraform interpolations
    destroy            Destroy Terraform-managed infrastructure
    env                Workspace management
    fmt                Rewrites config files to canonical format
    get                Download and install modules for the configuration
    graph              Create a visual graph of Terraform resources
    import             Import existing infrastructure into Terraform
    init               Initialize a Terraform working directory
    output             Read an output from a state file
    plan               Generate and show an execution plan
    providers          Prints a tree of the providers used in the configuration
    push               Upload this Terraform module to Atlas to run
    refresh            Update local state file against real resources
    show               Inspect Terraform state or plan
    taint              Manually mark a resource for recreation
    untaint            Manually unmark a resource as tainted
    validate           Validates the Terraform files
    version            Prints the Terraform version
    workspace          Workspace management

All other commands:
    debug              Debug output management (experimental)
    force-unlock       Manually unlock the terraform state
    state              Advanced state management

Приступим к использованию!

Работа с Google Cloud Platform (google runtimeconfig) и Terraform в Unix/Linux

Первое что нужно сделать — это настроить «Cloud Identity». С помощью сервиса Google Cloud Identity вы сможете предоставлять доменам, пользователям и аккаунтам в организации доступ к ресурсам Cloud, а также централизованно управлять пользователями и группами через консоль администратора Google.

Полезное чтиво:

Установка Google Cloud SDK/gcloud в Unix/Linux

У меня есть папка terraform, в ней у меня будут лежать провайдеры с которыми я буду работать. Т.к в этом примере я буду использовать google_cloud_platform, то создам данную папку и перейду в нее. Далее, в этой папке, стоит создать:

$ mkdir examples modules

В папке examples, я буду хранить так званые «плейбуки» для разварачивания различных служб, например — zabbix-server, grafana, web-серверы и так далее. В modules директории, я буду хранить все необходимые модули.

Начнем писать модуль, но для этой задачи, я создам папку:

$  mkdir modules/google_runtimeconfig

Переходим в нее:

$ cd modules/google_runtimeconfig

Открываем файл:

$ vim google_runtimeconfig.tf

В данный файл, вставляем:

#---------------------------------------------------
# Create runtimeconfig config
#---------------------------------------------------
resource "google_runtimeconfig_config" "runtimeconfig_config" {
    
    name        = "${lower(var.name)}-rc-config-${lower(var.environment)}"
    description = "${var.description}"
    project     = "${var.project}"

    lifecycle {
        ignore_changes = []
        create_before_destroy = true
    }
}
#---------------------------------------------------
# Create runtimeconfig variable 
#---------------------------------------------------
resource "google_runtimeconfig_variable" "runtimeconfig_variable_text" {
    count       = "${var.enable_runtimeconfig_variable_text_usage ? 1 : 0}"
    
    parent      = "${var.runtimeconfig_config_name}"
    name        = "${lower(var.name)}-rc-variable-${lower(var.environment)}"
    project     = "${var.project}"
    text        = "${var.text}"

    lifecycle {
        ignore_changes = []
        create_before_destroy = true
    }
}

resource "google_runtimeconfig_variable" "runtimeconfig_variable_value" {
    count       = "${var.enable_runtimeconfig_variable_value_usage ? 1 : 0}"

    parent      = "${var.runtimeconfig_config_name}"
    name        = "${lower(var.name)}-rc-variable-${lower(var.environment)}"
    project     = "${var.project}"
    value       = "${length(var.value) >0 ? "${base64encode(var.value)}" : "${base64encode(file("${path.module}/${var.value_file}"))}" }"
    
    lifecycle {
        ignore_changes = []
        create_before_destroy = true
    }
}

Открываем файл:

$ vim variables.tf

И прописываем:

variable "name" {
    description = "A unique name for the resource, required by GCE. Changing this forces a new resource to be created."
    default     = "TEST"
}

variable "environment" {
    description = "Environment for service"
    default     = "STAGE"
}

variable "description" {
    description = "(Optional) The description to associate with the runtime config."
    default     = ""
}

variable "project" {
    description = "(Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used."
    default     = ""
}

variable "enable_runtimeconfig_variable_text_usage" {
    description = "Enable runtimeconfig variable with text usage"
    default     = "false"
}

variable "runtimeconfig_config_name" {
    description = "(Required) The name of the RuntimeConfig resource containing this variable."
    default     = ""
}

variable "text" {
    description = "(Required) The content to associate with the variable. Exactly one of text or variable must be specified. If text is specified, it must be a valid UTF-8 string and less than 4096 bytes in length. If value is specified, it must be base64 encoded and less than 4096 bytes in length."
    default     = ""
}

variable "value" {
    description = "(Required) The content to associate with the variable. Exactly one of text or variable must be specified. If text is specified, it must be a valid UTF-8 string and less than 4096 bytes in length. If value is specified, it must be base64 encoded and less than 4096 bytes in length."
    default     = ""
}

variable "enable_runtimeconfig_variable_value_usage" {
    description = "Enable runtimeconfig variable with value usage"
    default     = "false"
}

variable "value_file" {
    description = "Path to file with value data"
    default     = "files/file_name.dat"
}

Собственно в этом файле храняться все переменные. Спасибо кэп!

Открываем последний файл:

$ vim outputs.tf

И в него вставить нужно следующие строки:

output "google_runtimeconfig_config_name" {
    description = "Name of google_runtimeconfig_config"
    value       = "${google_runtimeconfig_config.runtimeconfig_config.name}"
}

output "google_runtimeconfig_config_id" {
    description = "ID"
    value       = "${google_runtimeconfig_config.runtimeconfig_config.id}"
}

output "google_runtimeconfig_variable_text_update_time" {
    description = "update_time"
    value       = "${google_runtimeconfig_variable.runtimeconfig_variable_text.*.update_time}"
}

output "google_runtimeconfig_variable_value_update_time" {
    description = "update_time"
    value       = "${google_runtimeconfig_variable.runtimeconfig_variable_value.*.update_time}"
}

Переходим теперь в папку google_cloud_platform/examples и создадим еще одну папку для проверки написанного чуда:

$ mkdir google_runtimeconfig && cd $_

Внутри созданной папки открываем файл:

$ vim main.tf

Вставляем:

#
# MAINTAINER Vitaliy Natarov "vitaliy.natarov@yahoo.com"
#
terraform {
  required_version = "> 0.9.0"
}
provider "google" {
    credentials = "${file("/Users/captain/.config/gcloud/creds/terraform_creds.json")}"
    project     = "terraform-2018"
    region      = "us-east1"
}   
module "google_runtimeconfig" {
    source                                      = "../../modules/google_runtimeconfig"
    name                                        = "TEST"
                                        
    # variable with text
    #enable_runtimeconfig_variable_text_usage    = "true"
    #runtimeconfig_config_name                   = "test-rc-config-stage"
    #text                                        = "linux-notes.org"

    # variable with value
    #enable_runtimeconfig_variable_value_usage   = true
    #runtimeconfig_config_name                   = "test-rc-config-stage"
    #value                                       = "test2"
    #value_file                                  = "files/file_name.dat"
    
}    

Все уже написано и готово к использованию. Ну что, начнем тестирование. В папке с вашим плейбуком, выполняем:

$ terraform init

Этим действием я инициализирую проект. Затем, подтягиваю модуль:

$ terraform get

PS: Для обновление изменений в самом модуле, можно выполнять:

$ terraform get -update

Проверим валидацию:

$ terraform validate

Запускем прогон:

$ terraform plan

Мне вывело что все у меня хорошо и можно запускать деплой:

$ terraform apply

Как видно с вывода, — все прошло гладко! Чтобы удалить созданное творение, можно выполнить:

$ terraform destroy

Весь материал аплоаджу в github аккаунт для удобства использования:

$ git clone https://github.com/SebastianUA/terraform.git

Вот и все на этом. Данная статья «Работа с Google Cloud Platform (google runtimeconfig) и Terraform в Unix/Linux» завершена.

The post Работа с Google Cloud Platform (google runtimeconfig) и Terraform в Unix/Linux first appeared on linux-notes.org.]]>
https://linux-notes.org/rabota-s-google-cloud-platform-google-runtimeconfig-i-terraform-v-unix-linux/feed/ 0
Page_c76a3fcf https://linux-notes.org/rabota-s-google-cloud-platform-spanner-instance-i-terraform-v-unix-linux/ https://linux-notes.org/rabota-s-google-cloud-platform-spanner-instance-i-terraform-v-unix-linux/#respond Wed, 18 Jul 2018 11:10:14 +0000 http://linux-notes.org/?p=15832 Работа с Google Cloud Platform (spanner instance) и Terraform в Unix/Linux Google Cloud Platrorm — это платформа вида «инфраструктура как сервис» (IaaS), позволяющая клиентам создавать, тестировать и развертывать собственные приложения на инфраструктуре Google, в высокопроизводительных виртуальных машинах. Google Compute Engine предоставляет виртуальные машины, работающие в инновационных центрах обработки данных Google и всемирной сети. Cloud Spanner – полностью управляемый […]

The post Работа с Google Cloud Platform (spanner instance) и Terraform в Unix/Linux first appeared on linux-notes.org.]]>

Работа с Google Cloud Platform (spanner instance) и Terraform в Unix/Linux

Google Cloud Platrorm — это платформа вида «инфраструктура как сервис» (IaaS), позволяющая клиентам создавать, тестировать и развертывать собственные приложения на инфраструктуре Google, в высокопроизводительных виртуальных машинах.

Google Compute Engine предоставляет виртуальные машины, работающие в инновационных центрах обработки данных Google и всемирной сети.

Cloud Spanner – полностью управляемый сервис реляционных баз данных, который обеспечивает согласованность критически важных транзакций на глобальном уровне. Он поддерживает стандартную реляционную семантику (схемы, ACID-транзакции, SQL) и автоматическую синхронную репликацию для обеспечения высокой доступности.

Установка terraform в Unix/Linux

Установка крайне примитивная и я описал как это можно сделать тут:

Установка terraform в Unix/Linux

Вот еще полезные статьи по GCP + Terrafrom:

Работа с Google Cloud Platform (compute instance) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute health check) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute target pool) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute forwarding rule) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute firewall) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute disk) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute image) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute instance template) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute instance group manager) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute autoscaler) и Terraform в Unix/Linux

Работа с Google Cloud Platform (google kms) и Terraform в Unix/Linux

Работа с Google Cloud Platform (storage bucket) и Terraform в Unix/Linux

Работа с Google Cloud Platform (google pubsub) и Terraform в Unix/Linux

Работа с Google Cloud Platform (google dns) и Terraform в Unix/Linux

Работа с Google Cloud Platform (cloudbuild_trigger) и Terraform в Unix/Linux

Работа с Google Cloud Platform (redis instance) и Terraform в Unix/Linux

Работа с Google Cloud Platform (sql database instance) и Terraform в Unix/Linux

Работа с Google Cloud Platform (sourcerepo repository) и Terraform в Unix/Linux

Работа с Google Cloud Platform (dataflow job) и Terraform в Unix/Linux

Работа с Google Cloud Platform (endpoints service) и Terraform в Unix/Linux

Генерация документации для Terraform с Python в Unix/Linux

Так же, в данной статье, я создал скрипт для автоматической установки данного ПО. Он был протестирован на CentOS 6/7, Debian 8 и на Mac OS X. Все работает должным образом!

Чтобы получить помощь по использованию команд, выполните:

$ terraform --help
Usage: terraform [--version] [--help] <command> [args]

The available commands for execution are listed below.
The most common, useful commands are shown first, followed by
less common or more advanced commands. If you're just getting
started with Terraform, stick with the common commands. For the
other commands, please read the help and docs before usage.

Common commands:
    apply              Builds or changes infrastructure
    console            Interactive console for Terraform interpolations
    destroy            Destroy Terraform-managed infrastructure
    env                Workspace management
    fmt                Rewrites config files to canonical format
    get                Download and install modules for the configuration
    graph              Create a visual graph of Terraform resources
    import             Import existing infrastructure into Terraform
    init               Initialize a Terraform working directory
    output             Read an output from a state file
    plan               Generate and show an execution plan
    providers          Prints a tree of the providers used in the configuration
    push               Upload this Terraform module to Atlas to run
    refresh            Update local state file against real resources
    show               Inspect Terraform state or plan
    taint              Manually mark a resource for recreation
    untaint            Manually unmark a resource as tainted
    validate           Validates the Terraform files
    version            Prints the Terraform version
    workspace          Workspace management

All other commands:
    debug              Debug output management (experimental)
    force-unlock       Manually unlock the terraform state
    state              Advanced state management

Приступим к использованию!

Работа с Google Cloud Platform (spanner instance) и Terraform в Unix/Linux

Первое что нужно сделать — это настроить «Cloud Identity». С помощью сервиса Google Cloud Identity вы сможете предоставлять доменам, пользователям и аккаунтам в организации доступ к ресурсам Cloud, а также централизованно управлять пользователями и группами через консоль администратора Google.

Полезное чтиво:

Установка Google Cloud SDK/gcloud в Unix/Linux

У меня есть папка terraform, в ней у меня будут лежать провайдеры с которыми я буду работать. Т.к в этом примере я буду использовать google_cloud_platform, то создам данную папку и перейду в нее. Далее, в этой папке, стоит создать:

$ mkdir examples modules

В папке examples, я буду хранить так званые «плейбуки» для разварачивания различных служб, например — zabbix-server, grafana, web-серверы и так далее. В modules директории, я буду хранить все необходимые модули.

Начнем писать модуль, но для этой задачи, я создам папку:

$  mkdir modules/spanner_instance

Переходим в нее:

$ cd modules/spanner_instance

Открываем файл:

$ vim spanner_instance.tf

В данный файл, вставляем:

#---------------------------------------------------
# Create google spanner instance
#---------------------------------------------------
resource "google_spanner_instance" "spanner_instance" {
  
    config          = "${var.config}"
    display_name    = "${length(var.display_name) >0 ? var.display_name : "${lower(var.name)}-si-${lower(var.environment)}" }"
    name            = "${lower(var.name)}-si-${lower(var.environment)}"
    num_nodes       = "${var.num_nodes}"
    project         = "${var.project}"

    labels {
        name            = "${lower(var.name)}-si-${lower(var.environment)}"
        environment     = "${lower(var.environment)}"
        orchestration   = "${lower(var.orchestration)}"
    }

    lifecycle {
        ignore_changes = []
        create_before_destroy = true
    }
}

#---------------------------------------------------
# Create google spanner iam
#---------------------------------------------------
data "google_iam_policy" "iam_policy" {
  
    binding {
        role = "${var.role}"
        members = ["${var.members}"]
    }
}

resource "google_spanner_instance_iam_policy" "spanner_instance_iam_policy" {
    count       = "${var.enable_spanner_instance_iam_policy ? 1 : 0}"  

    instance    = "${var.instance}"
    policy_data = "${data.google_iam_policy.iam_policy.policy_data}"
                    
    depends_on  = ["data.google_iam_policy.iam_policy"]

    lifecycle {
        ignore_changes = []
        create_before_destroy = true
    }

}

resource "google_spanner_instance_iam_binding" "spanner_instance_iam_binding" {
    count       = "${var.enable_spanner_instance_iam_binding ? 1 : 0}"  

    instance    = "${var.instance}"
    role        = "${var.role}"

    members     = ["${var.members}"]
    
    lifecycle {
        ignore_changes = []
        create_before_destroy = true
    }

}

resource "google_spanner_instance_iam_member" "spanner_instance_iam_member" {
    count       = "${var.enable_spanner_instance_iam_member ? 1 : 0}"

    instance    = "${var.instance}"
    role        = "${var.role}"
    member      = "${element(var.members, 0)}"

    lifecycle {
        ignore_changes = []
        create_before_destroy = true
    }
}

#---------------------------------------------------
# Create spanner database 
#---------------------------------------------------
resource "google_spanner_database" "spanner_database" {
    count       = "${var.enable_spanner_database ? 1 : 0}"    

    instance    = "${var.instance}"
    name        = "${var.db_name}"
    project     = "${var.project}"
   
    ddl       =  ["${var.ddl}"]

    lifecycle {
        ignore_changes = []
        create_before_destroy = true
    }

}

#---------------------------------------------------
# Create spanner database iam
#---------------------------------------------------
data "google_iam_policy" "database_iam_policy" {
    binding {
        role = "${var.role}"
    
        members = ["${var.members}"]
    }
}

resource "google_spanner_database_iam_policy" "spanner_database_iam_policy" {
    count           = "${var.enable_spanner_database_iam_policy ? 1 : 0}"

    instance        = "${var.instance}"
    database        = "${var.db_name}"
    policy_data     = "${data.google_iam_policy.database_iam_policy.policy_data}"

    depends_on      = ["data.google_iam_policy.database_iam_policy"]

    lifecycle {
        ignore_changes = []
        create_before_destroy = true
    }
}

resource "google_spanner_database_iam_binding" "spanner_database_iam_binding" {
    count       = "${var.enable_spanner_database_iam_binding ? 1 : 0}"  

    instance    = "${var.instance}"
    database    = "${var.db_name}"
    role        = "${var.role}"
    
    members     = ["${var.members}"]
    
    lifecycle {
        ignore_changes = []
        create_before_destroy = true
    }
}

resource "google_spanner_database_iam_member" "spanner_database_iam_member" {
    count       = "${var.enable_spanner_database_iam_member ? 1 :0}"

    instance    = "${var.instance}"
    database    = "${var.db_name}"
    role        = "${var.role}"
    member      = "${element(var.members, 0)}"

    lifecycle {
        ignore_changes = []
        create_before_destroy = true
    }
}

Открываем файл:

$ vim variables.tf

И прописываем:

variable "name" {
    description = "A unique name for the resource, required by GCE. Changing this forces a new resource to be created."
    default     = "TEST"
}

variable "environment" {
    description = "Environment for service"
    default     = "STAGE"
}

variable "project" {
    description = "(Optional) The ID of the project in which to look for the instance specified. If it is not provided, the provider project is used."
    default     = ""
}

variable "orchestration" {
    description = "Type of orchestration"
    default     = "Terraform"
}

variable "config" {
    description = "(Required) The name of the instance's configuration (similar but not quite the same as a region) which defines defines the geographic placement and replication of your databases in this instance. It determines where your data is stored. Values are typically of the form regional-europe-west1 , us-central etc. In order to obtain a valid list please consult the Configuration section of the docs."
    default     = "nam3"
}

variable "display_name" {
    description = "(Required) The descriptive name for this instance as it appears in UIs. Can be updated, however should be kept globally unique to avoid confusion."
    default     = ""
}

variable "num_nodes" {
    description = "(Optional, Computed) The number of nodes allocated to this instance. Defaults to 1. This can be updated after creation."
    default     = "1"
}

variable "enable_spanner_instance_iam_policy" {
    description = "Enable spanner instance iam policy"
    default     = "false"
}

variable "role" {
    description = "(Required) The role that should be applied. Only one google_spanner_instance_iam_binding can be used per role. Note that custom roles must be of the format [projects|organizations]/{parent-name}/roles/{role-name}."
    default     = "roles/editor"
}

variable "members" {
    description = "(Required) Identities that will be granted the privilege in role."
    default     = []
}

variable "instance" {
    description = "(Required) The name of the instance."
    default     = ""
}

variable "enable_spanner_instance_iam_binding" {
    description = "Enable spanner instance iam binding"
    default     = "false"
}

variable "enable_spanner_instance_iam_member" {
    description = "Enable spanner instance iam member"
    default     = "false"
}

variable "enable_spanner_database" {
    description = "Enable spanner DB"
    default     = "false"
}

variable "db_name" {
    description = "(Required) The name of the database."
    default     = "db-test"
}

variable "ddl" {
    description = "(Optional) An optional list of DDL statements to run inside the newly created database. Statements can create tables, indexes, etc. These statements execute atomically with the creation of the database: if there is an error in any statement, the database is not created."
    default     = []
}

variable "enable_spanner_database_iam_policy" {
    description = "Enable spanner database iam policy"
    default     = "false"
}

variable "enable_spanner_database_iam_binding" {
    description = "Enable spanner database iam binding"
    default     = "false"
}

variable "enable_spanner_database_iam_member" {
    description = "Enable spanner database iam member"
    default     = "false"
}

Собственно в этом файле храняться все переменные. Спасибо кэп!

Открываем последний файл:

$ vim outputs.tf

И в него вставить нужно следующие строки:

#-------------------------------------------------------------------
# instance
#-------------------------------------------------------------------
output "google_spanner_instance_name" {
    description = "Name of spanner_instance"
    value       = "${google_spanner_instance.spanner_instance.name}"
}

output "google_spanner_instance_state" {
    description = "The current state of the instance."
    value       = "${google_spanner_instance.spanner_instance.state}"
}

output "google_spanner_instance_id" {
    description = "ID"
    value       = "${google_spanner_instance.spanner_instance.id}"
}
#-------------------------------------------------------------------
# IAM
#-------------------------------------------------------------------
output "google_spanner_instance_iam_policy_etag" {
    description = "etag"
    value       = "${google_spanner_instance_iam_policy.spanner_instance_iam_policy.*.etag}"
}

output "google_spanner_instance_iam_binding_etag" {
    description = "etag"
    value       = "${google_spanner_instance_iam_binding.spanner_instance_iam_binding.*.etag}"
}

output "google_spanner_instance_iam_member_etag" {
    description = "etag"
    value       = "${google_spanner_instance_iam_member.spanner_instance_iam_member.*.etag}"
}
#-------------------------------------------------------------------
# DB
#-------------------------------------------------------------------
output "google_spanner_database_name" {
    description = "Name"
    value       = "${google_spanner_database.spanner_database.*.name}"
}

output "google_spanner_database_state" {
    description = "state" 
    value       = "${google_spanner_database.spanner_database.*.state}"
}
#-------------------------------------------------------------------
# DM IAM
#-------------------------------------------------------------------
output "google_spanner_database_iam_policy_etag" {
    description = "Etag"
    value       = "${google_spanner_database_iam_policy.spanner_database_iam_policy.*.etag}"
}

output "google_spanner_database_iam_binding_etag" {
    description = "Etag"
    value       = "${google_spanner_database_iam_binding.spanner_database_iam_binding.*.etag}"
}

output "google_spanner_database_iam_member_etag" {
    description = "Etag"
    value       = "${google_spanner_database_iam_member.spanner_database_iam_member.*.etag}"
}

Переходим теперь в папку google_cloud_platform/examples и создадим еще одну папку для проверки написанного чуда:

$ mkdir spanner_instance && cd $_

Внутри созданной папки открываем файл:

$ vim main.tf

Вставляем:

#
# MAINTAINER Vitaliy Natarov "vitaliy.natarov@yahoo.com"
#
terraform {
  required_version = "> 0.9.0"
}
provider "google" {
    credentials = "${file("/Users/captain/.config/gcloud/creds/terraform_creds.json")}"
    project     = "terraform-2018"
    region      = "us-east1"
}   
module "spanner_instance" {
    source                              = "../../modules/spanner_instance"
    name                                = "TEST"

    num_nodes                           = 1
    
    # spanner instance iam policy
    #enable_spanner_instance_iam_policy  = true
    #instance                            = "test-si-stage"
    #members                             = ["user:solo.metaliSebastian@gmail.com",]
    #role                                = "roles/editor"    
    #
    # spanner instance iam binding
    #enable_spanner_instance_iam_binding = true
    #instance                            = "test-si-stage"
    #members                             = [
    #    "user:solo.metaliSebastian@gmail.com",
    #]
    #role                                = "roles/editor"    
    #
    # spanner instance iam member
    #enable_spanner_instance_iam_member  = true
    #instance                            = "test-si-stage"
    #members                             = [
    #    "user:solo.metaliSebastian@gmail.com",
    #]
    #role                                = "roles/editor"
    #
    # spanner_database
    #enable_spanner_database             = true
    #instance                            = "test-si-stage"
    #db_name                             = "db-test"
    #ddl                                 = [
    #]
    #
    # Create spanner database iam
    #enable_spanner_database_iam_policy  = true
    #instance                            = "test-si-stage"
    #members                             = [
    #    "user:solo.metaliSebastian@gmail.com",
    #]
    #role                                = "roles/editor"
    #
    # spanner_database_iam_binding
    #enable_spanner_database_iam_binding = true
    #instance                            = "test-si-stage"
    #members                             = [
    #    "user:solo.metaliSebastian@gmail.com",
    #]
    #role                                = "roles/editor"
    #
    # spanner_database_iam_member
    #enable_spanner_database_iam_member  = true
    #instance                            = "test-si-stage"
    #members                             = [
    #    "user:solo.metaliSebastian@gmail.com",
    #]
    #role                                = "roles/editor"
} 

Все уже написано и готово к использованию. Ну что, начнем тестирование. В папке с вашим плейбуком, выполняем:

$ terraform init

Этим действием я инициализирую проект. Затем, подтягиваю модуль:

$ terraform get

PS: Для обновление изменений в самом модуле, можно выполнять:

$ terraform get -update

Проверим валидацию:

$ terraform validate

Запускем прогон:

$ terraform plan

Мне вывело что все у меня хорошо и можно запускать деплой:

$ terraform apply

Как видно с вывода, — все прошло гладко! Чтобы удалить созданное творение, можно выполнить:

$ terraform destroy

Весь материал аплоаджу в github аккаунт для удобства использования:

$ git clone https://github.com/SebastianUA/terraform.git

Вот и все на этом. Данная статья «Работа с Google Cloud Platform (spanner instance) и Terraform в Unix/Linux» завершена.

The post Работа с Google Cloud Platform (spanner instance) и Terraform в Unix/Linux first appeared on linux-notes.org.]]>
https://linux-notes.org/rabota-s-google-cloud-platform-spanner-instance-i-terraform-v-unix-linux/feed/ 0
Page_c76a3fcf https://linux-notes.org/rabota-s-google-cloud-platform-endpoints-service-i-terraform-v-unix-linux/ https://linux-notes.org/rabota-s-google-cloud-platform-endpoints-service-i-terraform-v-unix-linux/#respond Tue, 17 Jul 2018 11:23:02 +0000 http://linux-notes.org/?p=15827 Работа с Google Cloud Platform (endpoints service) и Terraform в Unix/Linux Google Cloud Platrorm — это платформа вида «инфраструктура как сервис» (IaaS), позволяющая клиентам создавать, тестировать и развертывать собственные приложения на инфраструктуре Google, в высокопроизводительных виртуальных машинах. Google Compute Engine предоставляет виртуальные машины, работающие в инновационных центрах обработки данных Google и всемирной сети. Cloud Endpoints — […]

The post Работа с Google Cloud Platform (endpoints service) и Terraform в Unix/Linux first appeared on linux-notes.org.]]>

Работа с Google Cloud Platform (endpoints service) и Terraform в Unix/Linux

Google Cloud Platrorm — это платформа вида «инфраструктура как сервис» (IaaS), позволяющая клиентам создавать, тестировать и развертывать собственные приложения на инфраструктуре Google, в высокопроизводительных виртуальных машинах.

Google Compute Engine предоставляет виртуальные машины, работающие в инновационных центрах обработки данных Google и всемирной сети.

Cloud Endpoints — это набор технологий, обеспечивающих сквозное управление API: написания и обслуживания вашего API (путем его обеспечения и мониторинга во время выполнения). Функциональность управления обеспечивается через Extensible Service Proxy или с использованием Framework Endpoints в Java или Python.

Установка terraform в Unix/Linux

Установка крайне примитивная и я описал как это можно сделать тут:

Установка terraform в Unix/Linux

Вот еще полезные статьи по GCP + Terrafrom:

Работа с Google Cloud Platform (compute instance) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute health check) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute target pool) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute forwarding rule) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute firewall) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute disk) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute image) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute instance template) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute instance group manager) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute autoscaler) и Terraform в Unix/Linux

Работа с Google Cloud Platform (google kms) и Terraform в Unix/Linux

Работа с Google Cloud Platform (storage bucket) и Terraform в Unix/Linux

Работа с Google Cloud Platform (google pubsub) и Terraform в Unix/Linux

Работа с Google Cloud Platform (google dns) и Terraform в Unix/Linux

Работа с Google Cloud Platform (cloudbuild_trigger) и Terraform в Unix/Linux

Работа с Google Cloud Platform (redis instance) и Terraform в Unix/Linux

Работа с Google Cloud Platform (sql database instance) и Terraform в Unix/Linux

Работа с Google Cloud Platform (sourcerepo repository) и Terraform в Unix/Linux

fdsfs

Генерация документации для Terraform с Python в Unix/Linux

Так же, в данной статье, я создал скрипт для автоматической установки данного ПО. Он был протестирован на CentOS 6/7, Debian 8 и на Mac OS X. Все работает должным образом!

Чтобы получить помощь по использованию команд, выполните:

$ terraform --help
Usage: terraform [--version] [--help] <command> [args]

The available commands for execution are listed below.
The most common, useful commands are shown first, followed by
less common or more advanced commands. If you're just getting
started with Terraform, stick with the common commands. For the
other commands, please read the help and docs before usage.

Common commands:
    apply              Builds or changes infrastructure
    console            Interactive console for Terraform interpolations
    destroy            Destroy Terraform-managed infrastructure
    env                Workspace management
    fmt                Rewrites config files to canonical format
    get                Download and install modules for the configuration
    graph              Create a visual graph of Terraform resources
    import             Import existing infrastructure into Terraform
    init               Initialize a Terraform working directory
    output             Read an output from a state file
    plan               Generate and show an execution plan
    providers          Prints a tree of the providers used in the configuration
    push               Upload this Terraform module to Atlas to run
    refresh            Update local state file against real resources
    show               Inspect Terraform state or plan
    taint              Manually mark a resource for recreation
    untaint            Manually unmark a resource as tainted
    validate           Validates the Terraform files
    version            Prints the Terraform version
    workspace          Workspace management

All other commands:
    debug              Debug output management (experimental)
    force-unlock       Manually unlock the terraform state
    state              Advanced state management

Приступим к использованию!

Работа с Google Cloud Platform (endpoints service) и Terraform в Unix/Linux

Первое что нужно сделать — это настроить «Cloud Identity». С помощью сервиса Google Cloud Identity вы сможете предоставлять доменам, пользователям и аккаунтам в организации доступ к ресурсам Cloud, а также централизованно управлять пользователями и группами через консоль администратора Google.

Полезное чтиво:

Установка Google Cloud SDK/gcloud в Unix/Linux

У меня есть папка terraform, в ней у меня будут лежать провайдеры с которыми я буду работать. Т.к в этом примере я буду использовать google_cloud_platform, то создам данную папку и перейду в нее. Далее, в этой папке, стоит создать:

$ mkdir examples modules

В папке examples, я буду хранить так званые «плейбуки» для разварачивания различных служб, например — zabbix-server, grafana, web-серверы и так далее. В modules директории, я буду хранить все необходимые модули.

Начнем писать модуль, но для этой задачи, я создам папку:

$  mkdir modules/endpoints_service

Переходим в нее:

$ cd modules/endpoints_service

Открываем файл:

$ vim endpoints_service.tf

В данный файл, вставляем:

#---------------------------------------------------
# Create endpoints service (openapi)
#---------------------------------------------------
resource "google_endpoints_service" "endpoints_service_openapi" {
    count           = "${var.enable_endpoints_service_openapi && length(var.openapi_config) >0 ? 1 : 0}"  

    service_name    = "${var.service_name}"
    project         = "${var.project}"
    openapi_config  = "${file("${path.module}/${var.openapi_config}")}"

    lifecycle {
        ignore_changes = []
        create_before_destroy = true
    }
}

#---------------------------------------------------
# Create endpoints service (grpc)
#---------------------------------------------------
resource "google_endpoints_service" "endpoints_service_grpc" {
    count                   = "${var.enable_endpoints_service_grpc && length(var.grpc_config) >0 && length(var.protoc_output_base64) >0 ? 1 : 0}"  
                
    service_name            = "${var.service_name}"
    project                 = "${var.project}"
    grpc_config             = "${file("${path.module}/${var.grpc_config}")}"
    protoc_output_base64    = "${file("${path.module}/${var.protoc_output_base64}")}"
                    
    lifecycle {
        ignore_changes = []
        create_before_destroy = true
    }
}

Открываем файл:

$ vim variables.tf

И прописываем:

variable "project" {
  description = "(Optional) The project ID that the service belongs to. If not provided, provider project is used."
  default     = ""    
} 

variable "enable_endpoints_service_openapi" {
    description = "Enable endpoints service openapi usage"
    default     = "false"
}

variable "openapi_config" {
    description = "(Optional) The full text of the OpenAPI YAML configuration as described. Set path to openapi config file. Ex: openapi_spec.yml."
    default     = ""
}

variable "enable_endpoints_service_grpc" {
    description = "Enable endpoints service grpc usage"
    default     = "false"
}

variable "grpc_config" {
    description = "(Optional) The full text of the Service Config YAML file (Example located here). If provided, must also provide protoc_output. open_api config must not be provided. Set path to grpc config file. Ex: service_spec.yml"
    default     = ""
}

variable "protoc_output_base64" {
    description = "(Optional) The full contents of the Service Descriptor File generated by protoc. This should be a compiled .pb file, base64-encoded. Set path to protoc output file. Ex: compiled_descriptor_file.pb"
    default     = ""
}

variable "service_name" {
    description = "(Required) The name of the service. Usually of the form $apiname.endpoints.$projectid.cloud.goog."
    default     = ""
}

Собственно в этом файле храняться все переменные. Спасибо кэп!

Открываем последний файл:

$ vim outputs.tf

И в него вставить нужно следующие строки:

#-----------------------------------------------------------------------
# Openapi
#-----------------------------------------------------------------------
output "google_endpoints_service_openapi_id" {
    description = "ID"
    value       = "${google_endpoints_service.endpoints_service_openapi.*.id}"
}

output "google_endpoints_service_openapi_endpoints" {
    description = "endpoints"
    value       = "${google_endpoints_service.endpoints_service_openapi.*.endpoints}"
}

output "google_endpoints_service_openapi_dns_address" {
    description = "dns_address"
    value       = "${google_endpoints_service.endpoints_service_openapi.*.dns_address}"
}

output "google_endpoints_service_openapi_apis" {
    description = "apis"
    value       = "${google_endpoints_service.endpoints_service_openapi.*.apis}"
}
#-----------------------------------------------------------------------
#
#-----------------------------------------------------------------------
output "google_endpoints_service_grpc_id" {
    description = "ID"
    value       = "${google_endpoints_service.endpoints_service_grpc.*.id}"
}

output "google_endpoints_service_grpc_endpoints" {
    description = "endpoints"
    value       = "${google_endpoints_service.endpoints_service_grpc.*.endpoints}"
}

output "google_endpoints_service_grpc_dns_address" {
    description = "dns_address"
    value       = "${google_endpoints_service.endpoints_service_grpc.*.dns_address}"
}

output "google_endpoints_service_grpc_apis" {
    description = "apis"
    value       = "${google_endpoints_service.endpoints_service_grpc.*.apis}"
}

Переходим теперь в папку google_cloud_platform/examples и создадим еще одну папку для проверки написанного чуда:

$ mkdir endpoints_service && cd $_

Внутри созданной папки открываем файл:

$ vim main.tf

Вставляем:

#
# MAINTAINER Vitaliy Natarov "vitaliy.natarov@yahoo.com"
#
terraform {
  required_version = "> 0.9.0"
}
provider "google" {
    credentials = "${file("/Users/captain/.config/gcloud/creds/terraform_creds.json")}"
    project     = "terraform-2018"
    region      = "us-east1"
}   
module "endpoints_service" {
    source                              = "../../modules/endpoints_service"

    # Use openapi 
    enable_endpoints_service_openapi    = true
    openapi_config                      = "files/openapi_spec.yml"   
    #
    # Use grpc
    #enable_endpoints_service_grpc        = true
    #grpc_config                         = "files/service_spec.yml"
    #protoc_output_base64                = "files/compiled_descriptor_file.pb"

   service_name                         = "api-name.endpoints.terraform-2018.cloud.goog"
}

Все уже написано и готово к использованию. Ну что, начнем тестирование. В папке с вашим плейбуком, выполняем:

$ terraform init

Этим действием я инициализирую проект. Затем, подтягиваю модуль:

$ terraform get

PS: Для обновление изменений в самом модуле, можно выполнять:

$ terraform get -update

Проверим валидацию:

$ terraform validate

Запускем прогон:

$ terraform plan

Мне вывело что все у меня хорошо и можно запускать деплой:

$ terraform apply

Как видно с вывода, — все прошло гладко! Чтобы удалить созданное творение, можно выполнить:

$ terraform destroy

Весь материал аплоаджу в github аккаунт для удобства использования:

$ git clone https://github.com/SebastianUA/terraform.git

Вот и все на этом. Данная статья «Работа с Google Cloud Platform (endpoints service) и Terraform в Unix/Linux» завершена.

The post Работа с Google Cloud Platform (endpoints service) и Terraform в Unix/Linux first appeared on linux-notes.org.]]>
https://linux-notes.org/rabota-s-google-cloud-platform-endpoints-service-i-terraform-v-unix-linux/feed/ 0
Page_c76a3fcf https://linux-notes.org/rabota-s-google-cloud-platform-dataflow-job-i-terraform-v-unix-linux/ https://linux-notes.org/rabota-s-google-cloud-platform-dataflow-job-i-terraform-v-unix-linux/#respond Tue, 17 Jul 2018 07:29:21 +0000 http://linux-notes.org/?p=15820 Работа с Google Cloud Platform (dataflow job) и Terraform в Unix/Linux Google Cloud Platrorm — это платформа вида «инфраструктура как сервис» (IaaS), позволяющая клиентам создавать, тестировать и развертывать собственные приложения на инфраструктуре Google, в высокопроизводительных виртуальных машинах. Google Compute Engine предоставляет виртуальные машины, работающие в инновационных центрах обработки данных Google и всемирной сети. Dataflow job — […]

The post Работа с Google Cloud Platform (dataflow job) и Terraform в Unix/Linux first appeared on linux-notes.org.]]>

Работа с Google Cloud Platform (dataflow job) и Terraform в Unix/Linux

Google Cloud Platrorm — это платформа вида «инфраструктура как сервис» (IaaS), позволяющая клиентам создавать, тестировать и развертывать собственные приложения на инфраструктуре Google, в высокопроизводительных виртуальных машинах.

Google Compute Engine предоставляет виртуальные машины, работающие в инновационных центрах обработки данных Google и всемирной сети.

Dataflow job — Создает задание в Dataflow, которое представляет собой реализацию Apache Beam, запущенную в Google Compute Engine. Для получения дополнительной информации смотрите официальную документацию для Beam и Dataflow.

Установка terraform в Unix/Linux

Установка крайне примитивная и я описал как это можно сделать тут:

Установка terraform в Unix/Linux

Вот еще полезные статьи по GCP + Terrafrom:

Работа с Google Cloud Platform (compute instance) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute health check) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute target pool) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute forwarding rule) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute firewall) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute disk) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute image) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute instance template) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute instance group manager) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute autoscaler) и Terraform в Unix/Linux

Работа с Google Cloud Platform (google kms) и Terraform в Unix/Linux

Работа с Google Cloud Platform (storage bucket) и Terraform в Unix/Linux

Работа с Google Cloud Platform (google pubsub) и Terraform в Unix/Linux

Работа с Google Cloud Platform (google dns) и Terraform в Unix/Linux

Работа с Google Cloud Platform (cloudbuild_trigger) и Terraform в Unix/Linux

Работа с Google Cloud Platform (redis instance) и Terraform в Unix/Linux

Работа с Google Cloud Platform (sql database instance) и Terraform в Unix/Linux

Работа с Google Cloud Platform (sourcerepo repository) и Terraform в Unix/Linux

Генерация документации для Terraform с Python в Unix/Linux

Так же, в данной статье, я создал скрипт для автоматической установки данного ПО. Он был протестирован на CentOS 6/7, Debian 8 и на Mac OS X. Все работает должным образом!

Чтобы получить помощь по использованию команд, выполните:

$ terraform --help
Usage: terraform [--version] [--help] <command> [args]

The available commands for execution are listed below.
The most common, useful commands are shown first, followed by
less common or more advanced commands. If you're just getting
started with Terraform, stick with the common commands. For the
other commands, please read the help and docs before usage.

Common commands:
    apply              Builds or changes infrastructure
    console            Interactive console for Terraform interpolations
    destroy            Destroy Terraform-managed infrastructure
    env                Workspace management
    fmt                Rewrites config files to canonical format
    get                Download and install modules for the configuration
    graph              Create a visual graph of Terraform resources
    import             Import existing infrastructure into Terraform
    init               Initialize a Terraform working directory
    output             Read an output from a state file
    plan               Generate and show an execution plan
    providers          Prints a tree of the providers used in the configuration
    push               Upload this Terraform module to Atlas to run
    refresh            Update local state file against real resources
    show               Inspect Terraform state or plan
    taint              Manually mark a resource for recreation
    untaint            Manually unmark a resource as tainted
    validate           Validates the Terraform files
    version            Prints the Terraform version
    workspace          Workspace management

All other commands:
    debug              Debug output management (experimental)
    force-unlock       Manually unlock the terraform state
    state              Advanced state management

Приступим к использованию!

Работа с Google Cloud Platform (dataflow job) и Terraform в Unix/Linux

Первое что нужно сделать — это настроить «Cloud Identity». С помощью сервиса Google Cloud Identity вы сможете предоставлять доменам, пользователям и аккаунтам в организации доступ к ресурсам Cloud, а также централизованно управлять пользователями и группами через консоль администратора Google.

Полезное чтиво:

Установка Google Cloud SDK/gcloud в Unix/Linux

У меня есть папка terraform, в ней у меня будут лежать провайдеры с которыми я буду работать. Т.к в этом примере я буду использовать google_cloud_platform, то создам данную папку и перейду в нее. Далее, в этой папке, стоит создать:

$ mkdir examples modules

В папке examples, я буду хранить так званые «плейбуки» для разварачивания различных служб, например — zabbix-server, grafana, web-серверы и так далее. В modules директории, я буду хранить все необходимые модули.

Начнем писать модуль, но для этой задачи, я создам папку:

$  mkdir modules/dataflow_job

Переходим в нее:

$ cd modules/dataflow_job

Открываем файл:

$ vim dataflow_job.tf

В данный файл, вставляем:

#---------------------------------------------------
# Create google dataflow job
#---------------------------------------------------
resource "google_dataflow_job" "dataflow_job" {

    name                = "${lower(var.name)}-df-job-${lower(var.environment)}"    
    project             = "${var.project}"
    zone                = "${var.zone}"

    template_gcs_path   = "${var.template_gcs_path}"
    temp_gcs_location   = "${var.temp_gcs_location}"
    
    max_workers         = "${var.max_workers}"
    on_delete           = "${var.on_delete}"
    
    parameters {
        foo = "bar"
        baz = "qux"
    }
    
    lifecycle {
        ignore_changes = []
        create_before_destroy = true
    }
}

Открываем файл:

$ vim variables.tf

И прописываем:

variable "name" {
    description = "A unique name for the resource, required by GCE. Changing this forces a new resource to be created."
    default     = "TEST"
}

variable "environment" {
    description = "Environment for service"
    default     = "STAGE"
}

variable "project" {
    description = "(Optional) The project in which the resource belongs. If it is not provided, the provider project is used."
    default     = "terraform-2018"
}

variable "template_gcs_path" {
    description = "(Required) The GCS path to the Dataflow job template. Expect 'gs://<bucket>/<path>'. Ex: 'gs://my-bucket/templates/template_file'"
    default     = ""
}

variable "temp_gcs_location" {
    description = "(Required) A writeable location on GCS for the Dataflow job to dump its temporary data. Expect 'gs://<bucket>/<path>'. Ex: 'gs://my-bucket/tmp_dir'"
    default     = ""
}

variable "zone" {
    description = "(Optional) The zone in which the created job should run. If it is not provided, the provider zone is used."
    default     = "us-east1"
}

variable "max_workers" {
    description = "(Optional) The number of workers permitted to work on the job. More workers may improve processing speed at additional cost."
    default     = "1"
}

variable "on_delete" {
    description = "(Optional) One of 'drain' or 'cancel'. Specifies behavior of deletion during terraform destroy. See above note."
    default     = "cancel"
}

variable "parameters" {
    description = "(Optional) Key/Value pairs to be passed to the Dataflow job (as used in the template)."
    default     = []
}

Собственно в этом файле храняться все переменные. Спасибо кэп!

Открываем последний файл:

$ vim outputs.tf

И в него вставить нужно следующие строки:

output "google_dataflow_job_name" {
    description = "Name of google dataflow job"
    value       = "${google_dataflow_job.dataflow_job.name}"
}

output "google_dataflow_job_state" {
    description = "State"
    value       = "${google_dataflow_job.dataflow_job.state}"
}

output "google_dataflow_job_id" {
    description = "ID"
    value       = "${google_dataflow_job.dataflow_job.id}"
}

Переходим теперь в папку google_cloud_platform/examples и создадим еще одну папку для проверки написанного чуда:

$ mkdir dataflow_job && cd $_

Внутри созданной папки открываем файл:

$ vim main.tf

Вставляем:

#
# MAINTAINER Vitaliy Natarov "vitaliy.natarov@yahoo.com"
#
terraform {
  required_version = "> 0.9.0"
}
provider "google" {
    credentials = "${file("/Users/captain/.config/gcloud/creds/terraform_creds.json")}"
    project     = "terraform-2018"
    region      = "us-east1"
}   
module "dataflow_job" {
    source                              = "../../modules/dataflow_job"
    name                                = "TEST"

    template_gcs_path                   = "gs://terraform-2018/templates/template_file"
    temp_gcs_location                   = "gs://terraform-2018/tmp_dir"
}

Все уже написано и готово к использованию. Ну что, начнем тестирование. В папке с вашим плейбуком, выполняем:

$ terraform init

Этим действием я инициализирую проект. Затем, подтягиваю модуль:

$ terraform get

PS: Для обновление изменений в самом модуле, можно выполнять:

$ terraform get -update

Проверим валидацию:

$ terraform validate

Запускем прогон:

$ terraform plan

Мне вывело что все у меня хорошо и можно запускать деплой:

$ terraform apply

Как видно с вывода, — все прошло гладко! Чтобы удалить созданное творение, можно выполнить:

$ terraform destroy

Весь материал аплоаджу в github аккаунт для удобства использования:

$ git clone https://github.com/SebastianUA/terraform.git

Вот и все на этом. Данная статья «Работа с Google Cloud Platform (dataflow job) и Terraform в Unix/Linux» завершена.

The post Работа с Google Cloud Platform (dataflow job) и Terraform в Unix/Linux first appeared on linux-notes.org.]]>
https://linux-notes.org/rabota-s-google-cloud-platform-dataflow-job-i-terraform-v-unix-linux/feed/ 0
Page_c76a3fcf https://linux-notes.org/rabota-s-google-cloud-platform-sourcerepo-repository-i-terraform-v-unix-linux/ https://linux-notes.org/rabota-s-google-cloud-platform-sourcerepo-repository-i-terraform-v-unix-linux/#respond Mon, 16 Jul 2018 20:59:30 +0000 http://linux-notes.org/?p=15814 Работа с Google Cloud Platform (sourcerepo repository) и Terraform в Unix/Linux Google Cloud Platrorm — это платформа вида «инфраструктура как сервис» (IaaS), позволяющая клиентам создавать, тестировать и развертывать собственные приложения на инфраструктуре Google, в высокопроизводительных виртуальных машинах. Google Compute Engine предоставляет виртуальные машины, работающие в инновационных центрах обработки данных Google и всемирной сети. Google Cloud Source […]

The post Работа с Google Cloud Platform (sourcerepo repository) и Terraform в Unix/Linux first appeared on linux-notes.org.]]>

Работа с Google Cloud Platform (sourcerepo repository) и Terraform в Unix/Linux

Google Cloud Platrorm — это платформа вида «инфраструктура как сервис» (IaaS), позволяющая клиентам создавать, тестировать и развертывать собственные приложения на инфраструктуре Google, в высокопроизводительных виртуальных машинах.

Google Compute Engine предоставляет виртуальные машины, работающие в инновационных центрах обработки данных Google и всемирной сети.

Google Cloud Source Repositories — это сервис для управления версиями ПО. Больше можно почитать на офичиальном сайте. А сейчас я приведу пример создание терраформ модуля.

Установка terraform в Unix/Linux

Установка крайне примитивная и я описал как это можно сделать тут:

Установка terraform в Unix/Linux

Вот еще полезные статьи по GCP + Terrafrom:

Работа с Google Cloud Platform (compute instance) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute health check) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute target pool) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute forwarding rule) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute firewall) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute disk) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute image) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute instance template) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute instance group manager) и Terraform в Unix/Linux

Работа с Google Cloud Platform (compute autoscaler) и Terraform в Unix/Linux

Работа с Google Cloud Platform (google kms) и Terraform в Unix/Linux

Работа с Google Cloud Platform (storage bucket) и Terraform в Unix/Linux

Работа с Google Cloud Platform (google pubsub) и Terraform в Unix/Linux

Работа с Google Cloud Platform (google dns) и Terraform в Unix/Linux

Работа с Google Cloud Platform (cloudbuild_trigger) и Terraform в Unix/Linux

Работа с Google Cloud Platform (redis instance) и Terraform в Unix/Linux

Работа с Google Cloud Platform (sql database instance) и Terraform в Unix/Linux

Генерация документации для Terraform с Python в Unix/Linux

Так же, в данной статье, я создал скрипт для автоматической установки данного ПО. Он был протестирован на CentOS 6/7, Debian 8 и на Mac OS X. Все работает должным образом!

Чтобы получить помощь по использованию команд, выполните:

$ terraform --help
Usage: terraform [--version] [--help] <command> [args]

The available commands for execution are listed below.
The most common, useful commands are shown first, followed by
less common or more advanced commands. If you're just getting
started with Terraform, stick with the common commands. For the
other commands, please read the help and docs before usage.

Common commands:
    apply              Builds or changes infrastructure
    console            Interactive console for Terraform interpolations
    destroy            Destroy Terraform-managed infrastructure
    env                Workspace management
    fmt                Rewrites config files to canonical format
    get                Download and install modules for the configuration
    graph              Create a visual graph of Terraform resources
    import             Import existing infrastructure into Terraform
    init               Initialize a Terraform working directory
    output             Read an output from a state file
    plan               Generate and show an execution plan
    providers          Prints a tree of the providers used in the configuration
    push               Upload this Terraform module to Atlas to run
    refresh            Update local state file against real resources
    show               Inspect Terraform state or plan
    taint              Manually mark a resource for recreation
    untaint            Manually unmark a resource as tainted
    validate           Validates the Terraform files
    version            Prints the Terraform version
    workspace          Workspace management

All other commands:
    debug              Debug output management (experimental)
    force-unlock       Manually unlock the terraform state
    state              Advanced state management

Приступим к использованию!

Работа с Google Cloud Platform (sourcerepo repository) и Terraform в Unix/Linux

Первое что нужно сделать — это настроить «Cloud Identity». С помощью сервиса Google Cloud Identity вы сможете предоставлять доменам, пользователям и аккаунтам в организации доступ к ресурсам Cloud, а также централизованно управлять пользователями и группами через консоль администратора Google.

Полезное чтиво:

Установка Google Cloud SDK/gcloud в Unix/Linux

У меня есть папка terraform, в ней у меня будут лежать провайдеры с которыми я буду работать. Т.к в этом примере я буду использовать google_cloud_platform, то создам данную папку и перейду в нее. Далее, в этой папке, стоит создать:

$ mkdir examples modules

В папке examples, я буду хранить так званые «плейбуки» для разварачивания различных служб, например — zabbix-server, grafana, web-серверы и так далее. В modules директории, я буду хранить все необходимые модули.

Начнем писать модуль, но для этой задачи, я создам папку:

$  mkdir modules/sourcerepo_repository

Переходим в нее:

$ cd modules/sourcerepo_repository

Открываем файл:

$ vim sourcerepo_repository.tf

В данный файл, вставляем:

#---------------------------------------------------
# Create sourcerepo repository
#---------------------------------------------------
resource "google_sourcerepo_repository" "sourcerepo_repository" {

    name    = "${lower(var.name)}-sr-repository-${lower(var.environment)}"
    project = "${var.project}"

    lifecycle {
        ignore_changes = []
        create_before_destroy = true
    }
}

Открываем файл:

$ vim variables.tf

И прописываем:

variable "name" {
    description = "(Required) The name of the repository that will be created."
    default     = "TEST"
}

variable "project" {
  description = "(Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used."
  default     = ""    
} 

variable "environment" {
    description = "Environment for service"
    default     = "STAGE"
}

Собственно в этом файле храняться все переменные. Спасибо кэп!

Открываем последний файл:

$ vim outputs.tf

И в него вставить нужно следующие строки:

output "google_sourcerepo_repository_name" {
    description = "Name of google sourcerepo repository"
    value       = "${google_sourcerepo_repository.sourcerepo_repository.name}"
}

output "google_sourcerepo_repository_url" {
    description = "The url to clone the repository."
    value       = "${google_sourcerepo_repository.sourcerepo_repository.url}"
}

output "google_sourcerepo_repository_size" {
    description = "The size of the repository."
    value       = "${google_sourcerepo_repository.sourcerepo_repository.size}"
}

output "google_sourcerepo_repository_id" {
    description = "ID"
    value       = "${google_sourcerepo_repository.sourcerepo_repository.id}"
}

Переходим теперь в папку google_cloud_platform/examples и создадим еще одну папку для проверки написанного чуда:

$ mkdir sourcerepo_repository && cd $_

Внутри созданной папки открываем файл:

$ vim main.tf

Вставляем:

#
# MAINTAINER Vitaliy Natarov "vitaliy.natarov@yahoo.com"
#
terraform {
  required_version = "> 0.9.0"
}
provider "google" {
    credentials = "${file("/Users/captain/.config/gcloud/creds/terraform_creds.json")}"
    project     = "terraform-2018"
    region      = "us-east1"
}   
module "sourcerepo_repository" {
    source                              = "../../modules/sourcerepo_repository"
    name                                = "TEST"
    
}

Все уже написано и готово к использованию. Ну что, начнем тестирование. В папке с вашим плейбуком, выполняем:

$ terraform init

Этим действием я инициализирую проект. Затем, подтягиваю модуль:

$ terraform get

PS: Для обновление изменений в самом модуле, можно выполнять:

$ terraform get -update

Проверим валидацию:

$ terraform validate

Запускем прогон:

$ terraform plan

Мне вывело что все у меня хорошо и можно запускать деплой:

$ terraform apply

Как видно с вывода, — все прошло гладко! Чтобы удалить созданное творение, можно выполнить:

$ terraform destroy

Весь материал аплоаджу в github аккаунт для удобства использования:

$ git clone https://github.com/SebastianUA/terraform.git

Вот и все на этом. Данная статья «Работа с Google Cloud Platform (sourcerepo repository) и Terraform в Unix/Linux» завершена.

The post Работа с Google Cloud Platform (sourcerepo repository) и Terraform в Unix/Linux first appeared on linux-notes.org.]]>
https://linux-notes.org/rabota-s-google-cloud-platform-sourcerepo-repository-i-terraform-v-unix-linux/feed/ 0