All files / app/assets/javascripts/terraform/components init_command_modal.vue

100% Statements 4/4
100% Branches 2/2
100% Functions 2/2
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90      5x                                                             7x               14x   14x                                                                                          
<script>
import { GlModal, GlSprintf, GlLink } from '@gitlab/ui';
import { __, s__ } from '~/locale';
import ModalCopyButton from '~/vue_shared/components/modal_copy_button.vue';
 
export default {
  i18n: {
    title: s__('Terraform|Terraform init command'),
    explanatoryText: s__(
      `Terraform|To get access to this terraform state from your local computer, run the following command at the command line. The first line requires a personal access token with API read and write access. %{linkStart}How do I create a personal access token?%{linkEnd}.`,
    ),
    closeText: __('Close'),
    copyToClipboardText: __('Copy'),
  },
  components: {
    GlModal,
    GlSprintf,
    GlLink,
    ModalCopyButton,
  },
  inject: ['accessTokensPath', 'terraformApiUrl', 'username'],
  props: {
    modalId: {
      type: String,
      required: true,
    },
    stateName: {
      type: String,
      required: false,
      default: '',
    },
  },
  computed: {
    closeModalProps() {
      return {
        text: this.$options.i18n.closeText,
        attributes: {},
      };
    },
  },
  methods: {
    getModalInfoCopyStr() {
      const stateNameEncoded = this.stateName ? encodeURIComponent(this.stateName) : 'default';
 
      return `export GITLAB_ACCESS_TOKEN=<YOUR-ACCESS-TOKEN>
export TF_STATE_NAME=${stateNameEncoded}
terraform init \\
    -backend-config="address=${this.terraformApiUrl}/$TF_STATE_NAME" \\
    -backend-config="lock_address=${this.terraformApiUrl}/$TF_STATE_NAME/lock" \\
    -backend-config="unlock_address=${this.terraformApiUrl}/$TF_STATE_NAME/lock" \\
    -backend-config="username=${this.username}" \\
    -backend-config="password=$GITLAB_ACCESS_TOKEN" \\
    -backend-config="lock_method=POST" \\
    -backend-config="unlock_method=DELETE" \\
    -backend-config="retry_wait_min=5"
    `;
    },
  },
};
</script>
 
<template>
  <gl-modal
    ref="initCommandModal"
    :modal-id="modalId"
    :title="$options.i18n.title"
    :action-cancel="closeModalProps"
  >
    <p data-testid="init-command-explanatory-text">
      <gl-sprintf :message="$options.i18n.explanatoryText">
        <template #link="{ content }">
          <gl-link :href="accessTokensPath" target="_blank">{{ content }}</gl-link>
        </template>
      </gl-sprintf>
    </p>
 
    <div class="gl-display-flex">
      <pre class="gl-bg-gray gl-white-space-pre-wrap" data-testid="terraform-init-command">{{
        getModalInfoCopyStr()
      }}</pre>
      <modal-copy-button
        :title="$options.i18n.copyToClipboardText"
        :text="getModalInfoCopyStr()"
        :modal-id="$options.modalId"
        css-classes="gl-align-self-start gl-ml-2"
      />
    </div>
  </gl-modal>
</template>