Class: Pangea::Entities::Namespace

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/pangea/entities/namespace.rb

Defined Under Namespace

Classes: State, StateConfig

Instance Method Summary collapse

Instance Method Details

#local_backend?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/pangea/entities/namespace.rb', line 85

def local_backend?
  state.local?
end

#s3_backend?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/pangea/entities/namespace.rb', line 81

def s3_backend?
  state.s3?
end

#s3_configObject



103
104
105
106
107
108
109
110
111
112
# File 'lib/pangea/entities/namespace.rb', line 103

def s3_config
  raise "Namespace #{name} does not use S3 backend" unless s3_backend?
  state.config.validate_s3!
  {
    bucket: state.config.bucket,
    key: state.config.key,
    region: state.config.region,
    dynamodb_table: state.config.lock_table
  }
end

#state_configObject



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/pangea/entities/namespace.rb', line 89

def state_config
  config = {
    type: state.type,
    region: state.config.region
  }

  if s3_backend?
    config[:bucket] = state.config.bucket
    config[:lock] = state.config.lock
  end

  config.compact
end

#to_terraform_backendObject



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/pangea/entities/namespace.rb', line 114

def to_terraform_backend
  if local_backend?
    return {
      local: {
        path: state.config.path || "terraform.tfstate"
      }
    }
  end

  if state.config.bucket.nil? || state.config.bucket.empty?
    raise ValidationError, "S3 bucket is required but was nil or empty for namespace '#{name}'"
  end
  if state.config.key.nil? || state.config.key.empty?
    raise ValidationError, "S3 key is required but was nil or empty for namespace '#{name}'"
  end

  {
    s3: {
      bucket: state.config.bucket,
      key: state.config.key,
      region: state.config.region,
      dynamodb_table: state.config.lock_table,
      encrypt: state.config.encrypt
    }.compact
  }
end