Code Monkey home page Code Monkey logo

packer-plugin-alicloud's Introduction

Packer Plugin Alicloud

The Alicloud multi-component plugin can be used with HashiCorp Packer to create custom images. For the full list of available features for this plugin see docs.

Installation

Using pre-built releases

Using the packer init command

Starting from version 1.7, Packer supports a new packer init command allowing automatic installation of Packer plugins. Read the Packer documentation for more information.

To install this plugin, copy and paste this code into your Packer configuration . Then, run packer init.

packer {
  required_plugins {
    alicloud = {
      version = ">= 1.1.0"
      source  = "github.com/hashicorp/alicloud"
    }
  }
}

Manual installation

You can find pre-built binary releases of the plugin here. Once you have downloaded the latest archive corresponding to your target OS, uncompress it to retrieve the plugin binary file corresponding to your platform. To install the plugin, please follow the Packer documentation on installing a plugin.

From Sources

If you prefer to build the plugin from sources, clone the GitHub repository locally and run the command go build from the root directory. Upon successful compilation, a packer-plugin-alicloud plugin binary file can be found in the root directory. To install the compiled plugin, please follow the official Packer documentation on installing a plugin.

Configuration

For more information on how to configure the plugin, please read the documentation located in the docs/ directory.

Contributing

  • If you think you've found a bug in the code or you have a question regarding the usage of this software, please reach out to us by opening an issue in this GitHub repository.
  • Contributions to this project are welcome: if you want to add a feature or a fix a bug, please do so by opening a Pull Request in this GitHub repository. In case of feature contribution, we kindly ask you to open an issue to discuss it beforehand.

packer-plugin-alicloud's People

Contributors

2rs2ts avatar alexyueer avatar ashwin-mangale avatar azr avatar binkesi avatar bittopaz avatar chhaj5236 avatar chrislundquist avatar danham avatar dependabot[bot] avatar epipho avatar hashicorp-copywrite[bot] avatar jen20 avatar jescalan avatar jsoref avatar lbajolet-hashicorp avatar lrxcy avatar mitchellh avatar modrake avatar mwhooker avatar nywilken avatar rickard-von-essen avatar rogerhu avatar swampdragons avatar sylviamoss avatar timdawson264 avatar williamb1024 avatar yusungduk avatar zchsh avatar zhuzhih2017 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

packer-plugin-alicloud's Issues

Failed to get private ip of instance

Overview of the Issue

Getting error "Failed to get private ip of instance" when using VPC network when associate_public_ip_address = false

Reproduction Steps

use config as follows:

vpc_id = ...
vswitch_id = ...
associate_public_ip_address = false

Instance is creating with the private IP address assigned:

aliyun ecs DescribeInstances --RegionId cn-shanghai --InstanceIds "['i-uf63g7an1rd3tack5r9q']"
...
"InnerIpAddress": {
                                        "IpAddress": []
                                },
...
 "VpcAttributes": {
                                        "NatIpAddress": "",
                                        "PrivateIpAddress": {
                                                "IpAddress": [
                                                        "10.35.243.237"
                                                ]
                                        },
                                        "VSwitchId": "vsw-xxx",
                                        "VpcId": "vpc-xxx"
                                },
                                "ZoneId": "cn-shanghai-b"

Plugin and Packer version

1.0.4, 1.0.5.
Worked before 1.0.4.

Log Fragments and crash.log files

==> base_image.alicloud-ecs.base: Prevalidating source region and copied regions...
==> base_image.alicloud-ecs.base: Force delete flag found, skipping prevalidating image name.
==> base_image.alicloud-ecs.base: Pausing after run of step 'stepPreValidate'. Press enter to continue.
    base_image.alicloud-ecs.base: Found image ID: ubuntu_20_04_x64_20G_alibase_20220824.vhd
==> base_image.alicloud-ecs.base: Pausing after run of step 'stepCheckAlicloudSourceImage'. Press enter to continue.
==> base_image.alicloud-ecs.base: Creating temporary keypair: packer_637c64d4-b76a-755b-3e7a-ecf663a2111c
    base_image.alicloud-ecs.base: Saving key for debug purposes: ecs_base.pem
==> base_image.alicloud-ecs.base: Pausing after run of step 'stepConfigAlicloudKeyPair'. Press enter to continue.
==> base_image.alicloud-ecs.base: Pausing after run of step 'stepConfigAlicloudVPC'. Press enter to continue.
==> base_image.alicloud-ecs.base: Pausing after run of step 'stepConfigAlicloudVSwitch'. Press enter to continue.
==> base_image.alicloud-ecs.base: Pausing after run of step 'stepConfigAlicloudSecurityGroup'. Press enter to continue.
==> base_image.alicloud-ecs.base: Creating instance...
    base_image.alicloud-ecs.base: Created instance: i-uf63g7an1rd3tack5r9q
==> base_image.alicloud-ecs.base: Pausing after run of step 'stepCreateAlicloudInstance'. Press enter to continue.
==> base_image.alicloud-ecs.base: Failed to get private ip of instance
==> base_image.alicloud-ecs.base: Pausing before cleanup of step 'stepCreateAlicloudInstance'. Press enter to continue.
==> base_image.alicloud-ecs.base: Deleting instance because of cancellation or error...
==> base_image.alicloud-ecs.base: Pausing before cleanup of step 'stepConfigAlicloudSecurityGroup'. Press enter to continue.
==> base_image.alicloud-ecs.base: Pausing before cleanup of step 'stepConfigAlicloudVSwitch'. Press enter to continue.
==> base_image.alicloud-ecs.base: Pausing before cleanup of step 'stepConfigAlicloudVPC'. Press enter to continue.
==> base_image.alicloud-ecs.base: Pausing before cleanup of step 'stepConfigAlicloudKeyPair'. Press enter to continue.
==> base_image.alicloud-ecs.base: Deleting temporary keypair...
==> base_image.alicloud-ecs.base: Pausing before cleanup of step 'stepCheckAlicloudSourceImage'. Press enter to continue.
==> base_image.alicloud-ecs.base: Pausing before cleanup of step 'stepPreValidate'. Press enter to continue.
Build 'base_image.alicloud-ecs.base' finished after 15 minutes 4 seconds.

EcsRamRole mode is not supported when profile is used

When filing a bug, please include the following headings if possible. Any
example text in this template can be deleted.

Overview of the Issue

when run packer build in an ECS server in which ECSRamRole mode is configured, if the profile and shared_credentials_file attributes are configured, the packer build doesn't work.

Reproduction Steps

  1. create a linux ECS server in aliyun with RamRole configured
  2. Run aliyun configure to use ECSRamRole mode
  3. create a packer script to use the profile and shared_credentials_file attributes
  4. run the packer build

Plugin and Packer version

From 1.8.0

Simplified Packer Buildfile

source "alicloud-ecs" "base" {
  ##image_name            = "tio_base_${var.image_name}-${var.ami_build_date}"
  image_name            = "${var.image_name}-${local.timestamp}"
  image_share_account   = var.image_share_account
  internet_charge_type  = var.internet_charge_type
  instance_type         = var.instance_type
  io_optimized          = var.io_optimized
  profile               = "default"
  shared_credentials_file = "$HOME/.aliyun/config.json"
  region                = "cn-shanghai"
  source_image          = var.latest_image_id
  ram_role_name         = var.ramfole_for_oss

  system_disk_mapping {
    disk_size = var.disk_size
    disk_category = var.disk_category
  }
}

Operating system and Environment details

Linux

Log Fragments and crash.log files

==> alicloud-ecs.base: Prevalidating source region and copied regions...
==> alicloud-ecs.base: 1 error(s) occurred:
==> alicloud-ecs.base:
==> alicloud-ecs.base: * SDK.ServerError
==> alicloud-ecs.base: ErrorCode: MissingParameter
==> alicloud-ecs.base: Recommend: https://troubleshoot.api.aliyun.com?q=MissingParameter&product=Ecs
==> alicloud-ecs.base: RequestId: CE4AF14B-BE23-5686-AA80-80E6171225B9
==> alicloud-ecs.base: Message: The input parameter "AccessKeyId" that is mandatory for processing this request is not supplied.
Build 'alicloud-ecs.base' errored after 17 milliseconds 187 microseconds: 1 error(s) occurred:

Note: same configurations work well in terraform.

Support for multiple security groups with security_group_ids

Community Note

Please vote on this issue by adding a ๐Ÿ‘ reaction to the original issue to help the community and maintainers prioritize this request.
Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request.
If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Description

Currently, only one security group ID can be supplied to an instance with security_group_id. It would be great to be able to supply a list of security group IDs via a new parameter: security_group_ids.

Use Case(s)

Attach multiple, pre-existing security groups to an instance created by packer instead of just one.

Potential configuration

{
  "security_group_ids": [
    "sg-...",
    "sg-...",
    "sg-..."
  ]
}

Potential References

The basic example does not work.

Overview of the Issue

The basic example does not work, trying to build it gives the following error:

==> alicloud-ecs.basic-example: No alicloud image was found matching filters: centos_7_04_64_20G_alibase_201701015.vhd

Other regions, instance types and OSes give the same error, for instance

  instance_type = "ecs.t1.small"
  region        = "eu-central-1"
  source_image  = "ubuntu_20_04_x64_20G_alibase_20220824.vhd"

This gives the same error as with CentOS previously.

Note these are public images where in the source file step_check_source_image.go at line 38 there is the following:

  // Describe markerplace image
  describeImagesRequest.ImageOwnerAlias = "marketplace"

Trying to use a marketplace instance id does not work either - same error.

Adding a ram_role_name (required according the documentation, but also see issue #7) does not help either, then the error becomes:

2022/11/10 05:26:12 [INFO] (telemetry) ending alicloud-ecs.basic-example

* refresh Ecs sts token err: Get "http://100.100.100.200/latest/meta-data/ram/security-credentials/usp-test": dial tcp 100.100.100.200:80: i/o timeout

Reproduction Steps

  • Download the basic example and save as 'basic.example'
  • Set secret_key and access_key
  • Run 'packer build basic.example'

From packer version

  • 1.8.4
  • plugin: 1.0.4

Simplified Packer Buildfile

See https://github.com/hashicorp/packer-plugin-alicloud/blob/main/docs/builders/alicloud-ecs.mdx#basic-example

Operating system and Environment details

macOS Monterey

Log Fragments and crash.log files

Prints mostly getting started and nothing about the actual error

An argument name "system_disk_mapping" is not expected here

Overview of the Issue

While the failed information was reported when building an image using an HCL format configuration, the target image can be successfully built by a JSON format configuration with the same content.

Reproduction Steps

HCL format configuration(named alicloud.pkr.hcl):

packer init alicloud.pkr.hcl

packer build alicloud.pkr.hcl

Plugin and Packer version

Plugin version: alicloud v1.0.1

Pakcer version: packer v1.7.10

Simplified Packer Buildfile

`packer {
required_plugins{
alicloud = {
version = ">= 1.0.1"
source = "github.com/hashicorp/alicloud"
}
}
}
source "alicloud-ecs" "install-sgx"{
image_name = "sgx-env-installed"
source_image = "ubuntu_18_04_uefi_x64_20G_alibase_20210609.vhd"
ssh_username = "root"
instance_type = "ecs.g7t.large"
io_optimized = true
internet_charge_type = "PayByTraffic"
system_disk_mapping = {
"disk_category" = "cloud_essd"
}
run_tags = {
"Built by" = "Packer"
"Managed by" = "Packer"
}
}

build{
sources = ["sources.alicloud-ecs.install-sgx"]
provisioner "shell"{
script = "./enable-sgx.sh"
}
}`

Operating system and Environment details

Operating system: ubuntu 18.04

packer version: ubuntu 18.04

Log Fragments and crash.log files

Log 2022/02/25 11:48:47 [INFO] Packer version: 1.7.10 [go1.17.6 linux amd64] 2022/02/25 11:48:47 [TRACE] discovering plugins in /usr/bin 2022/02/25 11:48:47 [TRACE] discovering plugins in /root/.config/packer/plugins 2022/02/25 11:48:47 [TRACE] discovering plugins in . 2022/02/25 11:48:47 [INFO] PACKER_CONFIG env var not set; checking the default config file path 2022/02/25 11:48:47 [INFO] PACKER_CONFIG env var set; attempting to open config file: /root/.packerconfig 2022/02/25 11:48:47 [WARN] Config file doesn't exist: /root/.packerconfig 2022/02/25 11:48:47 [INFO] Setting cache directory: /root/.cache/packer 2022/02/25 11:48:47 [TRACE] listing potential installations for "github.com/hashicorp/alicloud" that match ">= 1.0.1". plugingetter.ListInstallationsOptions{FromFolders:[]stri ng{"/usr/bin/packer", ".", "/root/.config/packer/plugins"}, BinaryInstallationOptions:plugingetter.BinaryInstallationOptions{APIVersionMajor:"5", APIVersionMinor:"0", OS:"linu x", ARCH:"amd64", Ext:"", Checksummers:[]plugingetter.Checksummer{plugingetter.Checksummer{Type:"sha256", Hash:(*sha256.digest)(0xc00015a100)}}}} 2022/02/25 11:48:47 [TRACE] Found the following "github.com/hashicorp/alicloud" installations: [{/root/.config/packer/plugins/github.com/hashicorp/alicloud/packer-plugin-alicl oud_v1.0.1_x5.0_linux_amd64 v1.0.1}] 2022/02/25 11:48:47 [INFO] found external [ecs] builders from alicloud plugin 2022/02/25 11:48:47 [INFO] found external [import] post-processors from alicloud plugin 2022/02/25 11:48:47 [TRACE] Starting external plugin /root/.config/packer/plugins/github.com/hashicorp/alicloud/packer-plugin-alicloud_v1.0.1_x5.0_linux_amd64 start builder ec s 2022/02/25 11:48:47 Starting plugin: /root/.config/packer/plugins/github.com/hashicorp/alicloud/packer-plugin-alicloud_v1.0.1_x5.0_linux_amd64 []string{"/root/.config/packer/p lugins/github.com/hashicorp/alicloud/packer-plugin-alicloud_v1.0.1_x5.0_linux_amd64", "start", "builder", "ecs"} 2022/02/25 11:48:47 Waiting for RPC address for: /root/.config/packer/plugins/github.com/hashicorp/alicloud/packer-plugin-alicloud_v1.0.1_x5.0_linux_amd64 2022/02/25 11:48:47 Received unix RPC address for /root/.config/packer/plugins/github.com/hashicorp/alicloud/packer-plugin-alicloud_v1.0.1_x5.0_linux_amd64: addr is /tmp/packe r-plugin570028700 2022/02/25 11:48:47 packer-plugin-alicloud_v1.0.1_x5.0_linux_amd64 plugin: 2022/02/25 11:48:47 Plugin address: unix /tmp/packer-plugin570028700 2022/02/25 11:48:47 packer-plugin-alicloud_v1.0.1_x5.0_linux_amd64 plugin: 2022/02/25 11:48:47 Waiting for connection... 2022/02/25 11:48:47 packer-plugin-alicloud_v1.0.1_x5.0_linux_amd64 plugin: 2022/02/25 11:48:47 Serving a plugin connection... 2022/02/25 11:48:47 packer-plugin-alicloud_v1.0.1_x5.0_linux_amd64 plugin: 2022/02/25 11:48:47 [TRACE] starting builder ecs

on alicloud.pkr.hcl line 16:
(source code not available)

An argument named "system_disk_mapping" is not expected here. Did you mean to
define a block of type "system_disk_mapping"?

Error: Unsupported argument

on alicloud.pkr.hcl line 16:
(source code not available)

An argument named "system_disk_mapping" is not expected here. Did you mean to
define a block of type "system_disk_mapping"?

2022/02/25 11:48:47 Build debug mode: false
2022/02/25 11:48:47 Force build: false
2022/02/25 11:48:47 On error:
2022/02/25 11:48:47 Waiting on builds to complete...
==> Wait completed after 97 microseconds

==> Wait completed after 97 microseconds
==> Builds finished but no artifacts were created.

==> Builds finished but no artifacts were created.
2022/02/25 11:48:47 [INFO] (telemetry) Finalizing.
2022/02/25 11:48:48 waiting for all plugin processes to complete...
2022/02/25 11:48:48 /root/.config/packer/plugins/github.com/hashicorp/alicloud/packer-plugin-alicloud_v1.0.1_x5.0_linux_amd64: plugin process exited

Please add resource_group parameter (already available in CreateImage API)

Community Note

Please vote on this issue by adding a ๐Ÿ‘ reaction to the original issue to help the community and maintainers prioritize this request.
Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request.
If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Description

Please add capability to specify resource group for images. This parameter is supported by CreateImage API but not used by AliCloud builder

Use Case(s)

Taxonomy of resources (e.g. for billing)

run_tags configuration

Community Note

Please vote on this issue by adding a ๐Ÿ‘ reaction to the original issue to help the community and maintainers prioritize this request.
Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request.
If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Description

AWS EBS builder has a nice feature to add tags to the building instance as below:

run_tags (map[string]string) - Key/value pair tags to apply to the instance that is that is launched to create the EBS volumes.

It would be super nice to provider the same feature for Alicloud ECS builder.

Use Case(s)

We can add custom tags attached to the instance that is that is launched to build the image.

Potential configuration

`run_tags` (map[string]string) - Key/value pair tags to apply to the instance that is that is launched to create the ECS instance.

Potential References

https://www.packer.io/docs/builders/amazon/ebs

RamRoleArn mode is not supported when profile is used

Overview of the Issue

when run packer build in an ECS server in which RamRoleArn mode is configured, if the profile attributes are configured, the packer build doesn't work.

Reproduction Steps

  1. create a ram user in aliyun
  2. create a profile for the ram user by aliyun cli tool with RamRoleArn mode
  3. create a packer script to use the profile attributes
  4. run the packer build

Plugin and Packer Version

  1. Packer v1.8.3
  2. packer-plugin-alicloud v1.0.4

Simplified Packer Buildfile

source "alicloud-ecs" "base" {
  image_name            = "${var.image_name}-${local.timestamp}"
  image_share_account   = var.image_share_account
  internet_charge_type  = var.internet_charge_type
  instance_type         = var.instance_type
  io_optimized          = var.io_optimized
  profile               = "ram_user"
  shared_credentials_file = "$HOME/.aliyun/config.json"
  region                = "cn-shenzhen"
  source_image          = "ubuntu_20_04_x64_20G_alibase_20220824"

  system_disk_mapping {
    disk_size = var.disk_size
    disk_category = var.disk_category
  }
}

Operating system and Environment details

ubuntu 18.04

Log Fragments and crash.log files

alicloud-ecs: output will be in this color.

==> alicloud-ecs: Prevalidating source region and copied regions...
==> alicloud-ecs: Force delete flag found, skipping prevalidating image name.
==> alicloud-ecs: No alicloud image was found matching filters: ubuntu_20_04_x64_20G_alibase_20220824.vhd
Build 'alicloud-ecs' errored after 1 second 708 milliseconds: No alicloud image was found matching filters: ubuntu_20_04_x64_20G_alibase_20220824.vhd

==> Wait completed after 1 second 708 milliseconds

==> Some builds didn't complete successfully and had errors:
--> alicloud-ecs: No alicloud image was found matching filters: ubuntu_20_04_x64_20G_alibase_20220824.vhd

==> Builds finished but no artifacts were created.

SSH issue with 1.0.4

Overview of the Issue

I'm trying to create a VM on alicloud and into a particular resource group. I'm using using the provided alicloud-ecs module but it fails with a problem with the resource_group_id. According to the docs this is an acceptable optional field.

https://developer.hashicorp.com/packer/plugins/builders/alicloud

Without the resource_group_id field it runs fine.

I've then added 1.0.4 to my packer file which does get around the resource_group_id problem:

packer {
  required_plugins {
    alicloud = {
      version = "= 1.0.4"
      source  = "github.com/hashicorp/alicloud"
    }
  }
}

but it now has ssh issues:

2022/10/04 19:00:26 packer-plugin-alicloud_v1.0.4_x5.0_linux_arm64 plugin: 2022/10/04 19:00:26 [DEBUG] TCP connection to SSH ip/port failed: dial tcp :22: connect: connection refused

same packer file (without the resource_group_id) works fine so the security groups are configured correctly.

Hope someone can help with this. Thanks

Reproduction Steps

"packer.pkr.hcl" packer file (note that I've excluded the ansible provisioner from this issue)

https://gist.github.com/michaelw730/45453a0e775d8d303961d3d542cba580

"aliyun.pkrvars.hcl" vars file (values are from alicloud)

vpc_id = ""
security_group_id = ""
vswitch_id = ""
vpc_cidr_block = "172.16.0.0/24"
resource_group_id = ""

run using

packer build -var "build_number=mw" -var "access_key=$ACCESS_KEY" -var "secret_key=$SECRET_KEY" -var "image_name=debian_10_11_x64_20G_alibase_20220208.vhd" -var-file="aliyun.pkrvars.hcl" "packer.pkr.hcl"

Packer version

Packer v1.8.0

Operating system and Environment details

Ubuntu 20.04 devcontainer on Mac M1

Log Fragments and crash.log files

logs here: https://gist.github.com/michaelw730/31b70268e29da4dd5dbd7e8b435b3371

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.