Skip to content
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

fix(instance): made keys as forcenew true for instance and template #5318

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions ibm/service/vpc/resource_ibm_is_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,12 @@ func ResourceIBMISInstance() *schema.Resource {
},

isInstanceKeys: {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
DiffSuppressFunc: flex.ApplyOnce,
Description: "SSH key Ids for the instance",
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
ForceNew: true,
Description: "SSH key Ids for the instance",
},

isInstanceTags: {
Expand Down
12 changes: 6 additions & 6 deletions ibm/service/vpc/resource_ibm_is_instance_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@ func ResourceIBMISInstanceTemplate() *schema.Resource {
},

isInstanceTemplateKeys: {
Type: schema.TypeSet,
Required: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
DiffSuppressFunc: flex.ApplyOnce,
Description: "SSH key Ids for the instance template",
Type: schema.TypeSet,
Required: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
ForceNew: true,
Description: "SSH key Ids for the instance template",
},

isPlacementTargetDedicatedHost: {
Expand Down
87 changes: 87 additions & 0 deletions ibm/service/vpc/resource_ibm_is_instance_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,49 @@ func TestAccIBMISInstanceTemplate_basic(t *testing.T) {
},
})
}
func TestAccIBMISInstanceTemplate_keys_update(t *testing.T) {
randInt := acctest.RandIntRange(10, 100)

publicKey := strings.TrimSpace(`
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDVtuCfWKVGKaRmaRG6JQZY8YdxnDgGzVOK93IrV9R5Hl0JP1oiLLWlZQS2reAKb8lBqyDVEREpaoRUDjqDqXG8J/kR42FKN51su914pjSBc86wJ02VtT1Wm1zRbSg67kT+g8/T1jCgB5XBODqbcICHVP8Z1lXkgbiHLwlUrbz6OZkGJHo/M/kD1Eme8lctceIYNz/Ilm7ewMXZA4fsidpto9AjyarrJLufrOBl4MRVcZTDSJ7rLP982aHpu9pi5eJAjOZc7Og7n4ns3NFppiCwgVMCVUQbN5GBlWhZ1OsT84ZiTf+Zy8ew+Yg5T7Il8HuC7loWnz+esQPf0s3xhC/kTsGgZreIDoh/rxJfD67wKXetNSh5RH/n5BqjaOuXPFeNXmMhKlhj9nJ8scayx/wsvOGuocEIkbyJSLj3sLUU403OafgatEdnJOwbqg6rUNNF5RIjpJpL7eEWlKIi1j9LyhmPJ+fEO7TmOES82VpCMHpLbe4gf/MhhJ/Xy8DKh9s= root@ffd8363b1226
`)
publicKey2 := strings.TrimSpace(`ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHEE9sLlndKFR/hVbF7SUNhKBFrxscJDHrVN/OD1Z+8V [email protected]`)
sshKey := "ed25519"
vpcName := fmt.Sprintf("tf-testvpc%d", randInt)
subnetName := fmt.Sprintf("tf-testsubnet%d", randInt)
templateName := fmt.Sprintf("tf-testtemplate%d", randInt)
sshKeyName := fmt.Sprintf("tf-testsshkey%d", randInt)
sshKeyName2 := fmt.Sprintf("tf-testsshkey%d", randInt)
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
CheckDestroy: testAccCheckIBMISInstanceTemplateDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMISInstanceTemplateConfig(vpcName, subnetName, sshKeyName, publicKey, templateName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"ibm_is_instance_template.instancetemplate1", "name", templateName),
resource.TestCheckResourceAttr(
"ibm_is_instance_template.instancetemplate1", "keys.#", "1"),
resource.TestCheckResourceAttrSet(
"ibm_is_instance_template.instancetemplate1", "profile"),
),
},
{
Config: testAccCheckIBMISInstanceTemplateConfigKeyUpdate(vpcName, subnetName, sshKeyName, publicKey, sshKeyName2, sshKey, publicKey2, templateName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"ibm_is_instance_template.instancetemplate1", "name", templateName),
resource.TestCheckResourceAttr(
"ibm_is_instance_template.instancetemplate1", "keys.#", "2"),
resource.TestCheckResourceAttrSet(
"ibm_is_instance_template.instancetemplate1", "profile"),
),
},
},
})
}
func TestAccIBMISInstanceTemplate_vni(t *testing.T) {
randInt := acctest.RandIntRange(10, 100)

Expand Down Expand Up @@ -355,6 +398,50 @@ func testAccCheckIBMISInstanceTemplateConfig(vpcName, subnetName, sshKeyName, pu

`, vpcName, subnetName, sshKeyName, publicKey, templateName)

}
func testAccCheckIBMISInstanceTemplateConfigKeyUpdate(vpcName, subnetName, sshKeyName, publicKey, sshKeyName2, sshKey, publicKey2, templateName string) string {
return fmt.Sprintf(`
resource "ibm_is_vpc" "vpc2" {
name = "%s"
}

resource "ibm_is_subnet" "subnet2" {
name = "%s"
vpc = ibm_is_vpc.vpc2.id
zone = "us-south-2"
ipv4_cidr_block = "10.240.64.0/28"
}

resource "ibm_is_ssh_key" "sshkey" {
name = "%s"
public_key = "%s"
}
resource "ibm_is_ssh_key" "sshkey2" {
name = "%s"
public_key = "%s"
type = "%s"
}

data "ibm_is_images" "is_images" {
}

resource "ibm_is_instance_template" "instancetemplate1" {
name = "%s"
image = data.ibm_is_images.is_images.images.0.id
profile = "bx2-8x32"

primary_network_interface {
subnet = ibm_is_subnet.subnet2.id
}

vpc = ibm_is_vpc.vpc2.id
zone = "us-south-2"
keys = [ibm_is_ssh_key.sshkey.id, ibm_is_ssh_key.sshkey2.id]
}


`, vpcName, subnetName, sshKeyName, publicKey, sshKeyName2, publicKey2, sshKey, templateName)

}
func testAccCheckIBMISInstanceTemplateVniConfig(vpcName, subnetName, sshKeyName, publicKey, templateName string) string {
return fmt.Sprintf(`
Expand Down
102 changes: 102 additions & 0 deletions ibm/service/vpc/resource_ibm_is_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,68 @@ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVE
},
})
}
func TestAccIBMISInstance_keysupdate(t *testing.T) {
var instance string
vpcname := fmt.Sprintf("tf-vpc-%d", acctest.RandIntRange(10, 100))
name := fmt.Sprintf("tf-instnace-%d", acctest.RandIntRange(10, 100))
subnetname := fmt.Sprintf("tf-subnet-%d", acctest.RandIntRange(10, 100))
publicKey := strings.TrimSpace(`
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVERRN7/9484SOBJ3HSKxxNG5JN8owAjy5f9yYwcUg+JaUVuytn5Pv3aeYROHGGg+5G346xaq3DAwX6Y5ykr2fvjObgncQBnuU5KHWCECO/4h8uWuwh/kfniXPVjFToc+gnkqA+3RKpAecZhFXwfalQ9mMuYGFxn+fwn8cYEApsJbsEmb0iJwPiZ5hjFC8wREuiTlhPHDgkBLOiycd20op2nXzDbHfCHInquEe/gYxEitALONxm0swBOwJZwlTDOB7C6y2dzlrtxr1L59m7pCkWI4EtTRLvleehBoj3u7jB4usR
`)
publicKey2 := strings.TrimSpace(`ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHEE9sLlndKFR/hVbF7SUNhKBFrxscJDHrVN/OD1Z+8V [email protected]`)
sshKey := "ed25519"
sshname := fmt.Sprintf("tf-ssh-%d", acctest.RandIntRange(10, 100))
sshname2 := fmt.Sprintf("tf-ssh-%d", acctest.RandIntRange(10, 100))
userData1 := "a"

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
CheckDestroy: testAccCheckIBMISInstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMISInstanceConfig(vpcname, subnetname, sshname, publicKey, name, userData1),
Check: resource.ComposeTestCheckFunc(
testAccCheckIBMISInstanceExists("ibm_is_instance.testacc_instance", instance),
resource.TestCheckResourceAttr(
"ibm_is_instance.testacc_instance", "name", name),
resource.TestCheckResourceAttr(
"ibm_is_instance.testacc_instance", "user_data", userData1),
resource.TestCheckResourceAttr(
"ibm_is_instance.testacc_instance", "zone", acc.ISZoneName),
resource.TestCheckResourceAttrSet(
"ibm_is_instance.testacc_instance", "vcpu.#"),
resource.TestCheckResourceAttr(
"ibm_is_instance.testacc_instance", "keys.#", "1"),
resource.TestCheckResourceAttrSet(
"ibm_is_instance.testacc_instance", "vcpu.0.manufacturer"),
),
},
{
Config: testAccCheckIBMISInstanceKeysConfig(vpcname, subnetname, sshname, publicKey, sshname2, publicKey2, sshKey, name, userData1),
Check: resource.ComposeTestCheckFunc(
testAccCheckIBMISInstanceExists("ibm_is_instance.testacc_instance", instance),
resource.TestCheckResourceAttr(
"ibm_is_instance.testacc_instance", "name", name),
resource.TestCheckResourceAttr(
"ibm_is_instance.testacc_instance", "user_data", userData1),
resource.TestCheckResourceAttr(
"ibm_is_instance.testacc_instance", "zone", acc.ISZoneName),
resource.TestCheckResourceAttrSet(
"ibm_is_instance.testacc_instance", "primary_network_interface.0.port_speed"),
resource.TestCheckResourceAttrSet(
"ibm_is_instance.testacc_instance", "vcpu.#"),
resource.TestCheckResourceAttr(
"ibm_is_instance.testacc_instance", "keys.#", "2"),
resource.TestCheckResourceAttrSet(
"ibm_is_instance.testacc_instance", "vcpu.0.manufacturer"),
resource.TestCheckResourceAttrSet(
"ibm_is_instance.testacc_instance", "numa_count"),
),
},
},
})
}
func TestAccIBMISInstance_vni(t *testing.T) {
var instance string
vpcname := fmt.Sprintf("tf-vpc-%d", acctest.RandIntRange(10, 100))
Expand Down Expand Up @@ -1290,6 +1352,46 @@ func testAccCheckIBMISInstanceConfig(vpcname, subnetname, sshname, publicKey, na
}
}`, vpcname, subnetname, acc.ISZoneName, acc.ISCIDR, sshname, publicKey, name, acc.IsImage, acc.InstanceProfileName, userData, acc.ISZoneName)
}
func testAccCheckIBMISInstanceKeysConfig(vpcname, subnetname, sshname, publicKey, sshname2, publicKey2, sshkey, name, userData string) string {
return fmt.Sprintf(`
resource "ibm_is_vpc" "testacc_vpc" {
name = "%s"
}

resource "ibm_is_subnet" "testacc_subnet" {
name = "%s"
vpc = ibm_is_vpc.testacc_vpc.id
zone = "%s"
ipv4_cidr_block = "%s"
}

resource "ibm_is_ssh_key" "testacc_sshkey" {
name = "%s"
public_key = "%s"
}
resource "ibm_is_ssh_key" "testacc_sshkey2" {
name = "%s"
public_key = "%s"
type = "%s"
}

resource "ibm_is_instance" "testacc_instance" {
name = "%s"
image = "%s"
profile = "%s"
primary_network_interface {
subnet = ibm_is_subnet.testacc_subnet.id
}
user_data = "%s"
vpc = ibm_is_vpc.testacc_vpc.id
zone = "%s"
keys = [ibm_is_ssh_key.testacc_sshkey.id, ibm_is_ssh_key.testacc_sshkey2.id]
network_interfaces {
subnet = ibm_is_subnet.testacc_subnet.id
name = "eth1"
}
}`, vpcname, subnetname, acc.ISZoneName, acc.ISCIDR, sshname, publicKey, sshname2, publicKey2, sshkey, name, acc.IsImage, acc.InstanceProfileName, userData, acc.ISZoneName)
}
func testAccCheckIBMISInstanceVniConfig(vpcname, subnetname, sshname, publicKey, name, vniname, userData string) string {
return fmt.Sprintf(`
resource "ibm_is_vpc" "testacc_vpc" {
Expand Down
Loading