Class: Hashicorptools::RegionDeployment

Inherits:
Object
  • Object
show all
Defined in:
lib/hashicorptools/code_deploy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aws_region:, environment:) ⇒ RegionDeployment

Returns a new instance of RegionDeployment.



13
14
15
16
# File 'lib/hashicorptools/code_deploy.rb', line 13

def initialize(aws_region:, environment:)
  @aws_region = aws_region
  @environment = environment
end

Instance Attribute Details

#aws_regionObject

Returns the value of attribute aws_region.



11
12
13
# File 'lib/hashicorptools/code_deploy.rb', line 11

def aws_region
  @aws_region
end

#environmentObject

Returns the value of attribute environment.



11
12
13
# File 'lib/hashicorptools/code_deploy.rb', line 11

def environment
  @environment
end

Instance Method Details

#create_deployment(commit_id, commit_message) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/hashicorptools/code_deploy.rb', line 18

def create_deployment(commit_id, commit_message)
  client = Aws::CodeDeploy::Client.new(region: aws_region)
  response = client.create_deployment({
                                        application_name: application_name,
                                        deployment_group_name: "#{application_name}-#{@environment}",
                                        revision: {
                                          revision_type: 'GitHub',
                                          git_hub_location: {
                                            repository: "controlshift/#{application_name}",
                                            commit_id: commit_id
                                          }
                                        },
                                        description: (commit_message || "commit #{commit_id}").slice(0,99)
                                      })
  output "created deployment #{response.deployment_id}"
  output "https://console.aws.amazon.com/codedeploy/home?region=#{aws_region}#/deployments/#{response.deployment_id}"
end