GithubHelp home page GithubHelp logo

baidubce / terraform-provider-baiducloud Goto Github PK

View Code? Open in Web Editor NEW
22.0 12.0 19.0 9.28 MB

Terraform provider for BaiduCloud

Home Page: https://www.terraform.io/docs/providers/baiducloud/

License: Mozilla Public License 2.0

Makefile 0.08% Go 98.78% JavaScript 0.01% Shell 0.16% HTML 0.98%
terraform-provider baiducloud terraform

terraform-provider-baiducloud's Introduction

Terraform Provider

Requirements

  • Terraform 0.10.x
  • Go 1.11 (to build the provider plugin)

Usage

# For example, restrict baiducloud version in 0.1.x
provider "baiducloud" {
  version = "~> 0.1"
}

Building The Provider

Clone repository to: $GOPATH/src/github.com/terraform-providers/terraform-provider-baiducloud

$ mkdir -p $GOPATH/src/github.com/terraform-providers; cd $GOPATH/src/github.com/terraform-providers
$ git clone [email protected]:terraform-providers/terraform-provider-baiducloud

Enter the provider directory and build the provider

$ cd $GOPATH/src/github.com/terraform-providers/terraform-provider-baiducloud
$ make build

Using the provider

Fill in for each provider

Developing the Provider

If you wish to work on the provider, you'll first need Go installed on your machine (version 1.11+ is required). You'll also need to correctly setup a GOPATH, as well as adding $GOPATH/bin to your $PATH.

To compile the provider, run make build. This will build the provider and put the provider binary in the $GOPATH/bin directory.

$ make build
...
$ $GOPATH/bin/terraform-provider-baiducloud
...

In order to test the provider, you can simply run make test.

$ make test

In order to run the full suite of Acceptance tests, run make testacc.

Note: Acceptance tests create real resources, and often cost money to run.

$ make testacc

terraform-provider-baiducloud's People

Contributors

benbeng avatar cgriggs01 avatar garenwen avatar gola avatar paultyng avatar perhapsdy avatar sunzhaochang avatar tampermonkeyzq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

terraform-provider-baiducloud's Issues

image_id

去哪里找,麻烦暴露一下链接呗

Error: Failed to install provider

HI all,
I try to follow this link ( https://registry.terraform.io/providers/baidubce/baiducloud/latest/docs ) to initializing provider plugins, but I get bellow error:


Initializing the backend...

Initializing provider plugins...

  • Finding baidubce/baiducloud versions matching "1.10.0"...
  • Installing baidubce/baiducloud v1.10.0...

Error: Failed to install provider

Error while installing baidubce/baiducloud v1.10.0: checksum list has
unexpected SHA-256 hash
47468d260f2269cdb476786f45716278fa5b2e9c0b492e1cb01d490cd712f5b7 (expected
2e33e045a47745773aab906fe0e39f7e470d3515e2c387f2796030671f8fe4b0)


my client summary is:
OS: macOS Catalina-10.15.6
version: Terraform v0.13.4

Change cds size failed

refer to issue #8 , change disk size from 40 GB to 50 GB , got following error:

baiducloud_cds.tf-server-data: Refreshing state... [id=v-LTPPeii1]
baiducloud_eip.tf-eip: Refreshing state... [id=180.76.154.104]
baiducloud_instance.tf-server: Refreshing state... [id=i-nJMIKbZW]
baiducloud_eip_association.tf-eip-link: Refreshing state... [id=180.76.154.104]
baiducloud_cds_attachment.default: Refreshing state... [id=v-LTPPeii1]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # baiducloud_cds.tf-server-data will be updated in-place
  ~ resource "baiducloud_cds" "tf-server-data" {
      ~ disk_size_in_gb = 40 -> 50
        id              = "v-LTPPeii1"
        name            = "tf-server-data"
        # (8 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Do you want to perform these actions in workspace "vm-2"?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

baiducloud_cds.tf-server-data: Modifying... [id=v-LTPPeii1]
╷
│ Error: [ERROR] terraform-provider-baiducloud/baiducloud/resource_baiducloud_cds.go:295:
│ [ERROR] terraform-provider-baiducloud/baiducloud/service_baiducloud_cds.go:183: Resource baiducloud_cds Resize CDS volume v-LTPPeii1 Failed!!! [SDK bce-sdk-go ERROR]:
│ [Code: BadRequest; Message: Type cannot be changed to ephemeral; RequestId: 15ad24a5-ee53-4986-b08f-4c1cdb9e2852]
│ 
│   on baidu-vm.tf line 32, in resource "baiducloud_cds" "tf-server-data":
│   32: resource "baiducloud_cds" "tf-server-data" {

bec support vpc networkType

Now we can create bec with vpc network type by the param deployInstances[].networkType and deployInstances[].vpcId/subnetId when using openapi.

And it's suppoted in the Go SDK in the vendor dir, but not in this provider (service/bec/data_source_vm_instances.go).

Will support?

spot instances are not well supported

I found an undocumented way to create spot instances, by setting payment_timing to Bidding. when I executed terraform plan without any changes, I got:

~ billing                  = {
          ~ "payment_timing" = "Postpaid" -> "Bidding"
        }
...
Plan: 0 to add, 1 to change, 0 to destroy.

It seemed that spot instances were considered as postpaid instances.

[BUG Report] IAM user and IAM policy failed when the region is not bj

When the region in main.tf is not bj, resources IAM user and IAM policy will fail.

TF file content:

terraform {
required_providers {
baiducloud = {
source = "baidubce/baiducloud"
version = "~> 1.19.14"
}
}
}

provider "baiducloud" {
access_key = "xxxxxxxxxxxxxxxxx"
secret_key = "rrrrrrrrrrrrrrrrrrrr"
region = "bd" #When region is bj, success. When region is not bj, will fail.
}

resource "baiducloud_iam_user" "hpc_user" {
name = "riz268bhwa"
force_destroy = true
}

ERROR INFO (Thown out by Terraform):

│ Error: [ERROR] terraform-provider-baiducloud/baiducloud/resource_baiducloud_iam_user.go:80: Resource baiducloud_iam_user Create User kc920akch8 Failed!!! [SDK bce-sdk-go ERROR]:
│ execute http request failed! Retried 3 times, error: Post "http:///v1/user": http: no Host in request URL

Volume.DiskQuotaExceededLimit; Message: Number of volumes exceeds limit

when i create a new baiducloud_instance and attach a new disk, the disk create falied with a message:

│ Error: [ERROR] terraform-provider-baiducloud/baiducloud/resource_baiducloud_cds.go:191: Resource baiducloud_cds Create
CDS volume Failed!!! [SDK bce-sdk-go ERROR]:
│ [Code: Volume.DiskQuotaExceededLimit; Message: Number of volumes exceeds limit.; RequestId: f31b9bb5-b2f4-4b53-80c4-8fe2d2446854]

Terraform will perform the following actions:

  # baiducloud_cds.tf-server-data will be created
  + resource "baiducloud_cds" "tf-server-data" {
      + auto_snapshot_policy_id = (known after apply)
      + create_time             = (known after apply)
      + description             = "terraform create cds"
      + disk_size_in_gb         = 40
      + expire_time             = (known after apply)
      + id                      = (known after apply)
      + name                    = "tf-server-data"
      + payment_timing          = "Postpaid"
      + snapshot_id             = (known after apply)
      + status                  = (known after apply)
      + storage_type            = "hdd"
      + type                    = (known after apply)
      + zone_name               = "cn-bj-b"
    }

  # baiducloud_cds_attachment.default will be created
  + resource "baiducloud_cds_attachment" "default" {
      + attachment_device = (known after apply)
      + attachment_serial = (known after apply)
      + cds_id            = (known after apply)
      + id                = (known after apply)
      + instance_id       = (known after apply)
    }

  # baiducloud_eip.tf-eip will be created
  + resource "baiducloud_eip" "tf-eip" {
      + bandwidth_in_mbps = 100
      + billing_method    = "ByTraffic"
      + create_time       = (known after apply)
      + eip               = (known after apply)
      + eip_instance_type = (known after apply)
      + expire_time       = (known after apply)
      + id                = (known after apply)
      + name              = "tf-eip"
      + payment_timing    = "Postpaid"
      + share_group_id    = (known after apply)
      + status            = (known after apply)
    }

  # baiducloud_eip_association.tf-eip-link will be created
  + resource "baiducloud_eip_association" "tf-eip-link" {
      + eip           = (known after apply)
      + id            = (known after apply)
      + instance_id   = (known after apply)
      + instance_type = "BCC"
    }

  # baiducloud_instance.tf-server will be created
  + resource "baiducloud_instance" "tf-server" {
      + action                   = "start"
      + auto_renew               = (known after apply)
      + auto_renew_time_length   = 1
      + availability_zone        = "cn-bj-b"
      + billing                  = {
          + "payment_timing" = "Postpaid"
        }
      + cds_auto_renew           = false
      + cpu_count                = 1
      + create_time              = (known after apply)
      + delete_cds_snapshot_flag = false
      + expire_time              = (known after apply)
      + id                       = (known after apply)
      + image_id                 = "m-hDf0Uqut"
      + instance_type            = "N2"
      + internal_ip              = (known after apply)
      + keypair_id               = "k-mNMZVoe5"
      + keypair_name             = (known after apply)
      + memory_capacity_in_gb    = 1
      + name                     = "tf-instance"
      + network_capacity_in_mbps = (known after apply)
      + placement_policy         = (known after apply)
      + public_ip                = (known after apply)
      + related_release_flag     = false
      + root_disk_size_in_gb     = 40
      + root_disk_storage_type   = "cloud_hp1"
      + security_groups          = [
          + "g-34pxziaa8vi9",
        ]
      + status                   = (known after apply)
      + subnet_id                = "sbn-uj89sdh9d4fp"
      + vpc_id                   = (known after apply)
    }

Plan: 5 to add, 0 to change, 0 to destroy.

Do you want to perform these actions in workspace "vm-2"?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

baiducloud_eip.tf-eip: Creating...
baiducloud_instance.tf-server: Creating...
baiducloud_cds.tf-server-data: Creating...
baiducloud_eip.tf-eip: Still creating... [10s elapsed]
baiducloud_instance.tf-server: Still creating... [10s elapsed]
baiducloud_eip.tf-eip: Creation complete after 12s [id=180.76.154.104]
baiducloud_instance.tf-server: Still creating... [20s elapsed]
baiducloud_instance.tf-server: Still creating... [30s elapsed]
baiducloud_instance.tf-server: Still creating... [40s elapsed]
baiducloud_instance.tf-server: Still creating... [50s elapsed]
baiducloud_instance.tf-server: Still creating... [1m0s elapsed]
baiducloud_instance.tf-server: Still creating... [1m10s elapsed]
baiducloud_instance.tf-server: Still creating... [1m20s elapsed]
baiducloud_instance.tf-server: Still creating... [1m30s elapsed]
baiducloud_instance.tf-server: Still creating... [1m40s elapsed]
baiducloud_instance.tf-server: Still creating... [1m50s elapsed]
baiducloud_instance.tf-server: Still creating... [2m0s elapsed]
baiducloud_instance.tf-server: Still creating... [2m10s elapsed]
baiducloud_instance.tf-server: Still creating... [2m20s elapsed]
baiducloud_instance.tf-server: Still creating... [2m30s elapsed]
baiducloud_instance.tf-server: Still creating... [2m40s elapsed]
baiducloud_instance.tf-server: Still creating... [2m50s elapsed]
baiducloud_instance.tf-server: Creation complete after 3m0s [id=i-nJMIKbZW]
baiducloud_eip_association.tf-eip-link: Creating...
baiducloud_eip_association.tf-eip-link: Still creating... [10s elapsed]
baiducloud_eip_association.tf-eip-link: Creation complete after 13s [id=180.76.154.104]
╷
│ Error: [ERROR] terraform-provider-baiducloud/baiducloud/resource_baiducloud_cds.go:191: Resource baiducloud_cds Create CDS volume Failed!!! [SDK bce-sdk-go ERROR]:
│ [Code: Volume.DiskQuotaExceededLimit; Message: Number of volumes exceeds limit.; RequestId: f31b9bb5-b2f4-4b53-80c4-8fe2d2446854]
│ 
│   on baidu-vm.tf line 32, in resource "baiducloud_cds" "tf-server-data":
│   32: resource "baiducloud_cds" "tf-server-data" {
│ 

The disk created successfuly after retry again:

baiducloud_eip.tf-eip: Refreshing state... [id=180.76.154.104]
baiducloud_instance.tf-server: Refreshing state... [id=i-nJMIKbZW]
baiducloud_eip_association.tf-eip-link: Refreshing state... [id=180.76.154.104]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # baiducloud_cds.tf-server-data will be created
  + resource "baiducloud_cds" "tf-server-data" {
      + auto_snapshot_policy_id = (known after apply)
      + create_time             = (known after apply)
      + description             = "terraform create cds"
      + disk_size_in_gb         = 40
      + expire_time             = (known after apply)
      + id                      = (known after apply)
      + name                    = "tf-server-data"
      + payment_timing          = "Postpaid"
      + snapshot_id             = (known after apply)
      + status                  = (known after apply)
      + storage_type            = "hdd"
      + type                    = (known after apply)
      + zone_name               = "cn-bj-b"
    }

  # baiducloud_cds_attachment.default will be created
  + resource "baiducloud_cds_attachment" "default" {
      + attachment_device = (known after apply)
      + attachment_serial = (known after apply)
      + cds_id            = (known after apply)
      + id                = (known after apply)
      + instance_id       = "i-nJMIKbZW"
    }

Plan: 2 to add, 0 to change, 0 to destroy.

Do you want to perform these actions in workspace "vm-2"?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

baiducloud_cds.tf-server-data: Creating...
baiducloud_cds.tf-server-data: Still creating... [10s elapsed]
baiducloud_cds.tf-server-data: Still creating... [20s elapsed]
baiducloud_cds.tf-server-data: Still creating... [30s elapsed]
baiducloud_cds.tf-server-data: Still creating... [40s elapsed]
baiducloud_cds.tf-server-data: Creation complete after 40s [id=v-LTPPeii1]
baiducloud_cds_attachment.default: Creating...
baiducloud_cds_attachment.default: Still creating... [10s elapsed]
baiducloud_cds_attachment.default: Creation complete after 11s [id=v-LTPPeii1]

Apply complete! Resources: 2 added, 0 changed, 0 destroyed.

Allow more recent k8s versions in `baiducloud_ccev2_cluster`

╷
│ Error: expected cluster_spec.0.runtime_type to be one of [docker], got containerd
│
│   with baiducloud_ccev2_cluster.default,
│   on main.tf line 38, in resource "baiducloud_ccev2_cluster" "default":
│   38: resource "baiducloud_ccev2_cluster" "default" {
│
╵
╷
│ Error: expected cluster_spec.0.k8s_version to be one of [1.18.9 1.20.8 1.22.5], got 1.24.4
│
│   with baiducloud_ccev2_cluster.default,
│   on main.tf line 38, in resource "baiducloud_ccev2_cluster" "default":
│   38: resource "baiducloud_ccev2_cluster" "default" {
│
╵

On the Baidu Cloud Console UI, I can create a CCE cluster with k8s 1.24.4 and containerd runtime. It would be better to make the Terraform provider up-to-date.

Creating a default access key pair when creating a new IAM user

Currently, the bce terraform provider doesn't support creating/deleting/listing access key pair. However, our project requires creating a default access key pair when creating a new IAM user. Therefore, we came up with an idea, which only modifies ONE source code file:

resource_baiducloud_iam_user.go

Here are our modifications:

I. Adding 2 Optional items ("access_key" & "secret_key") to the schema map:

           Schema: map[string]*schema.Schema{
		"unique_id": {
			...
		},
		"name": {
			...
		},
		"description": {
			...
		},
		"force_destroy": {
			...
		},
		"access_key": {
			Type:        schema.TypeString,
			Description: "Default AK.",
			Optional:    true,
		},
		"secret_key": {
			Type:        schema.TypeString,
			Description: "Default SK.",
			Optional:    true,
		},
	},

II. Modify the function of creating a new user:

func resourceBaiduCloudIamUserCreate(d *schema.ResourceData, meta interface{}) error {
	client := meta.(*connectivity.BaiduClient)
	name := d.Get("name").(string)
	description := d.Get("description").(string)
	action := "Create User " + name

	user, err := client.WithIamClient(func(iamClient *iam.Client) (i interface{}, e error) {
		return iamClient.CreateUser(&api.CreateUserArgs{
			Name:        name,
			Description: description,
		})
	})
	if err != nil {
		return WrapErrorf(err, DefaultErrorMsg, "baiducloud_iam_user", action, BCESDKGoERROR)
	}
	addDebug(action, user)

	raw, err := client.WithIamClient(func(iamClient *iam.Client) (i interface{}, e error) {
		return iamClient.CreateAccessKey(name)
	})
	if err != nil {
		return WrapErrorf(err, DefaultErrorMsg, "baiducloud_iam_user", action, BCESDKGoERROR)
	}

	addDebug(action, raw)
	result := raw.(*api.CreateAccessKeyResult)
	d.Set("access_key", result.Id)
	d.Set("secret_key", result.Secret)

	d.SetId(name)
	return resourceBaiduCloudIamUserRead(d, meta)
}

III. Test:

I've updated the resource_baiducloud_iam_user.go file and compiled my own version of terraform-provider-baiducloud. It works quite well. Here is my test tf file:

 terraform {
  required_providers {
    baiducloud = {
      source  = "baidubce/baiducloud"
      version = "1.19.9"
    }
  }
}

provider "baiducloud" {
  access_key = "b1ec1f4df8********************"
  secret_key = "21910e70************************"
  region = "bj"
}

#The lifecycle part (ignore_changes = [access_key,secret_key] ) is VERY IMPORTANT!
#Without the lifecycle body, the ak and sk will be erased from the terraform.tfstate file at the next apply
#With the lifecycle part, the ak and sk string will not be erased. However, this is NOT secure, because the ak and sk string may leak
#Therefore, it depends on the purpose of the user.
resource "baiducloud_iam_user" "hpc_user" {
  name = "my_user_name_wzr"
  force_destroy = false
  lifecycle {
    ignore_changes = [access_key,secret_key]
  }
}

IV. Summary

The method above works. When creating a new user, a default AccessKey pair will be generated and exported to the terraform.tfstate file.

error when i use endpoints in the project

config in main.tf like this

provider "baiducloud" {
  access_key = "access_keyxadajdiajo"
  secret_key = "secret_keyxxafjasdfkd "
  endpoints [
      bos = "bos_custom_endpoint"
    ]
}

Error: Argument or block definition required

on main.tf line 11, in provider "baiducloud":
11: endpoints [

An argument or block definition is required here. To set an argument, use the
equals sign "=" to introduce the argument value.

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.