-
Notifications
You must be signed in to change notification settings - Fork 359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add openstack_compute_flavor_v2 resource #83
Add openstack_compute_flavor_v2 resource #83
Conversation
mcanevet
commented
Aug 22, 2017
•
edited
edited
- Create
- Read
- Delete
- Importer
- Documentation
@mcanevet This is a really good start. I was able to get this working with the following fixes. Some of them are a little tricky, so they deserve some explanation:
resource "openstack_compute_flavor_v2" "my_flavor" {
name = "my_flavor"
...
value_specs {
tenant_id = "abcd1234"
}
} Since the WIP flavor resource you created doesn't have Unless you need
If you'd like, I can submit a PR of my fixes to your branch, or you can copy them, or implement them yourself with any modifications you need. One thing I recommend is also including parameters for With regard to the source ~/openrc
cd ~/go/src/github.com/terraform-providers/terraform-provider-openstack
TF_LOG=DEBUG make testacc TEST=./openstack TESTARGS="-run=TestAccComputeV2Flavor_basic" 2>&1 | tee ~/openstack.log I have a local bash function to quickly run tests: ttest() {
if [[ -n $1 ]]; then
pushd ~/go/src/github.com/terraform-providers/terraform-provider-openstack
TF_LOG=DEBUG make testacc TEST=./openstack TESTARGS="-run=$1" 2>&1 | tee ~/openstack.log
popd
fi
}
ttest TestAccComputeV2Flavor_basic Let me know if you have any questions. :) edit: Oh, nevermind about the |
@jtopjian thanks a lot for your explanations. Creation works with your fix. I'll see if I've time to look at gophercloud to add the update and delete support. I first added parameters for |
@mcanevet Feel free to update the vendor dep if necessary...
|
@fatmcgav I'm trying to update gophercloud with this command:
But somehow it looks like it fails somewhere because I don't have the full diff I can see here : gophercloud/gophercloud@c5dfe1b...81a3d5b |
@mcanevet I suspect In the past, I've run So maybe try that on |
nothing happens... |
@mcanevet Hmm, did you revert your changes to As I've just run
|
@fatmcgav after checkouting master it works on by branch... |
@mcanevet Heh, gotta love |
Also, I guess documentation needs to go on the 'TODO' list :) |
8c801c6
to
bf37f40
Compare
@fatmcgav I'm not sure I'll have time to add support of update/delete to gophercloud. |
|
||
# openstack\_compute\_flavor_v2 | ||
|
||
Manages a V2 flavor resource within OpenStack. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth adding a note that currently only 'Create' operation is supported?
@jtopjian Is there any prior-art for this?
createOpts := flavors.CreateOpts{ | ||
Name: d.Get("name").(string), | ||
RAM: d.Get("ram").(int), | ||
VCPUs: d.Get("vcpus").(int), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency, should RAM
and VCPUs
be assigned to variables as well?
Granted they'll just be passed straight through rather than pointered...
Appreciate that gophercloud expects them in different formats currently, but probably should standardise :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jtopjian Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine to leave this as-is. The pattern throughout the rest of the OpenStack resources is more or less:
passAsInt := d.Get("foo").(string)
needsWorkDoneFirst := resourceComputeV2SomethingBar(d.Get("bar"))
createOpts := something.CreateOpts{
Foo: &passAsInt,
Bar: needsWorkDoneFirst,
Baz: d.Get("baz").(string),
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put another way, if you wanted to assign ram and vcpus as a variable as well, that opens the door to other contributors doing something like:
var1 := d.Get("var1").(string)
var2 := d.Get("var2").(string)
var3 := d.Get("var3").(string)
createOpts := something.createOpts{
Var1: var1,
Var2: var2,
Var3: var3,
}
While that's not bad and it technically works, I'd rather stick with something closer to how the rest of the resources look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine by me... I guess ideally Gophercloud should be updated to use the same pattern throughout flavors.CreateOpts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason disk
takes a pointer is because it's actually a tertiary type of setting: 0, non-zero, nil. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, Ok... Lots of little nuances then :)
"ram": &schema.Schema{ | ||
Type: schema.TypeInt, | ||
Required: true, | ||
ForceNew: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As Gophercloud doesn't currently support 'Update', is it worth setting these to ForceNew: true
?
@jtopjian Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fatmcgav as Gophercloud does not support delete either, ForceNew: true
will not help...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, true... 😃
This will have to wait until Update and Delete are implemented in Gophercloud. It doesn't make sense to have a Terraform resource that only creates. I can look at adding Update and Delete in the next week. |
@mcanevet I've opened a PR to add support for Delete operation to Gophercloud - gophercloud/gophercloud#501 Edit: So according to the Compute API Docs, you can't update flavors anyways, so Create and Delete is sufficient, combined with |
Yes, this is correct. I realized this this evening. While Horizon gives the ability to update flavors, it's really doing a delete/create in the background. If you guys get around to adding Delete, I'd like to do one final review before it gets merged. |
@fatmcgav @jtopjian , I tried to update
If I update only the flavor using Any idea? Should I update only |
Yes. I've been meaning to do a full Gophercloud vendor update and see if I can resolve any errors. But for now, definitely just update the flavors package. |
@mcanevet Yeh, I think the general practise is to only update the package required... So just updating |
I just implemented |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes all look good to me.
Will leave for @jtopjian to provide final approval though :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mcanevet Thank you for your work on this. Just a few small changes in the code.
Additionally, there needs to be two changes to the acceptance tests:
- Since two flavors with the same name can't exist, the acceptance test will fail if there's already a flavor with the name of
flavor_1
. So we need to randomly generate a flavor name. You can see how to do that in the Projects test:
- A separate test file for the Import functionality needs to be added. A quick copy/paste/rename of the Key Pair test should work:
At a minimum, if you can fix the inline comments I made, I'm OK with merging this. Acceptance tests aren't a firm requirement for having code merged, so I can follow-up with the above. But if you want to do it for experience, go for it :)
edit: Actually, the Project Import test is a better example since it requires Admin privileges + does the random name generation:
|
||
disk := d.Get("disk").(int) | ||
swap := d.Get("swap").(int) | ||
is_public := d.Get("is_public").(bool) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: isPublic
instead of is_public
.
return err | ||
} | ||
|
||
if found.Name != rs.Primary.ID { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
found.ID
The test was failing and this took me a 30 minutes to spot 😄
|
||
## Import | ||
|
||
Flavors can be imported using the `name`, e.g. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/name/ID
Flavors can be imported using the `name`, e.g. | ||
|
||
``` | ||
$ terraform import openstack_compute_flavor_v2.my-flavor test-flavor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/test-flavor/4142e64b-1b35-44a0-9b1e-5affc7af1106/
Add openstack_compute_flavor_v2 resource